Beispiel #1
0
        private async Task ExternalLoginAuthorizeAsync(LoginUserVM queryUser)
        {
            SetButtonsState(ButtonState.Disabled);
            _btnExternalLoginStates[queryUser.ExternalProvider] = ButtonState.Loading;

            var externalSchemes = LoginUserVM.ExternalLogins.ToList(); // would be overwritten by automapper;

            Mapper.Map(queryUser, LoginUserVM);
            LoginUserVM.ExternalLogins = externalSchemes;
            var externalLoginResult = await AccountService.ExternalLoginAuthorizeAsync(LoginUserVM);

            if (externalLoginResult.IsError)
            {
                SetButtonsState(ButtonState.Enabled);
                EditContext.AddValidationMessages(_validator.MessageStore, externalLoginResult.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, externalLoginResult.Message);

                return;
            }

            NavigationManager.NavigateTo(externalLoginResult.Result.ReturnUrl);
            await Main.PromptMessageAsync(PromptType.Success, externalLoginResult.Message);

            UserAuthStateProvider.StateChanged();
        }
Beispiel #2
0
        protected async Task FormRegister_ValidSubmitAsync()
        {
            _btnRegisterState = ButtonState.Loading;
            var registrationResult = await AccountService.RegisterAsync(RegisterUserVM);

            if (registrationResult.IsError)
            {
                _btnRegisterState = ButtonState.Enabled;
                if (registrationResult.Result?.ReturnUrl != null && RegisterUserVM.ReturnUrl != registrationResult.Result.ReturnUrl)
                {
                    NavigationManager.NavigateTo(registrationResult.Result.ReturnUrl); // redirect to `ResendEmailConfirmation` on successful registration but when email couldn't be deployed
                }
                EditContext.AddValidationMessages(_validator.MessageStore, registrationResult.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, registrationResult.Message);

                return;
            }

            var registereduser = registrationResult.Result;

            NavigationManager.NavigateTo(registereduser.ReturnUrl);
            await Main.PromptMessageAsync(PromptType.Success, registrationResult.Message);

            UserAuthStateProvider.StateChanged();
        }
        public async Task FormResendEmailConfirmation_ValidSubmitAsync()
        {
            _btnResendEmailConfirmationState = ButtonState.Loading;
            var resendEmailConfirmationResponse = await AccountService.ResendEmailConfirmationAsync(ResendEmailConfirmationUserVM);

            if (resendEmailConfirmationResponse.IsError)
            {
                _btnResendEmailConfirmationState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, resendEmailConfirmationResponse.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, resendEmailConfirmationResponse.Message);

                return;
            }

            NavigationManager.NavigateTo($"/Account/ConfirmEmail/?email={ResendEmailConfirmationUserVM.Email}&returnUrl={ResendEmailConfirmationUserVM.ReturnUrl?.HtmlEncode()}");
            await Main.PromptMessageAsync(PromptType.Success, resendEmailConfirmationResponse.Message);
        }
Beispiel #4
0
        public async Task FormAdminEditUser_ValidSubmitAsync()
        {
            _btnSaveUserState = ButtonState.Loading;
            var editUserResponse = await AdminService.EditUserAsync(AdminEditUserVM);

            if (editUserResponse.IsError)
            {
                _btnSaveUserState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, editUserResponse.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, editUserResponse.Message);

                return;
            }

            await Main.PromptMessageAsync(PromptType.Success, editUserResponse.Message);

            NavigationManager.NavigateTo(AdminEditUserVM.ReturnUrl);
        }
        protected async Task FormForgotPassword_ValidSubmitAsync()
        {
            _btnForgotPasswordState = ButtonState.Loading;
            var forgotPasswordResponse = await AccountService.ForgotPasswordAsync(ForgotPasswordUserVM);

            if (forgotPasswordResponse.IsError)
            {
                _btnForgotPasswordState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, forgotPasswordResponse.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, forgotPasswordResponse.Message);

                return;
            }

            var forgotPasswordUser = forgotPasswordResponse.Result;
            await Main.PromptMessageAsync(PromptType.Success, $"Reset Password link sent to: \"{forgotPasswordUser.Email}\"");

            NavigationManager.NavigateTo($"/Account/ResetPassword?email={forgotPasswordUser.Email}&returnUrl={forgotPasswordUser.ReturnUrl?.HtmlEncode()}");
        }
Beispiel #6
0
        public async Task FormAdminEditClaim_ValidSubmitAsync()
        {
            _btnSaveClaimState = ButtonState.Loading;
            var addClaimResp = await AdminService.EditClaimAsync(AdminEditClaimVM);

            if (addClaimResp.IsError)
            {
                _btnSaveClaimState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, addClaimResp.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, addClaimResp.Message);

                return;
            }

            await Main.PromptMessageAsync(PromptType.Success, addClaimResp.Message);

            NavigationManager.NavigateTo("/admin/claims");
            await Task.CompletedTask;
        }
Beispiel #7
0
        public async Task FormEdit_ValidSubmitAsync()
        {
            _btnSaveEditsState = ButtonState.Loading;
            var editResponse = await AccountService.EditAsync(EditUserVM);

            if (editResponse.IsError)
            {
                _btnSaveEditsState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, editResponse.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, editResponse.Message);

                return;
            }

            Mapper.Map(editResponse.Result, EditUserVM); // rebinding user would break the existing references, for the mapping to work properly 'EditUserVM --> EditUserVM' is required, otherwise the new object will be created properly but the existing destination won't be updated
            ParametersService.Parameters[nameof(EditUserVM)] = EditUserVM;
            NavigationManager.NavigateTo(EditUserVM.ReturnUrl);
            await Main.PromptMessageAsync(PromptType.Success, editResponse.Message);

            UserAuthStateProvider.StateChanged(); // mandatory since we are logging user out if the email was changed
        }
Beispiel #8
0
        protected async Task FormLogin_ValidSubmitAsync()
        {
            SetButtonsState(ButtonState.Disabled);
            _btnLoginState = ButtonState.Loading;

            var loginResult = await AccountService.LoginAsync(LoginUserVM);

            if (loginResult.IsError)
            {
                SetButtonsState(ButtonState.Enabled);
                EditContext.AddValidationMessages(_validator.MessageStore, loginResult.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, loginResult.Message);

                return;
            }

            NavigationManager.NavigateTo(loginResult.Result.ReturnUrl);
            await Main.PromptMessageAsync(PromptType.Success, loginResult.Message);

            UserAuthStateProvider.StateChanged();
        }
Beispiel #9
0
        private async Task ConfirmEmailAsync()
        {
            _btnConfirmEmailState = ButtonState.Loading;
            var emailConfirmationResponse = await AccountService.ConfirmEmailAsync(ConfirmUserVM.Email, ConfirmUserVM.ConfirmationCode);

            if (emailConfirmationResponse.IsError)
            {
                _btnConfirmEmailState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, emailConfirmationResponse.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, emailConfirmationResponse.Message); // can't update state on afterrender because it would cause an infinite loop

                return;
            }

            var confirmedUser = emailConfirmationResponse.Result;

            ConfirmUserVM.UserName = confirmedUser.UserName;
            IsEmailConfirmed       = true;
            NavigationManager.NavigateTo($"/Account/Login/?returnUrl={ConfirmUserVM.ReturnUrl?.HtmlEncode()}");
            await Main.PromptMessageAsync(PromptType.Success, $"Email for user: \"{confirmedUser.UserName}\" has been confirmed successfully", false); // can't update state on afterrender because it would cause an infinite loop
        } // https://localhost:44396/Account/[email protected]&code=xxx
Beispiel #10
0
        public async Task FormResetPassword_ValidSubmitAsync()
        {
            if (ResetPasswordUserVM.Email.IsNullOrWhiteSpace() || ResetPasswordUserVM.ResetPasswordCode.IsNullOrWhiteSpace())
            {
                return; // return silently because user chose to provide code manually
            }
            _btnChangePasswordState = ButtonState.Loading;
            var resetPasswordResponse = await AccountService.ResetPasswordAsync(ResetPasswordUserVM);

            if (resetPasswordResponse.IsError)
            {
                _btnChangePasswordState = ButtonState.Enabled;
                EditContext.AddValidationMessages(_validator.MessageStore, resetPasswordResponse.ValidationMessages);
                await Main.PromptMessageAsync(PromptType.Error, resetPasswordResponse.Message);

                return;
            }

            NavigationManager.NavigateTo($"/Account/Login?returnUrl={ResetPasswordUserVM.ReturnUrl?.HtmlEncode()}");
            await Main.PromptMessageAsync(PromptType.Success, resetPasswordResponse.Message);
        }