PINLoginPage.xaml.cs 27 KB

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