private async void Register()
        {
            bool isValidateName = Unities.ValidateName(FirstName);

            if (!isValidateName)
            {
                FirstName = "";
            }
            bool isValidateLastName = Unities.ValidateName(LastName);

            if (!isValidateLastName)
            {
                LastName = "";
            }
            bool isValidateDate = Unities.ValidateStringDateFormat(BirthDate);

            if (!isValidateDate)
            {
                BirthDate = "";
            }
            bool isValidateEmail = Unities.CheckEmailFormat(Email);

            if (!isValidateEmail)
            {
                Email = "";
            }
            if (!string.IsNullOrEmpty(MobileNumber))
            {
                MobileNumber = Regex.Replace(MobileNumber, @"[^\d]", "");
            }
            bool isValidatePhoneNumber = Unities.ValidateStringMobile(MobileNumber);

            if (!isValidatePhoneNumber)
            {
                MobileNumber = "";
            }
            if (isValidateName && isValidateLastName && isValidateDate && isValidateEmail && isValidatePhoneNumber)
            {
                RegisterCommand register = new RegisterCommand
                {
                    BirthDate    = DateTime.ParseExact(BirthDate, "dd/MM/yyyy", null),
                    Email        = Email,
                    FirstName    = FirstName,
                    LastName     = LastName,
                    Pin          = Pin,
                    MobileNumber = MobileNumber,
                    Gender       = Gender
                };
                SetPinForAuthViewModel authViewModel = new SetPinForAuthViewModel(register);

                await Application.Current.MainPage.Navigation.PushAsync(new PinPage(authViewModel));
            }
            else
            {
                await PopupNavigation.PushAsync(new Error(new ErrorViewModel("กรอกข้อมูลไม่ถูกต้อง", (int)EW_Enumerations.EW_ErrorTypeEnum.Warning)));
            }
        }
        public LoginByPinViewModel()
        {
            title            = "";
            image            = "icon_PIN";
            blackDetail      = "ใส่รหัสผ่าน";
            grayDetail       = "ใส่รหัสผ่านของคุณ";
            referenceText    = "";
            referenceVisible = false;
            orangeText       = "ลืมรหัสผ่าน";
            orangeVisible    = true;
            warningText      = "";
            warningVisible   = false;
            backVisible      = false;
            pin = "";

            OrangeTextTab = new Command(GoToForgotPasswordPage);
            InputPin      = new Command <string>(LoginByPin);

            try
            {
                email = SecureStorage.GetAsync("Email").Result;
                bool checkFingerPrint = Convert.ToBoolean(SecureStorage.GetAsync("IsFingerprintEnabled").Result);
                if (checkFingerPrint)
                {
                    fingerTabVisible = true;
                    Fingerprint      = new Command(LoginByFingerprint);
                }
                else
                {
                    fingerTabVisible = false;
                }
                bool isExistEmail = Unities.CheckEmailFormat(email);
                if (!isExistEmail)
                {
                    ForceLogout();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Get Email And Fingerprint in LoginViewModel : {0}", e);
                ForceLogout();
            }
            try
            {
                countLogin = Int32.Parse(SecureStorage.GetAsync("CountLogin").Result);
            }
            catch (Exception e)
            {
                countLogin = 0;
                Console.WriteLine("countLogin in LoginViewModel : {0}", e);
            }
        }
Exemplo n.º 3
0
        private async void Edit()
        {
            if (IsEditMode)
            {
                bool isValidateName     = Unities.ValidateName(FirstName);
                bool isValidateLastName = Unities.ValidateName(LastName);
                bool isValidateDate     = Unities.ValidateStringDateFormat(BirthDate);
                bool isValidateEmail    = Unities.CheckEmailFormat(Email);
                bool isValidatePhoneNum = Unities.ValidateStringMobile(MobileNumber);
                if (isValidateName && isValidateLastName && isValidateDate && isValidateEmail && isValidatePhoneNum)
                {
                    UpdateUserCommand updateUserCommand = new UpdateUserCommand
                    {
                        BitrhDate    = DateTime.ParseExact(BirthDate, "dd/MM/yyyy", null),
                        Email        = Email,
                        FirstName    = FirstName,
                        LastName     = LastName,
                        MobileNumber = MobileNumber,
                        Gender       = Gender
                    };
                    var editResult = await _userService.UpdateUser(updateUserCommand);

                    bool isError = editResult.IsError;
                    if (isError)
                    {
                        await PopupNavigation.PushAsync(new Error(new ErrorViewModel("Error", (int)EW_Enumerations.EW_ErrorTypeEnum.Warning)));
                    }
                    else
                    {
                        //TODO: Show Completed Popup
                        StoreValue(updateUserCommand);

                        IsEditMode     = false;
                        ShowEditButton = true;
                        await PopupNavigation.PushAsync(new SavedProfile());

                        Application.Current.MainPage.Navigation.PushAsync(new EditProfilePage());
                    }
                }
                else
                {
                    await PopupNavigation.PushAsync(new Error(new ErrorViewModel("กรอกข้อมูลไม่ถูกต้อง", (int)EW_Enumerations.EW_ErrorTypeEnum.Warning)));
                }
            }
            else
            {
                IsEditMode     = true;
                ShowEditButton = false;
            }
        }
Exemplo n.º 4
0
        private async void SignIn()
        {
            IsProcess = true;
            bool isEmail = Unities.CheckEmailFormat(Email);

            if (isEmail)
            {
                ResultServiceModel <CheckEmailViewModel> result = await _authService.SignIn(Email);

                if (result.IsError || result.Model == null)
                {
                    ErrorViewModel errorView = new ErrorViewModel("ไม่สามารถเชื่อมต่อกับระบบได้");
                    IsProcess = false;
                    await PopupNavigation.Instance.PushAsync(new Error(errorView));
                }
                else
                {
                    if (result.Model.Role != 0)
                    {
                        ErrorViewModel errorView = new ErrorViewModel("กรุณาใช้แอพพลิเคชั่นสำหรับผู้ค้าหรือแอดมิน");
                        IsProcess = false;
                        await PopupNavigation.Instance.PushAsync(new Error(errorView));

                        return;
                    }

                    App.Email = Email;

                    if (result.Model.IsExist == true)
                    {
                        IsProcess = false;
                        var status = Status.LastPage.Login;
                        await Application.Current.MainPage.Navigation.PushAsync(new PinPage(new OtpRegisViewModel(Email, result.Model.RefNumber, status)));
                    }
                    else
                    {
                        IsProcess = false;
                        var status = Status.LastPage.Register;
                        await Application.Current.MainPage.Navigation.PushAsync(new PinPage(new OtpRegisViewModel(Email, result.Model.RefNumber, status)));
                    }
                }
            }
            else
            {
                ErrorViewModel errorView = new ErrorViewModel("โปรดกรอก Username เป็น format Email", (int)EW_Enumerations.EW_ErrorTypeEnum.Warning);
                IsProcess = false;
                await PopupNavigation.Instance.PushAsync(new Error(errorView));
            }
        }
Exemplo n.º 5
0
        public async void SentOtpAgain()
        {
            bool isExistEmail = Unities.CheckEmailFormat(email);

            if (isExistEmail)
            {
                var signInData = await _authService.SignIn(email);

                if (signInData != null && !signInData.IsError)
                {
                    Status.LastPage lastPage;
                    if (signInData.Model.IsExist)
                    {
                        lastPage = Status.LastPage.Login;
                    }
                    else
                    {
                        lastPage = Status.LastPage.Register;
                    }
                    OtpRegisViewModel otpRegis = new OtpRegisViewModel(email, signInData.Model.RefNumber, lastPage);
                    await Application.Current.MainPage.Navigation.PushAsync(new PinPage(otpRegis));
                }
                else
                {
                    WarningText    = "ไม่สามารถเชื่อมต่อได้";
                    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();
            }
        }
Exemplo n.º 6
0
        public ChangePasswordViewModel()
        {
            title            = "เปลี่ยนรหัสผ่าน";
            image            = "icon_PIN";
            blackDetail      = "ใส่รหัสผ่าน";
            grayDetail       = "ใส่รหัสผ่านของคุณ";
            referenceText    = "";
            referenceVisible = false;
            orangeText       = "ลืมรหัสผ่าน";
            orangeVisible    = true;
            warningText      = "";
            warningVisible   = false;
            backVisible      = true;
            fingerTabVisible = false;
            OrangeTextTab    = new Command(GoToForgotPasswordPage);
            InputPin         = new Command <string>(InputPinMethod);
            GoBack           = new Command(BackPage);
            pin          = "";
            oldPin       = "";
            newPin       = "";
            repeatNewPin = "";
            email        = App.Email;
            bool isExistEmail = Unities.CheckEmailFormat(email);

            if (!isExistEmail)
            {
                ForceLogout();
            }
            try
            {
                countLogin = Int32.Parse(SecureStorage.GetAsync("CountLogin").Result);
            }
            catch (Exception e)
            {
                countLogin = 0;
                Console.WriteLine("countLogin in ChangePasswordViewModel : {0}", e);
            }
        }
Exemplo n.º 7
0
        public async void SentOtpAgain()
        {
            bool isExistEmail = Unities.CheckEmailFormat(email);

            if (isExistEmail)
            {
                var checkForgotData = await _pinService.CheckForgotPin(birthDate, email);

                if (checkForgotData != null && !checkForgotData.IsError)
                {
                    OtpForgotPassViewModel otpForgotPass = new OtpForgotPassViewModel(email, checkForgotData.Model.RefNumber, birthDate);
                    await Application.Current.MainPage.Navigation.PushAsync(new PinPage(otpForgotPass));
                }
                else
                {
                    WarningText    = "ไม่สามารถเชื่อมต่อได้";
                    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();
            }
        }
        private async void CheckPin()
        {
            IsProcess = true;
            DateTime birthDate = new DateTime();

            error = null;
            int errorType = 0;

            try
            {
                var inputDateTime = DateTime.ParseExact(BirthDate, "dd/MM/yyyy", null);
                birthDate = Convert.ToDateTime(inputDateTime);
            }
            catch (Exception e)
            {
                error = "Invalid BirthDate format is\n Example : 25/12/2562";
            }
            bool checkEmailFormat = false;

            if (!string.IsNullOrEmpty(Email))
            {
                checkEmailFormat = Unities.CheckEmailFormat(Email);
            }
            if (!checkEmailFormat)
            {
                error += "\n Invalid Email Format";
            }
            if (!string.IsNullOrEmpty(error))
            {
                IsProcess = false;
                ErrorViewModel errorView = new ErrorViewModel(error, errorType);
                await PopupNavigation.Instance.PushAsync(new Error(errorView));
            }
            else
            {
                var resultCaller = await _pinService.CheckForgotPin(birthDate, Email);

                if (resultCaller == null || resultCaller.Model == null || string.IsNullOrEmpty(resultCaller.Model.RefNumber))
                {
                    error = "ขออภัย! ไม่พบอีเมลล์ที่กรอกในระบบ";
                }
                else if (resultCaller.IsError)
                {
                    error     = "ขออภัย! ไม่สามารถเชื่อมต่อได้";
                    errorType = 1;
                }
                else
                {
                    IsProcess = false;
                    string resultRefOtp = resultCaller.Model.RefNumber;
                    await PopupNavigation.Instance.PopAllAsync();

                    await Application.Current.MainPage.Navigation.PushAsync(new PinPage(new OtpForgotPassViewModel(Email, resultRefOtp, birthDate)));
                }
                if (!string.IsNullOrEmpty(error))
                {
                    IsProcess = false;
                    ErrorViewModel errorView = new ErrorViewModel(error, errorType);
                    await PopupNavigation.Instance.PushAsync(new Error(errorView));
                }
            }
        }