PINLoginPage.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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. string chosenOption = await DisplayActionSheet("Connection error - please check your connection. Try again?", "Cancel", null, "Yes", "No");
  154. switch (chosenOption)
  155. {
  156. case "Yes":
  157. Task.Run(() =>
  158. {
  159. Thread.Sleep(1000);
  160. Device.BeginInvokeOnMainThread(() =>
  161. {
  162. RunValidate();
  163. });
  164. });
  165. break;
  166. default:
  167. break;
  168. }
  169. }
  170. }
  171. private async void LaunchMainPage()
  172. {
  173. if (!App.Current.Properties.ContainsKey("SessionID"))
  174. App.Current.Properties.Add("SessionID", ClientFactory.SessionID);
  175. else
  176. App.Current.Properties["SessionID"] = ClientFactory.SessionID;
  177. if (timerRunning)
  178. timer.Dispose();
  179. App.Data.Refresh(true);
  180. Device.BeginInvokeOnMainThread(async () => { await Navigation.PushAsync(new MainPage()); });
  181. }
  182. private async void Check2FA()
  183. {
  184. try
  185. {
  186. string address2FA = "";
  187. if (!string.IsNullOrWhiteSpace(ClientFactory.Recipient2FA))
  188. {
  189. address2FA = ClientFactory.Recipient2FA;
  190. }
  191. Show2FAScreen(address2FA);
  192. }
  193. catch { }
  194. }
  195. #region 2FA Logic
  196. private void Show2FAScreen(string address2FA)
  197. {
  198. twoFAvisible = true;
  199. twoFAGrid.IsVisible = true;
  200. SplashLayout.IsVisible = false;
  201. PINLayout.IsVisible = false;
  202. twoFALbl.Text = address2FA;
  203. MasterGrid.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Absolute);
  204. MasterGrid.ColumnDefinitions[1].Width = new GridLength(0, GridUnitType.Absolute);
  205. MasterGrid.ColumnDefinitions[2].Width = new GridLength(1, GridUnitType.Star);
  206. AnimateIcons();
  207. if (Device.RuntimePlatform == Device.iOS)
  208. Run2FACheckTimer();
  209. }
  210. private void Run2FACheckTimer()
  211. {
  212. try
  213. {
  214. timer = new Timer(Callback, null, 4000, 500);
  215. timerRunning = true;
  216. }
  217. catch
  218. { }
  219. }
  220. private void Callback(object state)
  221. {
  222. try
  223. {
  224. if (checkingClipBoard)
  225. return;
  226. checkingClipBoard = true;
  227. Device.BeginInvokeOnMainThread(async () =>
  228. {
  229. if (string.IsNullOrWhiteSpace(ent0.Text))
  230. {
  231. if (Clipboard.HasText)
  232. {
  233. string text = await Clipboard.GetTextAsync();
  234. int i = 0;
  235. int.TryParse(text, out i);
  236. if (i != 0)
  237. {
  238. if (text.Length != 6)
  239. return;
  240. else
  241. {
  242. ent0.Text = text;
  243. timer.Dispose();
  244. timer = new Timer(Callback, null, 4000, 500);
  245. }
  246. }
  247. }
  248. }
  249. checkingClipBoard = false;
  250. });
  251. }
  252. catch { checkingClipBoard = false; }
  253. }
  254. private void AnimateIcons()
  255. {
  256. image1.TranslateTo(-70, 0, 0);
  257. image2.TranslateTo(-70, 0, 0);
  258. image3.TranslateTo(-70, 0, 0);
  259. image4.TranslateTo(-70, 0, 0);
  260. image5.TranslateTo(-70, 0, 0);
  261. image6.TranslateTo(-70, 0, 0);
  262. image7.TranslateTo(-70, 0, 0);
  263. image8.TranslateTo(-70, 0, 0);
  264. image9.TranslateTo(-70, 0, 0);
  265. Task.Run(() =>
  266. {
  267. for (int i = 0; i < 10; i++)
  268. {
  269. Device.BeginInvokeOnMainThread(() => { image1.TranslateTo(1200, 0, 30000); });
  270. Thread.Sleep(2500);
  271. Device.BeginInvokeOnMainThread(() => { image2.TranslateTo(1200, 0, 30000); });
  272. Thread.Sleep(2500);
  273. Device.BeginInvokeOnMainThread(() => { image3.TranslateTo(1200, 0, 30000); });
  274. Thread.Sleep(2500);
  275. Device.BeginInvokeOnMainThread(() => { image4.TranslateTo(1200, 0, 30000); });
  276. Thread.Sleep(2500);
  277. Device.BeginInvokeOnMainThread(() => { image5.TranslateTo(1200, 0, 30000); });
  278. Thread.Sleep(2500);
  279. Device.BeginInvokeOnMainThread(() => { image6.TranslateTo(1200, 0, 30000); });
  280. Thread.Sleep(2500);
  281. Device.BeginInvokeOnMainThread(() => { image7.TranslateTo(1200, 0, 30000); });
  282. Thread.Sleep(2500);
  283. Device.BeginInvokeOnMainThread(() => { image8.TranslateTo(1200, 0, 30000); });
  284. Thread.Sleep(2500);
  285. Device.BeginInvokeOnMainThread(() => { image9.TranslateTo(1200, 0, 30000); });
  286. Thread.Sleep(10000);
  287. Device.BeginInvokeOnMainThread(() =>
  288. {
  289. image1.TranslateTo(-70, 0, 0);
  290. image2.TranslateTo(-70, 0, 0);
  291. image3.TranslateTo(-70, 0, 0);
  292. image4.TranslateTo(-70, 0, 0);
  293. image5.TranslateTo(-70, 0, 0);
  294. image6.TranslateTo(-70, 0, 0);
  295. image7.TranslateTo(-70, 0, 0);
  296. image8.TranslateTo(-70, 0, 0);
  297. image9.TranslateTo(-70, 0, 0);
  298. });
  299. }
  300. });
  301. }
  302. private void ClearBtn_Clicked(object sender, EventArgs e)
  303. {
  304. ent0.Text = "";
  305. ent0.Focus();
  306. timer.Dispose();
  307. timer = new Timer(Callback, null, 4000, 500);
  308. }
  309. private async void TwoFAEntry0_Changed(object sender, EventArgs e)
  310. {
  311. if (autoChange)
  312. return;
  313. Device.BeginInvokeOnMainThread(async () =>
  314. {
  315. if (Clipboard.HasText)
  316. {
  317. string clipboard = await Clipboard.GetTextAsync();
  318. if (clipboard.Length == 6 && ent0.Text.Length == 6)
  319. {
  320. string s = ent0.Text;
  321. autoChange = true;
  322. ent0.Text = s[0].ToString();
  323. ent1.Text = s[1].ToString();
  324. ent2.Text = s[2].ToString();
  325. ent3.Text = s[3].ToString();
  326. ent4.Text = s[4].ToString();
  327. ent5.Text = s[5].ToString();
  328. ent1.IsEnabled = true;
  329. ent2.IsEnabled = true;
  330. ent3.IsEnabled = true;
  331. ent4.IsEnabled = true;
  332. ent5.IsEnabled = true;
  333. Animate(true, true, true, true, true, true);
  334. ent5.Focus();
  335. autoChange = false;
  336. CheckEntries();
  337. return;
  338. }
  339. }
  340. });
  341. if (!string.IsNullOrWhiteSpace(ent0.Text))
  342. {
  343. if (ent0.Text.Length == 1)
  344. {
  345. ent1.IsEnabled = true;
  346. ent1.Focus();
  347. Animate(true);
  348. }
  349. if (ent0.Text.Length == 2)
  350. {
  351. autoChange = true;
  352. string s = ent0.Text;
  353. ent0.Text = s[0].ToString();
  354. ent1.Text = s[1].ToString();
  355. ent1.IsEnabled = true;
  356. ent2.IsEnabled = true;
  357. ent2.Focus();
  358. Animate(true, true);
  359. autoChange = false;
  360. }
  361. if (ent0.Text.Length == 3)
  362. {
  363. string s = ent0.Text;
  364. autoChange = true;
  365. ent0.Text = s[0].ToString();
  366. ent1.Text = s[1].ToString();
  367. ent2.Text = s[2].ToString();
  368. ent1.IsEnabled = true;
  369. ent2.IsEnabled = true;
  370. ent3.IsEnabled = true;
  371. Animate(true, true, true);
  372. ent3.Focus();
  373. autoChange = false;
  374. }
  375. if (ent0.Text.Length == 4)
  376. {
  377. string s = ent0.Text;
  378. autoChange = true;
  379. ent0.Text = s[0].ToString();
  380. ent1.Text = s[1].ToString();
  381. ent2.Text = s[2].ToString();
  382. ent3.Text = s[3].ToString();
  383. ent1.IsEnabled = true;
  384. ent2.IsEnabled = true;
  385. ent3.IsEnabled = true;
  386. ent4.IsEnabled = true;
  387. ent4.Focus();
  388. Animate(true, true, true, true);
  389. autoChange = false;
  390. }
  391. if (ent0.Text.Length == 5)
  392. {
  393. string s = ent0.Text;
  394. autoChange = true;
  395. ent0.Text = s[0].ToString();
  396. ent1.Text = s[1].ToString();
  397. ent2.Text = s[2].ToString();
  398. ent3.Text = s[3].ToString();
  399. ent4.Text = s[4].ToString();
  400. ent1.IsEnabled = true;
  401. ent2.IsEnabled = true;
  402. ent3.IsEnabled = true;
  403. ent4.IsEnabled = true;
  404. ent5.IsEnabled = true;
  405. ent5.Focus();
  406. Animate(true, true, true, true, true);
  407. autoChange = false;
  408. }
  409. if (ent0.Text.Length == 6)
  410. {
  411. string s = ent0.Text;
  412. autoChange = true;
  413. ent0.Text = s[0].ToString();
  414. ent1.Text = s[1].ToString();
  415. ent2.Text = s[2].ToString();
  416. ent3.Text = s[3].ToString();
  417. ent4.Text = s[4].ToString();
  418. ent5.Text = s[5].ToString();
  419. ent5.Focus();
  420. ent1.IsEnabled = true;
  421. ent2.IsEnabled = true;
  422. ent3.IsEnabled = true;
  423. ent4.IsEnabled = true;
  424. ent5.IsEnabled = true;
  425. ent5.Focus();
  426. Animate(true, true, true, true, true, true);
  427. autoChange = false;
  428. CheckEntries();
  429. }
  430. ent0.MaxLength = 1;
  431. }
  432. else
  433. {
  434. ent0.MaxLength = 6;
  435. ent1.Text = "";
  436. ent1.IsEnabled = false;
  437. }
  438. }
  439. private async void TwoFAEntry1_Changed(object sender, EventArgs e)
  440. {
  441. if (autoChange)
  442. return;
  443. if (!string.IsNullOrWhiteSpace(ent1.Text))
  444. {
  445. await frame1.TranslateTo(0, -15, 150);
  446. frame1.TranslateTo(0, 0, 150);
  447. ent2.IsEnabled = true;
  448. ent2.Focus();
  449. }
  450. else
  451. {
  452. ent2.IsEnabled = false;
  453. ent2.Text = "";
  454. }
  455. }
  456. private async void TwoFAEntry2_Changed(object sender, EventArgs e)
  457. {
  458. if (autoChange)
  459. return;
  460. if (!string.IsNullOrWhiteSpace(ent2.Text))
  461. {
  462. await frame2.TranslateTo(0, -15, 150);
  463. frame2.TranslateTo(0, 0, 150);
  464. ent3.IsEnabled = true;
  465. ent3.Focus();
  466. }
  467. else
  468. {
  469. ent3.IsEnabled = false;
  470. ent3.Text = "";
  471. }
  472. }
  473. private async void TwoFAEntry3_Changed(object sender, EventArgs e)
  474. {
  475. if (autoChange)
  476. return;
  477. if (!string.IsNullOrWhiteSpace(ent3.Text))
  478. {
  479. await frame3.TranslateTo(0, -15, 150);
  480. frame3.TranslateTo(0, 0, 150);
  481. ent4.IsEnabled = true;
  482. ent4.Focus();
  483. }
  484. else
  485. {
  486. ent4.IsEnabled = false;
  487. ent4.Text = "";
  488. }
  489. }
  490. private async void TwoFAEntry4_Changed(object sender, EventArgs e)
  491. {
  492. if (autoChange)
  493. return;
  494. if (!string.IsNullOrWhiteSpace(ent4.Text))
  495. {
  496. await frame4.TranslateTo(0, -15, 150);
  497. frame4.TranslateTo(0, 0, 150);
  498. ent5.IsEnabled = true;
  499. ent5.Focus();
  500. }
  501. else
  502. {
  503. ent5.IsEnabled = false;
  504. ent5.Text = "";
  505. }
  506. }
  507. private async void TwoFAEntry5_Changed(object sender, EventArgs e)
  508. {
  509. if (autoChange)
  510. return;
  511. if (!string.IsNullOrWhiteSpace(ent5.Text))
  512. {
  513. Animate(true, true, true, true, true, true);
  514. CheckEntries();
  515. }
  516. }
  517. private void Animate(bool zero = false, bool one = false, bool two = false, bool three = false, bool four = false, bool five = false)
  518. {
  519. Device.BeginInvokeOnMainThread(async () =>
  520. {
  521. if (zero)
  522. {
  523. await frame0.TranslateTo(0, -15, 150);
  524. frame0.TranslateTo(0, 0, 150);
  525. }
  526. if (one)
  527. {
  528. await frame1.TranslateTo(0, -15, 150);
  529. frame1.TranslateTo(0, 0, 150);
  530. }
  531. if (two)
  532. {
  533. await frame2.TranslateTo(0, -15, 150);
  534. frame2.TranslateTo(0, 0, 150);
  535. }
  536. if (three)
  537. {
  538. await frame3.TranslateTo(0, -15, 150);
  539. frame3.TranslateTo(0, 0, 150);
  540. }
  541. if (four)
  542. {
  543. await frame4.TranslateTo(0, -15, 150);
  544. frame4.TranslateTo(0, 0, 150);
  545. }
  546. if (five)
  547. {
  548. await frame5.TranslateTo(0, -15, 150);
  549. frame5.TranslateTo(0, 0, 150);
  550. }
  551. });
  552. }
  553. //only when last entry is filled
  554. private void CheckEntries()
  555. {
  556. Task.Run(() =>
  557. {
  558. Thread.Sleep(750);
  559. Device.BeginInvokeOnMainThread(async () =>
  560. {
  561. using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Checking"))
  562. {
  563. try
  564. {
  565. string s0 = ent0.Text;
  566. string s1 = ent1.Text;
  567. string s2 = ent2.Text;
  568. string s3 = ent3.Text;
  569. string s4 = ent4.Text;
  570. string s5 = ent5.Text;
  571. string fullstring = s0 + s1 + s2 + s3 + s4 + s5;
  572. Device.BeginInvokeOnMainThread(() => { clearBtn.Focus(); });
  573. bool check2FA = ClientFactory.Check2FA(fullstring);
  574. if (check2FA)
  575. Device.BeginInvokeOnMainThread(() => { LaunchMainPage(); });
  576. else
  577. return;
  578. }
  579. catch (Exception ex)
  580. {
  581. DisplayAlert("Error with 2FA", ex.Message, "OK");
  582. }
  583. }
  584. });
  585. });
  586. }
  587. #endregion
  588. private void CheckForLatestVersion()
  589. {
  590. Task.Run(async () =>
  591. {
  592. bool isLatest = true;
  593. try
  594. {
  595. isLatest = await MobileUtils.AppVersion.IsUsingLatestVersion();
  596. }
  597. catch (Exception eLatest)
  598. {
  599. string s = eLatest.Message;
  600. }
  601. if (!isLatest)
  602. {
  603. string latestVersionNumber = await MobileUtils.AppVersion.GetLatestVersionNumber();
  604. Device.BeginInvokeOnMainThread(async () =>
  605. {
  606. string chosenOption = await DisplayActionSheet(String.Format("Version {0} Available. Update now?", latestVersionNumber), "You will be reminded again in 10 minutes.", null, "Yes", "No");
  607. switch (chosenOption)
  608. {
  609. case "No":
  610. break;
  611. case "Cancel":
  612. break;
  613. case "Yes":
  614. Dispatcher.BeginInvokeOnMainThread(() => { MobileUtils.AppVersion.OpenAppInStore(); });
  615. break;
  616. default:
  617. break;
  618. }
  619. });
  620. }
  621. });
  622. }
  623. protected override void OnDisappearing()
  624. {
  625. base.OnDisappearing();
  626. }
  627. private void ShowSplashPage()
  628. {
  629. twoFAvisible = false;
  630. SplashLayout.IsVisible = true;
  631. PINLayout.IsVisible = false;
  632. twoFAGrid.IsVisible = false;
  633. ToolbarItems.Clear();
  634. ToolbarItems.Add(new ToolbarItem("Settings", "", () =>
  635. {
  636. Settings settingsform = new Settings();
  637. settingsform.Disappearing += Settingsform_Disappearing;
  638. Navigation.PushAsync(settingsform);
  639. }));
  640. MasterGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
  641. MasterGrid.ColumnDefinitions[1].Width = new GridLength(0, GridUnitType.Absolute);
  642. MasterGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Absolute);
  643. }
  644. private void ShowPINPad()
  645. {
  646. PINLayout.IsVisible = true;
  647. SplashLayout.IsVisible = false;
  648. SplashLayout.IsVisible = false;
  649. MasterGrid.ColumnDefinitions[0].Width = new GridLength(0, GridUnitType.Absolute);
  650. MasterGrid.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star);
  651. MasterGrid.ColumnDefinitions[2].Width = new GridLength(0, GridUnitType.Absolute);
  652. ToolbarItems.Clear();
  653. ToolbarItems.Add(new ToolbarItem("Settings", "", () =>
  654. {
  655. Settings settingsform = new Settings();
  656. settingsform.Disappearing += Settingsform_Disappearing;
  657. Navigation.PushAsync(settingsform);
  658. }));
  659. pin = "";
  660. PIN.Text = "";
  661. OK.IsEnabled = false;
  662. Back.IsEnabled = false;
  663. }
  664. void Button_Click(object sender, EventArgs args)
  665. {
  666. pin = pin + (sender as Button).Text;
  667. PIN.Text = new string('*', pin.Length);
  668. OK.IsEnabled = true;
  669. Back.IsEnabled = true;
  670. ;
  671. }
  672. void Back_Click(object sender, EventArgs args)
  673. {
  674. // renove the last one
  675. if (String.IsNullOrEmpty(pin))
  676. return;
  677. pin = pin.Substring(0, pin.Length - 1);
  678. PIN.Text = new string('*', pin.Length);
  679. OK.IsEnabled = !String.IsNullOrEmpty(pin);
  680. Back.IsEnabled = !String.IsNullOrEmpty(pin);
  681. }
  682. async void OK_Click(object sender, EventArgs args)
  683. {
  684. RunValidate(true, pin);
  685. }
  686. void Settings_Click(System.Object sender, System.EventArgs e)
  687. {
  688. Settings settingsform = new Settings();
  689. settingsform.Disappearing += Settingsform_Disappearing;
  690. Navigation.PushAsync(settingsform);
  691. }
  692. private async void Settingsform_Disappearing(object sender, EventArgs e)
  693. {
  694. try
  695. {
  696. Settings settingsform = (Settings)sender;
  697. if (App.IsUserLoggedIn)
  698. await Navigation.PushAsync(new MainPage());
  699. }
  700. catch { }
  701. }
  702. }
  703. }