コード例 #1
0
        public async void CheckOtp(string value)
        {
            WarningText    = "";
            WarningVisible = false;
            if (value == "Delete")
            {
                if (pin.Length > 0)
                {
                    pin = pin.Remove(pin.Length - 1);
                    int countPin = pin.Length;
                    HintColorChange(countPin);
                }
            }
            else
            {
                bool isExistvalue = Unities.CheckDigitaAndLength(value, 1);
                if (!isExistvalue)
                {
                    WarningText    = "ค่าที่ใส่ไม่ใช่ตัวเลข";
                    WarningVisible = true;
                    try
                    {
                        Vibration.Vibrate();
                        var duration = TimeSpan.FromSeconds(1);
                        Vibration.Vibrate(duration);
                    }
                    catch (FeatureNotSupportedException ex)
                    {
                    }
                    catch (Exception ex)
                    {
                    }
                }
                pin += value;
                int countPin = pin.Length;
                HintColorChange(countPin);
                if (countPin == 6)
                {
                    var checkOtpData = await _authService.CheckOtp(email, pin, reference);

                    if (checkOtpData != null && !checkOtpData.IsError)
                    {
                        if (checkOtpData.Model != null && checkOtpData.Model.IsValidateOtp)
                        {
                            if (checkProcess == Status.LastPage.Login)
                            {
                                SetPinForAuthViewModel setPinForAuth = new SetPinForAuthViewModel(email);
                                await Application.Current.MainPage.Navigation.PushAsync(new PinPage(setPinForAuth));
                            }
                            else if (checkProcess == Status.LastPage.Register)
                            {
                                await Application.Current.MainPage.Navigation.PushAsync(new RegisterPage());
                            }
                            else
                            {
                                await Application.Current.MainPage.Navigation.PopToRootAsync();
                            }
                        }
                        else
                        {
                            pin      = "";
                            countPin = pin.Length;
                            HintColorChange(countPin);
                            WarningText    = "OTP ไม่ถูกต้องหรือหมดอายุ";
                            WarningVisible = true;
                            try
                            {
                                Vibration.Vibrate();
                                var duration = TimeSpan.FromSeconds(1);
                                Vibration.Vibrate(duration);
                            }
                            catch (FeatureNotSupportedException ex)
                            {
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else
                    {
                        pin      = "";
                        countPin = pin.Length;
                        HintColorChange(countPin);
                        WarningText    = "ไม่สามารถเชื่อมต่อได้";
                        WarningVisible = true;
                        try
                        {
                            Vibration.Vibrate();
                            var duration = TimeSpan.FromSeconds(1);
                            Vibration.Vibrate(duration);
                        }
                        catch (FeatureNotSupportedException ex)
                        {
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                if (countPin > 6)
                {
                    pin = pin.Substring(0, 5);
                }
            }
        }
コード例 #2
0
        public async void InputPinMethod(string value)
        {
            WarningText    = "";
            WarningVisible = false;
            if (value == "Delete")
            {
                if (pin.Length > 0)
                {
                    pin = pin.Remove(pin.Length - 1);
                    int countPin = pin.Length;
                    HintColorChange(countPin);
                }
            }
            else
            {
                bool isExistvalue = Unities.CheckDigitaAndLength(value, 1);
                if (!isExistvalue)
                {
                    WarningText    = "ค่าที่ใส่ไม่ใช่ตัวเลข";
                    WarningVisible = true;
                    try
                    {
                        Vibration.Vibrate();
                        var duration = TimeSpan.FromSeconds(1);
                        Vibration.Vibrate(duration);
                    }
                    catch (FeatureNotSupportedException ex)
                    {
                    }
                    catch (Exception ex)
                    {
                    }
                }
                pin += value;
                int countPin = pin.Length;
                HintColorChange(countPin);
                if (countPin == 6)
                {
                    if (oldPin != "" && newPin != "")
                    {
                        repeatNewPin = pin;
                        if (newPin == repeatNewPin)
                        {
                            var updateData = await _pinService.UpdatePin(newPin, oldPin, email);

                            if (updateData != null && !updateData.IsError)
                            {
                                await PopupNavigation.Instance.PushAsync(new ChangePasswordSuccess());

                                await Application.Current.MainPage.Navigation.PopAsync();
                            }
                        }
                        else
                        {
                            pin      = "";
                            countPin = pin.Length;
                            HintColorChange(countPin);
                            WarningText    = "รหัสผ่านทั้ง 2 ครั้งไม่ตรงกัน";
                            WarningVisible = true;
                            try
                            {
                                Vibration.Vibrate();
                                var duration = TimeSpan.FromSeconds(1);
                                Vibration.Vibrate(duration);
                            }
                            catch (FeatureNotSupportedException ex)
                            {
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    else if (oldPin != "")
                    {
                        ChangeDataRepeatNewPin();
                    }
                    else
                    {
                        var loginPinData = await _pinService.LoginByPin(pin, email);

                        if (loginPinData != null && !loginPinData.IsError && loginPinData.Model != null)
                        {
                            if (loginPinData.Model.IsLogin)
                            {
                                await SecureStorage.SetAsync("CountLogin", "0");

                                ChangeDataNewPin();
                            }
                            else
                            {
                                pin      = "";
                                countPin = pin.Length;
                                HintColorChange(countPin);
                                WarningText    = "รหัสผ่านไม่ถูกต้อง";
                                WarningVisible = true;
                                try
                                {
                                    Vibration.Vibrate();
                                    var duration = TimeSpan.FromSeconds(1);
                                    Vibration.Vibrate(duration);
                                }
                                catch (FeatureNotSupportedException ex)
                                {
                                }
                                catch (Exception ex)
                                {
                                }
                                countLogin++;
                                await SecureStorage.SetAsync("CountLogin", countLogin.ToString());

                                if (countLogin >= 5)
                                {
                                    ForceLogout();
                                }
                            }
                        }
                        else
                        {
                            pin      = "";
                            countPin = pin.Length;
                            HintColorChange(countPin);
                            WarningText    = "ไม่สามารถเชื่อมต่อได้";
                            WarningVisible = true;
                            try
                            {
                                Vibration.Vibrate();
                                var duration = TimeSpan.FromSeconds(1);
                                Vibration.Vibrate(duration);
                            }
                            catch (FeatureNotSupportedException ex)
                            {
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
                if (countPin > 6)
                {
                    pin = pin.Substring(0, 5);
                }
            }
        }
コード例 #3
0
        public async void LoginByPin(string value)
        {
            WarningText    = "";
            WarningVisible = false;
            if (value == "Delete")
            {
                if (pin.Length > 0)
                {
                    pin = pin.Remove(pin.Length - 1);
                    int countPin = pin.Length;
                    HintColorChange(countPin);
                }
            }
            else
            {
                bool isExistvalue = Unities.CheckDigitaAndLength(value, 1);
                if (!isExistvalue)
                {
                    WarningText    = "ค่าที่ใส่ไม่ใช่ตัวเลข";
                    WarningVisible = true;
                    try
                    {
                        Vibration.Vibrate();
                        var duration = TimeSpan.FromSeconds(1);
                        Vibration.Vibrate(duration);
                    }
                    catch (FeatureNotSupportedException ex)
                    {
                    }
                    catch (Exception ex)
                    {
                    }
                }
                pin += value;
                int countPin = pin.Length;
                HintColorChange(countPin);
                if (countPin == 6)
                {
                    var loginPinData = await _pinService.LoginByPin(pin, email);

                    if (loginPinData != null && !loginPinData.IsError && loginPinData.Model != null)
                    {
                        if (loginPinData.Model.IsLogin)
                        {
                            try
                            {
                                await SecureStorage.SetAsync("CountLogin", "0");

                                var refreshToken = await SecureStorage.GetAsync("RefreshToken");;
                                var tokenData    = await _authService.GetTokenByRefreshToken(email, refreshToken);

                                if (tokenData != null || !tokenData.IsError)
                                {
                                    if (tokenData.Model == null || tokenData.Model.Token == null)
                                    {
                                        ErrorViewModel errorViewModel = new ErrorViewModel("กรุณาเข้าสู่ระบบอีกครั้ง", (int)EW_Enumerations.EW_ErrorTypeEnum.Error, ForceLogoutForErrorPopup);
                                        await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                                    }
                                    else
                                    {
                                        await SecureStorage.SetAsync("Token", tokenData.Model.Token);

                                        App.Account = await SecureStorage.GetAsync("Account");

                                        App.Email = await SecureStorage.GetAsync("Email");

                                        App.FirstName = await SecureStorage.GetAsync("FirstName");

                                        App.LastName = await SecureStorage.GetAsync("LastName");

                                        string preBirthDate = await SecureStorage.GetAsync("BirthDate");

                                        try
                                        {
                                            App.BirthDate = DateTime.Parse(preBirthDate);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                        App.MobileNumber = await SecureStorage.GetAsync("MobileNumber");

                                        int gender = 0;
                                        int.TryParse(await SecureStorage.GetAsync("Gender"), out gender);
                                        App.Gender = (EWalletV2.Api.ViewModels.EW_Enumerations.EW_GenderEnum)gender;
                                        Application.Current.MainPage = new NavigationPage(new UserTabbedPage());
                                    }
                                }
                                else
                                {
                                    pin      = "";
                                    countPin = pin.Length;
                                    HintColorChange(countPin);
                                    WarningText    = "ไม่สามารถเชื่อมต่อได้";
                                    WarningVisible = true;
                                    try
                                    {
                                        Vibration.Vibrate();
                                        var duration = TimeSpan.FromSeconds(1);
                                        Vibration.Vibrate(duration);
                                    }
                                    catch (FeatureNotSupportedException ex)
                                    {
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                ErrorViewModel errorViewModel = new ErrorViewModel("โทรศัพท์ของท่านไม่สามารถใช้งานแอพพลิเคชั่นนี้ได้", (int)EW_Enumerations.EW_ErrorTypeEnum.Warning, CloseApp);
                                await PopupNavigation.Instance.PushAsync(new Error(errorViewModel));
                            }
                        }
                        else
                        {
                            pin      = "";
                            countPin = pin.Length;
                            HintColorChange(countPin);
                            WarningText    = "รหัสผ่านไม่ถูกต้อง";
                            WarningVisible = true;
                            try
                            {
                                Vibration.Vibrate();
                                var duration = TimeSpan.FromSeconds(1);
                                Vibration.Vibrate(duration);
                            }
                            catch (FeatureNotSupportedException ex)
                            {
                            }
                            catch (Exception ex)
                            {
                            }
                            countLogin++;
                            await SecureStorage.SetAsync("CountLogin", countLogin.ToString());

                            if (countLogin >= 5)
                            {
                                ForceLogout();
                            }
                        }
                    }
                    else
                    {
                        pin      = "";
                        countPin = pin.Length;
                        HintColorChange(countPin);
                        WarningText    = "ไม่สามารถเชื่อมต่อได้";
                        WarningVisible = true;
                        try
                        {
                            Vibration.Vibrate();
                            var duration = TimeSpan.FromSeconds(1);
                            Vibration.Vibrate(duration);
                        }
                        catch (FeatureNotSupportedException ex)
                        {
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                if (countPin > 6)
                {
                    pin = pin.Substring(0, 5);
                    HintColorChange(pin.Length);
                }
            }
        }
コード例 #4
0
 public async void InputPinMethod(string value)
 {
     WarningText    = "";
     WarningVisible = false;
     if (value == "Delete")
     {
         if (pin.Length > 0)
         {
             pin = pin.Remove(pin.Length - 1);
             int countPin = pin.Length;
             HintColorChange(countPin);
         }
     }
     else
     {
         bool isExistvalue = Unities.CheckDigitaAndLength(value, 1);
         if (!isExistvalue)
         {
             WarningText    = "ค่าที่ใส่ไม่ใช่ตัวเลข";
             WarningVisible = true;
             try
             {
                 Vibration.Vibrate();
                 var duration = TimeSpan.FromSeconds(1);
                 Vibration.Vibrate(duration);
             }
             catch (FeatureNotSupportedException ex)
             {
             }
             catch (Exception ex)
             {
             }
         }
         pin += value;
         int countPin = pin.Length;
         HintColorChange(countPin);
         if (countPin == 6)
         {
             if (lastPage == Status.LastPage.Login)
             {
                 if (repeatPin == "")
                 {
                     ChangeDataJoint();
                 }
                 else
                 {
                     if (pin == repeatPin)
                     {
                         await Login();
                     }
                     else
                     {
                         pin      = "";
                         countPin = pin.Length;
                         HintColorChange(countPin);
                         WarningText    = "รหัสผ่านทั้ง 2 ครั้งไม่ตรงกัน";
                         WarningVisible = true;
                         try
                         {
                             Vibration.Vibrate();
                             var duration = TimeSpan.FromSeconds(1);
                             Vibration.Vibrate(duration);
                         }
                         catch (FeatureNotSupportedException ex)
                         {
                         }
                         catch (Exception ex)
                         {
                         }
                     }
                 }
             }
             else if (lastPage == Status.LastPage.Register)
             {
                 if (repeatPin == "")
                 {
                     ChangeDataJoint();
                 }
                 else
                 {
                     if (pin == repeatPin)
                     {
                         register.Pin = pin;
                         await Register();
                     }
                     else
                     {
                         pin      = "";
                         countPin = pin.Length;
                         HintColorChange(countPin);
                         WarningText    = "รหัสผ่านทั้ง 2 ครั้งไม่ตรงกัน";
                         WarningVisible = true;
                         try
                         {
                             Vibration.Vibrate();
                             var duration = TimeSpan.FromSeconds(1);
                             Vibration.Vibrate(duration);
                         }
                         catch (FeatureNotSupportedException ex)
                         {
                         }
                         catch (Exception ex)
                         {
                         }
                     }
                 }
             }
             else
             {
                 await Application.Current.MainPage.Navigation.PopToRootAsync();
             }
         }
         if (countPin > 6)
         {
             pin = pin.Substring(0, 5);
         }
     }
 }