public OTPVerificationPage(RegisterReqModel regData)
 {
     InitializeComponent();
     NavigationPage.SetHasNavigationBar(this, false);
     otpVerificationVM = new OTPVerificationPageViewModel(Navigation, regData);
     BindingContext    = otpVerificationVM;
 }
 public OTPVerificationPageViewModel(INavigation navigation, RegisterReqModel regData) : base(navigation)
 {
     _regData            = regData;
     _navigation         = navigation;
     PageHeaderText      = "OTP Verification";
     IsBackButtonVisible = false;
     IsMenuVisible       = false;
     SubmitCommand       = new DelegateCommand(ExecuteOnSubmit);
     ResendOTPCommand    = new DelegateCommand(ExecuteOnResendOTP);
     GoToHomeCommand     = new DelegateCommand(ExecuteOnGoToHome);
     LoginRequestModel   = new LoginRequestModel();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Register new account
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task RegisterAsync(RegisterReqModel model)
        {
            var existAccount = await _context.Accounts.FirstOrDefaultAsync(a => a.UserName.ToLower().Equals(model.UserName.ToLower()) || a.Email.ToLower().Equals(model.Email.ToLower()));

            if (existAccount != null)
            {
                throw new CustomException(Errors.ACCOUNT_HAS_REGISTERED, Errors.ACCOUNT_HAS_REGISTERED_MSG);
            }

            var account = _mapper.Map <RegisterReqModel, Account>(model);

            await _context.Accounts.AddAsync(account);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public async Task <LoginResModel> ExternalLoginAsync(ExternalLoginReqModel model)
        {
            var user = await _context.Accounts.FirstOrDefaultAsync(a => a.UserName == model.Email);

            if (user == null)
            {
                var registerModel = new RegisterReqModel
                {
                    Email    = model.Email,
                    UserName = model.Email,
                    Password = model.ExternalId,
                    FullName = model.FullName
                };
                await RegisterAsync(registerModel);
            }

            var loginModel = new LoginReqModel()
            {
                Password = model.ExternalId,
                UserName = model.Email
            };

            return(await LoginAsync(loginModel));
        }
Ejemplo n.º 5
0
        private async void ExecuteOnRegistration(object obj)
        {
            RegisterReqModel reqregister = new RegisterReqModel();

            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    var isValidate = await IsRegistrationValidation();

                    if (isValidate)
                    {
                        UserDialogs.Instance.ShowLoading("Loading...", MaskType.Black);

                        reqregister.FirstName = FirstName;
                        reqregister.LastName  = LastName;
                        reqregister.Email     = Email;
                        reqregister.password  = Password;
                        reqregister.Gender    = SelectedGender;
                        reqregister.State     = SelectedState;
                        reqregister.City      = SelectedCity;
                        reqregister.MobileNo  = MobileNumber;
                        reqregister.Address   = Address;
                        reqregister.PinCode   = PinCode;

                        Cache.GlobalEmail = Email;
                        Cache.DisplayName = FirstName + " " + LastName;

                        HttpClientHelper apicall = new HttpClientHelper(ApiUrls.Url_User_Register, string.Empty);

                        var regjson  = JsonConvert.SerializeObject(reqregister);
                        var response = await apicall.Post <RegistrationResponseModel>(regjson);

                        if (response != null)
                        {
                            if (response.regStatus == "successful")
                            {
                                Settings.IsFirstTimeLoginSettings = true;
                                await Application.Current.MainPage.DisplayAlert("Registration", "Thank you for registration.", "OK");

                                LoginRequestModel.u = reqregister.Email;
                                LoginRequestModel.p = reqregister.password;
                                UserDialogs.Instance.ShowLoading("Loading...");
                                HttpClientHelper _apicall = new HttpClientHelper(ApiUrls.Url_JwtAuth_login, string.Empty);
                                var loginjson             = JsonConvert.SerializeObject(LoginRequestModel);
                                var _response             = await _apicall.Post <LoginResultResponseModel>(loginjson);

                                if (_response != null)
                                {
                                    if (_response.accessToken != null && _response.renewalToken != null)
                                    {
                                        Settings.AccessTokenSettings  = _response.accessToken;
                                        Settings.RenewalTokenSettings = _response.renewalToken;
                                        Settings.DisplayNameSettings  = _response.displayName;
                                        Cache.GlobalEmail             = reqregister.Email;
                                        Settings.DisplayEmailSettings = reqregister.Email;

                                        if (reqregister.Email == "*****@*****.**")
                                        {
                                            //code to go to main admin home page
                                            await _navigation.PushAsync(new MainAdminMasterDetailPage());
                                        }
                                        else
                                        {
                                            //code to go to main home page
                                            await _navigation.PushAsync(new MainMasterDetailPage());
                                        }

                                        UserDialogs.Instance.HideLoading();
                                        return;
                                    }
                                    else
                                    {
                                        UserDialogs.Instance.HideLoading();
                                        await UserDialogs.Instance.AlertAsync(AppConstant.LOGIN_FAILURE, "Login", "OK");

                                        return;
                                    }
                                }
                                else
                                {
                                    await Application.Current.MainPage.DisplayAlert("LoginError", "Something wrong...", "OK");
                                }
                                UserDialogs.Instance.HideLoading();
                            }
                            else
                            {
                                UserDialogs.Instance.HideLoading();
                                await Application.Current.MainPage.DisplayAlert("Registration", response.message, "OK");

                                return;
                            }
                        }
                        else
                        {
                            UserDialogs.Instance.HideLoading();
                            await Application.Current.MainPage.DisplayAlert("Registration", response.message, "OK");

                            return;
                        }
                        ////redirect to OTP Page with register data

                        ////call api to send otp on mailid
                        //HttpClientHelper _apicall = new HttpClientHelper(string.Format(ApiUrls.Url_User_SendOTP), string.Empty);
                        //Dictionary<string, string> dictquery = new Dictionary<string, string>();
                        //dictquery.Add("emailId", Email);
                        //var _response = await _apicall.Get<OTPResponseModel>(dictquery);
                        //if (_response != null)
                        //{
                        //    string message = "We will sent you OTP on your email id " + Email + ", Verify OTP to complete registration process.";
                        //    await Application.Current.MainPage.DisplayAlert("Registration", message , "OK");
                        //    Cache.globalOTP = _response.OTPPassword;
                        //    UserDialogs.Instance.HideLoading();
                        //    //redirect to OTP page
                        //    await _navigation.PushAsync(new OTPVerificationPage(reqregister));
                        //}
                        //else
                        //{
                        //    UserDialogs.Instance.HideLoading();
                        //    await Application.Current.MainPage.DisplayAlert("Registration", "Error sending OTP", "OK");
                        //}
                    }
                    else
                    {
                        UserDialogs.Instance.HideLoading();
                        return;
                    }
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    await Application.Current.MainPage.DisplayAlert("Network", AppConstant.NETWORK_FAILURE, "OK");

                    return;
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Registration Error", ex.Message, "OK");

                UserDialogs.Instance.HideLoading();
                return;
            }
        }
        private async void ExecuteOnSubmit(object parma)
        {
            try
            {
                RegisterReqModel reqregister = new RegisterReqModel();
                if (CrossConnectivity.Current.IsConnected)
                {
                    var isValidate = await IsCheckValidation();

                    if (isValidate)
                    {
                        if (Cache.globalOTP == VerificationCode)
                        {
                            Cache.globalOTP = string.Empty;
                            UserDialogs.Instance.ShowLoading("Loading...", MaskType.Black);

                            HttpClientHelper apicall = new HttpClientHelper(ApiUrls.Url_User_Register, string.Empty);
                            reqregister.FirstName = _regData.FirstName;
                            reqregister.LastName  = _regData.LastName;
                            reqregister.Email     = _regData.Email;
                            reqregister.password  = _regData.password;
                            reqregister.Gender    = _regData.Gender;
                            reqregister.State     = _regData.State;
                            reqregister.City      = _regData.City;
                            reqregister.MobileNo  = _regData.MobileNo;
                            reqregister.Address   = _regData.Address;
                            reqregister.PinCode   = _regData.PinCode;

                            var regjson  = JsonConvert.SerializeObject(reqregister);
                            var response = await apicall.Post <RegistrationResponseModel>(regjson);

                            if (response != null)
                            {
                                if (response.regStatus == "successful")
                                {
                                    Settings.IsFirstTimeLoginSettings = true;
                                    await Application.Current.MainPage.DisplayAlert("Registration", "Thank you for registration.", "OK");

                                    LoginRequestModel.u = _regData.Email;
                                    LoginRequestModel.p = _regData.password;
                                    UserDialogs.Instance.ShowLoading("Loading...");
                                    HttpClientHelper _apicall = new HttpClientHelper(ApiUrls.Url_JwtAuth_login, string.Empty);
                                    var loginjson             = JsonConvert.SerializeObject(LoginRequestModel);
                                    var _response             = await _apicall.Post <LoginResultResponseModel>(loginjson);

                                    if (_response != null)
                                    {
                                        if (_response.accessToken != null && _response.renewalToken != null)
                                        {
                                            Settings.AccessTokenSettings  = _response.accessToken;
                                            Settings.RenewalTokenSettings = _response.renewalToken;
                                            Settings.DisplayNameSettings  = _response.displayName;
                                            Cache.GlobalEmail             = _regData.Email;
                                            Settings.DisplayEmailSettings = _regData.Email;

                                            if (_regData.Email == "*****@*****.**")
                                            {
                                                //code to go to main admin home page
                                                await _navigation.PushAsync(new MainAdminMasterDetailPage());
                                            }
                                            else
                                            {
                                                //code to go to main home page
                                                await _navigation.PushAsync(new MainMasterDetailPage());
                                            }

                                            UserDialogs.Instance.HideLoading();
                                            return;
                                        }
                                        else
                                        {
                                            UserDialogs.Instance.HideLoading();
                                            await UserDialogs.Instance.AlertAsync(AppConstant.LOGIN_FAILURE, "Login", "OK");

                                            return;
                                        }
                                    }
                                    else
                                    {
                                        await Application.Current.MainPage.DisplayAlert("LoginError", "Something wrong...", "OK");
                                    }
                                    UserDialogs.Instance.HideLoading();
                                }
                                else
                                {
                                    UserDialogs.Instance.HideLoading();
                                    await Application.Current.MainPage.DisplayAlert("Registration", response.message, "OK");

                                    return;
                                }
                            }
                            else
                            {
                                UserDialogs.Instance.HideLoading();
                                await Application.Current.MainPage.DisplayAlert("Registration", response.message, "OK");

                                return;
                            }
                        }
                        else
                        {
                            await Application.Current.MainPage.DisplayAlert("Verfication Error", "Entered code doesn't match.", "OK");
                        }
                        UserDialogs.Instance.HideLoading();
                    }
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    await Application.Current.MainPage.DisplayAlert("Network", AppConstant.NETWORK_FAILURE, "OK");

                    return;
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Verfication Error", ex.Message, "OK");
            }
        }
        public async Task <HttpResponseData <SuccessfulRegisterRespModel, ClientsApiErrorCodes> > DoSignupUser(RegisterReqModel newUser)
        {
            var user = new MyAuthUser()
            {
                UserName = newUser.Email,
                Name     = newUser.Name,
                Surname  = newUser.Surname,
                Email    = newUser.Email
            };
            var result = await _userManager.CreateAsync(user, newUser.Password);

            if (result.Succeeded)
            {
                _logger.LogInformation("User created a new account with password.");
                return(new HttpResponseData <SuccessfulRegisterRespModel, ClientsApiErrorCodes>());

                /*var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                 * code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));*/
            }
            else
            {
                return(new HttpResponseData <SuccessfulRegisterRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.InternalError));
            }

            /*var callbackUrl = Url.Page(
             *  "/Account/ConfirmEmail",
             *  pageHandler: null,
             *  values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
             *  protocol: Request.Scheme);*/

            /* await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
             *   $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");*/

            /*if (_userManager.Options.SignIn.RequireConfirmedAccount)
             * {
             *  return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
             * }
             * else
             * {
             *  await _signInManager.SignInAsync(user, isPersistent: false);
             *  return LocalRedirect(returnUrl);
             * }*/
        }
        private async void ExecuteOnUpdate(object obj)
        {
            try
            {
                RegisterReqModel RegisterReq = new RegisterReqModel();
                if (CrossConnectivity.Current.IsConnected)
                {
                    var isValidate = await IsEditValidation();

                    if (isValidate)
                    {
                        UserDialogs.Instance.ShowLoading("Loading...", MaskType.Black);

                        HttpClientHelper apicall = new HttpClientHelper(ApiUrls.Url_UpdateUserProfileData, string.Empty);
                        RegisterReq.FirstName = FirstName;
                        RegisterReq.LastName  = LastName;
                        // RegisterReq.Email = Email;
                        RegisterReq.MobileNo = MobileNumber;
                        RegisterReq.State    = SelectedState;
                        RegisterReq.Gender   = SelectedGender;
                        RegisterReq.Address  = Address;
                        RegisterReq.City     = SelectedCity;
                        RegisterReq.PinCode  = PinCode;

                        var regjson  = JsonConvert.SerializeObject(RegisterReq);
                        var response = await apicall.Post <RegistrationResponseModel>(regjson);

                        if (response != null)
                        {
                            if (response.regStatus == "successful")
                            {
                                //redirect to same page
                                await Application.Current.MainPage.DisplayAlert("Update Profile", response.message, "OK");

                                await _navigation.PushAsync(new MainMasterDetailPage());

                                UserDialogs.Instance.HideLoading();
                            }
                            else
                            {
                                UserDialogs.Instance.HideLoading();
                                await Application.Current.MainPage.DisplayAlert("Update Profile", response.message, "OK");

                                return;
                            }
                        }
                        else
                        {
                            UserDialogs.Instance.HideLoading();
                            await Application.Current.MainPage.DisplayAlert("Update Profile", response.message, "OK");

                            return;
                        }
                        UserDialogs.Instance.HideLoading();
                    }
                    else
                    {
                        UserDialogs.Instance.HideLoading();
                        return;
                    }
                }
                else
                {
                    UserDialogs.Instance.HideLoading();
                    await Application.Current.MainPage.DisplayAlert("Network", AppConstant.NETWORK_FAILURE, "OK");

                    return;
                }
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading();
            }
        }
        public async Task <ActionResult <HttpResponseData <SuccessfulRegisterRespModel, ClientsApiErrorCodes> > > Post([FromBody] RegisterReqModel newUser)
        {
            HttpResponseData <SuccessfulRegisterRespModel, ClientsApiErrorCodes> response = await _authServices.DoSignupUser(newUser);

            if (response.Success == true)
            {
                return(Ok(response));
            }

            ClientsApiErrorCodes val = response.Error.ErrorCode;

            switch (val)
            {
            case ClientsApiErrorCodes.InternalError:
                goto FailureCase;
            }

            FailureCase : return(Unauthorized(new HttpResponseData <SuccessfulRegisterRespModel, ClientsApiErrorCodes>(ClientsApiErrorCodes.InternalError)));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Register(RegisterReqModel model)
        {
            await _authService.RegisterAsync(model);

            return(Ok(new { registerSucceed = true }));
        }