PINLoginPage.xaml.cs 28 KB

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