PINLoginPage.xaml.cs 27 KB

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