public async Task <ActionResult> ChangePassword(string returnUrl, ChangePasswordViewModel vm) { var redirectAction = await ValidateChangePasswordRouteAsync(); if (redirectAction != null) { return(redirectAction); } await _contentRepository .WithModelState(this) .Users() .UpdatePasswordByCredentialsAsync(new UpdateUserPasswordByCredentialsCommand() { UserAreaCode = CofoundryAdminUserArea.Code, Username = vm.Username, NewPassword = vm.NewPassword, OldPassword = vm.OldPassword }); ViewBag.ReturnUrl = RedirectUrlHelper.GetAndValidateReturnUrl(this); var viewPath = ViewPathFormatter.View(CONTROLLER_NAME, nameof(ChangePassword)); return(View(viewPath, vm)); }
public async Task <ActionResult> Login(string returnUrl, SignInViewModel viewModel) { var authResult = await _contentRepository .WithModelState(this) .Users() .Authentication() .AuthenticateCredentials(new AuthenticateUserCredentialsQuery() { Username = viewModel.Username, Password = viewModel.Password, UserAreaCode = CofoundryAdminUserArea.Code, PropertyToValidate = nameof(viewModel.Password) }) .ExecuteAsync(); if (!ModelState.IsValid) { var viewPath = ViewPathFormatter.View(CONTROLLER_NAME, nameof(Login)); return(View(viewPath, viewModel)); } // Support redirect urls from login var redirectUrl = RedirectUrlHelper.GetAndValidateReturnUrl(this); if (authResult.User.RequirePasswordChange) { return(Redirect(_adminRouteLibrary.Auth.ChangePassword(returnUrl))); } // If no action required, log the user in await _contentRepository .Users() .Authentication() .SignInAuthenticatedUserAsync(new SignInAuthenticatedUserCommand() { UserId = authResult.User.UserId, RememberUser = true }); if (redirectUrl != null) { return(Redirect(redirectUrl)); } return(await GetLoggedInDefaultRedirectActionAsync()); }