PINLoginPage.xaml.cs 29 KB

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