예제 #1
0
        public async Task UpdateAccountPasswordAsync(ChangePasswordModel parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var user = await _userManager.FindByIdAsync(parameters.UserId);

            if (user == null)
            {
                throw new Exception(HESException.GetMessage(HESCode.UserNotFound));
            }

            var isValidPassword = await _userManager.CheckPasswordAsync(user, parameters.OldPassword);

            if (!isValidPassword)
            {
                throw new Exception(HESException.GetMessage(HESCode.IncorrectCurrentPassword));
            }

            var changePasswordResult = await _userManager.ChangePasswordAsync(user, parameters.OldPassword, parameters.NewPassword);

            if (!changePasswordResult.Succeeded)
            {
                throw new Exception(HESException.GetIdentityResultErrors(changePasswordResult.Errors));
            }
        }
예제 #2
0
        private async Task LoginWithPasswordAsync()
        {
            try
            {
                await ButtonSpinner.SpinAsync(async() =>
                {
                    var response = await IdentityApiClient.LoginWithPasswordAsync(PasswordSignInModel);
                    response.ThrowIfFailed();

                    if (response.Succeeded)
                    {
                        NavigationManager.NavigateTo(Routes.Dashboard, true);
                        return;
                    }

                    if (response.RequiresTwoFactor)
                    {
                        NavigationManager.NavigateTo($"{Routes.LoginWith2Fa}?returnUrl={ReturnUrl}", true);
                        return;
                    }

                    if (response.IsLockedOut)
                    {
                        NavigationManager.NavigateTo(Routes.Lockout, true);
                        return;
                    }
                });
            }
            catch (HESException ex) when(ex.Code == HESCode.InvalidLoginAttempt)
            {
                ValidationErrorMessage.DisplayError(nameof(PasswordSignInModel.Password), HESException.GetMessage(ex.Code));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                SetErrorMessage(ex.Message);
            }
        }
예제 #3
0
        private async Task NextAsync()
        {
            try
            {
                await ButtonSpinner.SpinAsync(async() =>
                {
                    var user = await ApplicationUserService.GetUserByEmailAsync(UserEmailModel.Email);
                    if (user == null)
                    {
                        ValidationErrorMessage.DisplayError(nameof(UserEmailModel.Email), HESException.GetMessage(HESCode.UserNotFound));
                        return;
                    }

                    PasswordSignInModel.Email = UserEmailModel.Email;
                    HasSecurityKey            = (await Fido2Service.GetCredentialsByUserEmail(UserEmailModel.Email)).Count > 0;
                    AuthenticationStep        = AuthenticationStep.EnterPassword;
                });
            }
            catch (HESException ex)
            {
                ValidationErrorMessage.DisplayError(nameof(UserEmailModel.Email), ex.Message);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                SetErrorMessage(ex.Message);
            }
        }
예제 #4
0
        private async Task NextAsync()
        {
            try
            {
                await Button.SpinAsync(async() =>
                {
                    var user = await ApplicationUserService.GetUserByEmailAsync(UserEmailModel.Email);
                    if (user == null)
                    {
                        ValidationErrorMessage.DisplayError(nameof(UserEmailModel.Email), HESException.GetMessage(HESCode.UserNotFound));
                        return;
                    }

                    await SignInWithSecurityKeyAsync();
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
                SetErrorMessage(ex.Message);
            }
        }