PINLoginPage.xaml.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.Mobile;
  10. using Plugin.BLE.Abstractions.EventArgs;
  11. using Xamarin.Essentials;
  12. using Xamarin.Forms;
  13. using XF.Material.Forms.UI.Dialogs;
  14. namespace comal.timesheets
  15. {
  16. public partial class PINLoginPage : ContentPage
  17. {
  18. String pin = "";
  19. bool autoChange = false;
  20. bool twoFAvisible = false;
  21. bool checkingClipBoard = false;
  22. string loadFromIOSLink = "";
  23. bool timerRunning = false;
  24. Timer timer;
  25. public PINLoginPage(string logindetails = "")
  26. {
  27. InitializeComponent();
  28. //ShowSplashPage();
  29. try
  30. {
  31. ShowPINPad();
  32. CheckForLatestVersion();
  33. if (!string.IsNullOrWhiteSpace(logindetails))
  34. loadFromIOSLink = logindetails;
  35. }
  36. catch
  37. {
  38. ShowPINPad();
  39. }
  40. }
  41. protected override void OnAppearing()
  42. {
  43. try
  44. {
  45. CheckLoadFromLink();
  46. if (!CheckAndPaste2FAText())
  47. return;
  48. SetPinAndShowSplash();
  49. if (App.IsUserLoggedIn && GlobalVariables.ChangeUser == false)
  50. {
  51. LaunchMainPage();
  52. return;
  53. }
  54. else
  55. {
  56. if (String.IsNullOrWhiteSpace(App.DBSettings.UserID) || String.IsNullOrWhiteSpace(App.DBSettings.Password))
  57. {
  58. DisplayAlert("Unable to log in", "User ID or password is blank", "OK");
  59. ShowPINPad();
  60. return;
  61. }
  62. RunValidate();
  63. }
  64. }
  65. catch
  66. {
  67. ShowPINPad();
  68. }
  69. base.OnAppearing();
  70. }
  71. private void SetPinAndShowSplash()
  72. {
  73. try
  74. {
  75. GlobalVariables.InternalOnAppearing = false;
  76. pin = "";
  77. PIN.Text = "";
  78. ShowSplashPage();
  79. }
  80. catch { }
  81. }
  82. private void CheckLoadFromLink()
  83. {
  84. try
  85. {
  86. if (!string.IsNullOrWhiteSpace(loadFromIOSLink))
  87. {
  88. GlobalVariables.LoadFromLinkString = loadFromIOSLink.Remove(0, 17);
  89. MobileUtils.LoadFromLink();
  90. }
  91. if (!string.IsNullOrWhiteSpace(GlobalVariables.LoadFromLinkString))
  92. {
  93. if (GlobalVariables.LoadFromLinkString == "Link has expired")
  94. DisplayAlert("Alert", "Link has expired", "OK");
  95. }
  96. }
  97. catch { }
  98. }
  99. private bool CheckAndPaste2FAText()
  100. {
  101. try
  102. {
  103. if (!GlobalVariables.InternalOnAppearing)
  104. {
  105. if (!twoFAvisible)
  106. return false;
  107. Device.BeginInvokeOnMainThread(async () =>
  108. {
  109. try
  110. {
  111. string text = await Clipboard.GetTextAsync();
  112. if (text.Length != 6)
  113. return;
  114. else
  115. ent0.Text = text;
  116. }
  117. catch
  118. {
  119. }
  120. });
  121. return false;
  122. }
  123. return true;
  124. }
  125. catch
  126. {
  127. return true;
  128. }
  129. }
  130. private async void RunValidate(bool usePIN = false, string pin = "")
  131. {
  132. try
  133. {
  134. //ShowSplashPage();
  135. Guid sessionID = Guid.Empty;
  136. if (App.Current.Properties.ContainsKey("SessionID"))
  137. sessionID = Guid.Parse(App.Current.Properties["SessionID"].ToString());
  138. ValidationResult result;
  139. if (usePIN)
  140. result = ClientFactory.Validate(pin, sessionID);
  141. else
  142. result = ClientFactory.Validate(App.DBSettings.UserID, App.DBSettings.Password, sessionID);
  143. switch (result)
  144. {
  145. case ValidationResult.INVALID:
  146. ShowPINPad();
  147. DisplayAlert("Error logging in", "Invalid User ID, Password or PIN", "OK");
  148. return;
  149. case ValidationResult.PASSWORD_EXPIRED:
  150. await DisplayAlert("Alert", "Your password has expired - please change it", "OK");
  151. PasswordResetPage passwordResetPage = new PasswordResetPage(App.DBSettings.UserID);
  152. passwordResetPage.OnPasswordReset += () => { Task.Run(() => { Thread.Sleep(1500); Device.BeginInvokeOnMainThread(() => { DisplayAlert("Success", "Password changed", "OK"); RunValidate(); }); }); };
  153. Navigation.PushAsync(passwordResetPage);
  154. return;
  155. case ValidationResult.REQUIRE_2FA:
  156. Check2FA();
  157. return;
  158. case ValidationResult.VALID:
  159. if (ClientFactory.PasswordExpiration != DateTime.MinValue)
  160. {
  161. var timeUntilExpiration = ClientFactory.PasswordExpiration - DateTime.Now;
  162. if (timeUntilExpiration.Days < 14)
  163. {
  164. string chosenOption = await DisplayActionSheet("Alert", $"Password will expire in {timeUntilExpiration.Days} days. Change password now?", null, "Yes", "No");
  165. switch (chosenOption)
  166. {
  167. case "Yes":
  168. PasswordResetPage passwordResetPage2 = new PasswordResetPage(App.DBSettings.UserID);
  169. passwordResetPage2.OnPasswordReset += () => { Task.Run(() => { Thread.Sleep(1500); Device.BeginInvokeOnMainThread(() => { DisplayAlert("Success", "Password changed", "OK"); RunValidate(); }); }); };
  170. Navigation.PushAsync(passwordResetPage2);
  171. return;
  172. case "No":
  173. break;
  174. default:
  175. break;
  176. }
  177. }
  178. }
  179. LaunchMainPage();
  180. return;
  181. default:
  182. ShowPINPad();
  183. return;
  184. }
  185. }
  186. catch (Exception ex)
  187. {
  188. string chosenOption = await DisplayActionSheet("Connection error - please check your connection. Try again?", "Cancel", null, "Yes", "No");
  189. switch (chosenOption)
  190. {
  191. case "Yes":
  192. Task.Run(() =>
  193. {
  194. Thread.Sleep(1000);
  195. Device.BeginInvokeOnMainThread(() =>
  196. {
  197. RunValidate();
  198. });
  199. });
  200. break;
  201. default:
  202. break;
  203. }
  204. }
  205. }
  206. private async void LaunchMainPage()
  207. {
  208. if (!App.Current.Properties.ContainsKey("SessionID"))
  209. App.Current.Properties.Add("SessionID", ClientFactory.SessionID);
  210. else
  211. App.Current.Properties["SessionID"] = ClientFactory.SessionID;
  212. if (timerRunning)
  213. timer.Dispose();
  214. App.Data.Refresh(true);
  215. Device.BeginInvokeOnMainThread(async () => { await Navigation.PushAsync(new MainPage()); });
  216. }
  217. private async void Check2FA()
  218. {
  219. try
  220. {
  221. string address2FA = "";
  222. if (!string.IsNullOrWhiteSpace(ClientFactory.Recipient2FA))
  223. {
  224. address2FA = ClientFactory.Recipient2FA;
  225. }
  226. Show2FAScreen(address2FA);
  227. }
  228. catch { }
  229. }
  230. #region 2FA Logic
  231. private void Show2FAScreen(string address2FA)
  232. {
  233. twoFAvisible = true;
  234. twoFAGrid.IsVisible = true;
  235. SplashLayout.IsVisible = false;
  236. PINLayout.IsVisible = false;
  237. twoFALbl.Text = address2FA;
  238. MasterGrid.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Absolute);
  239. MasterGrid.ColumnDefinitions[1].Width = new GridLength(0, GridUnitType.Absolute);
  240. MasterGrid.ColumnDefinitions[2].Width = new GridLength(1, GridUnitType.Star);
  241. AnimateIcons();
  242. if (Device.RuntimePlatform == Device.iOS)
  243. Run2FACheckTimer();
  244. }
  245. private void Run2FACheckTimer()
  246. {
  247. try
  248. {
  249. timer = new Timer(Callback, null, 4000, 500);
  250. timerRunning = true;
  251. }
  252. catch
  253. { }
  254. }
  255. private void Callback(object state)
  256. {
  257. try
  258. {
  259. if (checkingClipBoard)
  260. return;
  261. checkingClipBoard = true;
  262. Device.BeginInvokeOnMainThread(async () =>
  263. {
  264. if (string.IsNullOrWhiteSpace(ent0.Text))
  265. {
  266. if (Clipboard.HasText)
  267. {
  268. string text = await Clipboard.GetTextAsync();
  269. int i = 0;
  270. int.TryParse(text, out i);
  271. if (i != 0)
  272. {
  273. if (text.Length != 6)
  274. return;
  275. else
  276. {
  277. ent0.Text = text;
  278. timer.Dispose();
  279. timer = new Timer(Callback, null, 4000, 500);
  280. }
  281. }
  282. }
  283. }
  284. checkingClipBoard = false;
  285. });
  286. }
  287. catch { checkingClipBoard = false; }
  288. }
  289. private void AnimateIcons()
  290. {
  291. image1.TranslateTo(-70, 0, 0);
  292. image2.TranslateTo(-70, 0, 0);
  293. image3.TranslateTo(-70, 0, 0);
  294. image4.TranslateTo(-70, 0, 0);
  295. image5.TranslateTo(-70, 0, 0);
  296. image6.TranslateTo(-70, 0, 0);
  297. image7.TranslateTo(-70, 0, 0);
  298. image8.TranslateTo(-70, 0, 0);
  299. image9.TranslateTo(-70, 0, 0);
  300. Task.Run(() =>
  301. {
  302. for (int i = 0; i < 10; i++)
  303. {
  304. Device.BeginInvokeOnMainThread(() => { image1.TranslateTo(1200, 0, 30000); });
  305. Thread.Sleep(2500);
  306. Device.BeginInvokeOnMainThread(() => { image2.TranslateTo(1200, 0, 30000); });
  307. Thread.Sleep(2500);
  308. Device.BeginInvokeOnMainThread(() => { image3.TranslateTo(1200, 0, 30000); });
  309. Thread.Sleep(2500);
  310. Device.BeginInvokeOnMainThread(() => { image4.TranslateTo(1200, 0, 30000); });
  311. Thread.Sleep(2500);
  312. Device.BeginInvokeOnMainThread(() => { image5.TranslateTo(1200, 0, 30000); });
  313. Thread.Sleep(2500);
  314. Device.BeginInvokeOnMainThread(() => { image6.TranslateTo(1200, 0, 30000); });
  315. Thread.Sleep(2500);
  316. Device.BeginInvokeOnMainThread(() => { image7.TranslateTo(1200, 0, 30000); });
  317. Thread.Sleep(2500);
  318. Device.BeginInvokeOnMainThread(() => { image8.TranslateTo(1200, 0, 30000); });
  319. Thread.Sleep(2500);
  320. Device.BeginInvokeOnMainThread(() => { image9.TranslateTo(1200, 0, 30000); });
  321. Thread.Sleep(10000);
  322. Device.BeginInvokeOnMainThread(() =>
  323. {
  324. image1.TranslateTo(-70, 0, 0);
  325. image2.TranslateTo(-70, 0, 0);
  326. image3.TranslateTo(-70, 0, 0);
  327. image4.TranslateTo(-70, 0, 0);
  328. image5.TranslateTo(-70, 0, 0);
  329. image6.TranslateTo(-70, 0, 0);
  330. image7.TranslateTo(-70, 0, 0);
  331. image8.TranslateTo(-70, 0, 0);
  332. image9.TranslateTo(-70, 0, 0);
  333. });
  334. }
  335. });
  336. }
  337. private void ClearBtn_Clicked(object sender, EventArgs e)
  338. {
  339. ent0.Text = "";
  340. ent0.Focus();
  341. timer.Dispose();
  342. timer = new Timer(Callback, null, 4000, 500);
  343. }
  344. private async void TwoFAEntry0_Changed(object sender, EventArgs e)
  345. {
  346. if (autoChange)
  347. return;
  348. Device.BeginInvokeOnMainThread(async () =>
  349. {
  350. if (Clipboard.HasText)
  351. {
  352. string clipboard = await Clipboard.GetTextAsync();
  353. if (clipboard.Length == 6 && ent0.Text.Length == 6)
  354. {
  355. string s = ent0.Text;
  356. autoChange = true;
  357. ent0.Text = s[0].ToString();
  358. ent1.Text = s[1].ToString();
  359. ent2.Text = s[2].ToString();
  360. ent3.Text = s[3].ToString();
  361. ent4.Text = s[4].ToString();
  362. ent5.Text = s[5].ToString();
  363. ent1.IsEnabled = true;
  364. ent2.IsEnabled = true;
  365. ent3.IsEnabled = true;
  366. ent4.IsEnabled = true;
  367. ent5.IsEnabled = true;
  368. Animate(true, true, true, true, true, true);
  369. ent5.Focus();
  370. autoChange = false;
  371. CheckEntries();
  372. return;
  373. }
  374. }
  375. });
  376. if (!string.IsNullOrWhiteSpace(ent0.Text))
  377. {
  378. if (ent0.Text.Length == 1)
  379. {
  380. ent1.IsEnabled = true;
  381. ent1.Focus();
  382. Animate(true);
  383. }
  384. if (ent0.Text.Length == 2)
  385. {
  386. autoChange = true;
  387. string s = ent0.Text;
  388. ent0.Text = s[0].ToString();
  389. ent1.Text = s[1].ToString();
  390. ent1.IsEnabled = true;
  391. ent2.IsEnabled = true;
  392. ent2.Focus();
  393. Animate(true, true);
  394. autoChange = false;
  395. }
  396. if (ent0.Text.Length == 3)
  397. {
  398. string s = ent0.Text;
  399. autoChange = true;
  400. ent0.Text = s[0].ToString();
  401. ent1.Text = s[1].ToString();
  402. ent2.Text = s[2].ToString();
  403. ent1.IsEnabled = true;
  404. ent2.IsEnabled = true;
  405. ent3.IsEnabled = true;
  406. Animate(true, true, true);
  407. ent3.Focus();
  408. autoChange = false;
  409. }
  410. if (ent0.Text.Length == 4)
  411. {
  412. string s = ent0.Text;
  413. autoChange = true;
  414. ent0.Text = s[0].ToString();
  415. ent1.Text = s[1].ToString();
  416. ent2.Text = s[2].ToString();
  417. ent3.Text = s[3].ToString();
  418. ent1.IsEnabled = true;
  419. ent2.IsEnabled = true;
  420. ent3.IsEnabled = true;
  421. ent4.IsEnabled = true;
  422. ent4.Focus();
  423. Animate(true, true, true, true);
  424. autoChange = false;
  425. }
  426. if (ent0.Text.Length == 5)
  427. {
  428. string s = ent0.Text;
  429. autoChange = true;
  430. ent0.Text = s[0].ToString();
  431. ent1.Text = s[1].ToString();
  432. ent2.Text = s[2].ToString();
  433. ent3.Text = s[3].ToString();
  434. ent4.Text = s[4].ToString();
  435. ent1.IsEnabled = true;
  436. ent2.IsEnabled = true;
  437. ent3.IsEnabled = true;
  438. ent4.IsEnabled = true;
  439. ent5.IsEnabled = true;
  440. ent5.Focus();
  441. Animate(true, true, true, true, true);
  442. autoChange = false;
  443. }
  444. if (ent0.Text.Length == 6)
  445. {
  446. string s = ent0.Text;
  447. autoChange = true;
  448. ent0.Text = s[0].ToString();
  449. ent1.Text = s[1].ToString();
  450. ent2.Text = s[2].ToString();
  451. ent3.Text = s[3].ToString();
  452. ent4.Text = s[4].ToString();
  453. ent5.Text = s[5].ToString();
  454. ent5.Focus();
  455. ent1.IsEnabled = true;
  456. ent2.IsEnabled = true;
  457. ent3.IsEnabled = true;
  458. ent4.IsEnabled = true;
  459. ent5.IsEnabled = true;
  460. ent5.Focus();
  461. Animate(true, true, true, true, true, true);
  462. autoChange = false;
  463. CheckEntries();
  464. }
  465. ent0.MaxLength = 1;
  466. }
  467. else
  468. {
  469. ent0.MaxLength = 6;
  470. ent1.Text = "";
  471. ent1.IsEnabled = false;
  472. }
  473. }
  474. private async void TwoFAEntry1_Changed(object sender, EventArgs e)
  475. {
  476. if (autoChange)
  477. return;
  478. if (!string.IsNullOrWhiteSpace(ent1.Text))
  479. {
  480. await frame1.TranslateTo(0, -15, 150);
  481. frame1.TranslateTo(0, 0, 150);
  482. ent2.IsEnabled = true;
  483. ent2.Focus();
  484. }
  485. else
  486. {
  487. ent2.IsEnabled = false;
  488. ent2.Text = "";
  489. }
  490. }
  491. private async void TwoFAEntry2_Changed(object sender, EventArgs e)
  492. {
  493. if (autoChange)
  494. return;
  495. if (!string.IsNullOrWhiteSpace(ent2.Text))
  496. {
  497. await frame2.TranslateTo(0, -15, 150);
  498. frame2.TranslateTo(0, 0, 150);
  499. ent3.IsEnabled = true;
  500. ent3.Focus();
  501. }
  502. else
  503. {
  504. ent3.IsEnabled = false;
  505. ent3.Text = "";
  506. }
  507. }
  508. private async void TwoFAEntry3_Changed(object sender, EventArgs e)
  509. {
  510. if (autoChange)
  511. return;
  512. if (!string.IsNullOrWhiteSpace(ent3.Text))
  513. {
  514. await frame3.TranslateTo(0, -15, 150);
  515. frame3.TranslateTo(0, 0, 150);
  516. ent4.IsEnabled = true;
  517. ent4.Focus();
  518. }
  519. else
  520. {
  521. ent4.IsEnabled = false;
  522. ent4.Text = "";
  523. }
  524. }
  525. private async void TwoFAEntry4_Changed(object sender, EventArgs e)
  526. {
  527. if (autoChange)
  528. return;
  529. if (!string.IsNullOrWhiteSpace(ent4.Text))
  530. {
  531. await frame4.TranslateTo(0, -15, 150);
  532. frame4.TranslateTo(0, 0, 150);
  533. ent5.IsEnabled = true;
  534. ent5.Focus();
  535. }
  536. else
  537. {
  538. ent5.IsEnabled = false;
  539. ent5.Text = "";
  540. }
  541. }
  542. private async void TwoFAEntry5_Changed(object sender, EventArgs e)
  543. {
  544. if (autoChange)
  545. return;
  546. if (!string.IsNullOrWhiteSpace(ent5.Text))
  547. {
  548. Animate(true, true, true, true, true, true);
  549. CheckEntries();
  550. }
  551. }
  552. private void Animate(bool zero = false, bool one = false, bool two = false, bool three = false, bool four = false, bool five = false)
  553. {
  554. Device.BeginInvokeOnMainThread(async () =>
  555. {
  556. if (zero)
  557. {
  558. await frame0.TranslateTo(0, -15, 150);
  559. frame0.TranslateTo(0, 0, 150);
  560. }
  561. if (one)
  562. {
  563. await frame1.TranslateTo(0, -15, 150);
  564. frame1.TranslateTo(0, 0, 150);
  565. }
  566. if (two)
  567. {
  568. await frame2.TranslateTo(0, -15, 150);
  569. frame2.TranslateTo(0, 0, 150);
  570. }
  571. if (three)
  572. {
  573. await frame3.TranslateTo(0, -15, 150);
  574. frame3.TranslateTo(0, 0, 150);
  575. }
  576. if (four)
  577. {
  578. await frame4.TranslateTo(0, -15, 150);
  579. frame4.TranslateTo(0, 0, 150);
  580. }
  581. if (five)
  582. {
  583. await frame5.TranslateTo(0, -15, 150);
  584. frame5.TranslateTo(0, 0, 150);
  585. }
  586. });
  587. }
  588. //only when last entry is filled
  589. private void CheckEntries()
  590. {
  591. Task.Run(() =>
  592. {
  593. Thread.Sleep(750);
  594. Device.BeginInvokeOnMainThread(async () =>
  595. {
  596. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Checking"))
  597. {
  598. try
  599. {
  600. string s0 = ent0.Text;
  601. string s1 = ent1.Text;
  602. string s2 = ent2.Text;
  603. string s3 = ent3.Text;
  604. string s4 = ent4.Text;
  605. string s5 = ent5.Text;
  606. string fullstring = s0 + s1 + s2 + s3 + s4 + s5;
  607. Device.BeginInvokeOnMainThread(() => { clearBtn.Focus(); });
  608. bool check2FA = ClientFactory.Check2FA(fullstring);
  609. if (check2FA)
  610. Device.BeginInvokeOnMainThread(() => { LaunchMainPage(); });
  611. else
  612. return;
  613. }
  614. catch (Exception ex)
  615. {
  616. DisplayAlert("Error with 2FA", ex.Message, "OK");
  617. }
  618. }
  619. });
  620. });
  621. }
  622. #endregion
  623. private void CheckForLatestVersion()
  624. {
  625. Task.Run(async () =>
  626. {
  627. try
  628. {
  629. bool isLatest = true;
  630. try
  631. {
  632. isLatest = await MobileUtils.AppVersion.IsUsingLatestVersion();
  633. }
  634. catch (Exception eLatest)
  635. {
  636. string s = eLatest.Message;
  637. }
  638. if (!isLatest)
  639. {
  640. string latestVersionNumber = await MobileUtils.AppVersion.GetLatestVersionNumber();
  641. Device.BeginInvokeOnMainThread(async () =>
  642. {
  643. string chosenOption = await DisplayActionSheet(String.Format("Version {0} Available. Update now?", latestVersionNumber), "You will be reminded again in 10 minutes.", null, "Yes", "No");
  644. switch (chosenOption)
  645. {
  646. case "No":
  647. break;
  648. case "Cancel":
  649. break;
  650. case "Yes":
  651. Dispatcher.BeginInvokeOnMainThread(() => { MobileUtils.AppVersion.OpenAppInStore(); });
  652. break;
  653. default:
  654. break;
  655. }
  656. });
  657. }
  658. }
  659. catch { }
  660. });
  661. }
  662. protected override void OnDisappearing()
  663. {
  664. base.OnDisappearing();
  665. }
  666. private void ShowSplashPage()
  667. {
  668. twoFAvisible = false;
  669. SplashLayout.IsVisible = true;
  670. PINLayout.IsVisible = false;
  671. twoFAGrid.IsVisible = false;
  672. ToolbarItems.Clear();
  673. ToolbarItems.Add(new ToolbarItem("Settings", "", () =>
  674. {
  675. SettingsPage settingsform = new SettingsPage();
  676. settingsform.Disappearing += Settingsform_Disappearing;
  677. Navigation.PushAsync(settingsform);
  678. }));
  679. MasterGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
  680. MasterGrid.ColumnDefinitions[1].Width = new GridLength(0, GridUnitType.Absolute);
  681. MasterGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Absolute);
  682. }
  683. private void ShowPINPad()
  684. {
  685. PINLayout.IsVisible = true;
  686. SplashLayout.IsVisible = false;
  687. SplashLayout.IsVisible = false;
  688. MasterGrid.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Absolute);
  689. MasterGrid.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);
  690. MasterGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Absolute);
  691. ToolbarItems.Clear();
  692. ToolbarItems.Add(new ToolbarItem("Settings", "", () =>
  693. {
  694. SettingsPage settingsform = new SettingsPage();
  695. settingsform.Disappearing += Settingsform_Disappearing;
  696. Navigation.PushAsync(settingsform);
  697. }));
  698. pin = "";
  699. PIN.Text = "";
  700. OK.IsEnabled = false;
  701. Back.IsEnabled = false;
  702. }
  703. void Button_Click(object sender, EventArgs args)
  704. {
  705. pin = pin + (sender as Button).Text;
  706. PIN.Text = new string('*', pin.Length);
  707. OK.IsEnabled = true;
  708. Back.IsEnabled = true;
  709. ;
  710. }
  711. void Back_Click(object sender, EventArgs args)
  712. {
  713. // renove the last one
  714. if (String.IsNullOrEmpty(pin))
  715. return;
  716. pin = pin.Substring(0, pin.Length - 1);
  717. PIN.Text = new string('*', pin.Length);
  718. OK.IsEnabled = !String.IsNullOrEmpty(pin);
  719. Back.IsEnabled = !String.IsNullOrEmpty(pin);
  720. }
  721. async void OK_Click(object sender, EventArgs args)
  722. {
  723. RunValidate(true, pin);
  724. }
  725. void Settings_Click(System.Object sender, System.EventArgs e)
  726. {
  727. SettingsPage settingsform = new SettingsPage();
  728. settingsform.Disappearing += Settingsform_Disappearing;
  729. Navigation.PushAsync(settingsform);
  730. }
  731. private async void Settingsform_Disappearing(object sender, EventArgs e)
  732. {
  733. try
  734. {
  735. if (App.IsUserLoggedIn)
  736. await Navigation.PushAsync(new MainPage());
  737. }
  738. catch { }
  739. }
  740. }
  741. }