//[ValidateAntiForgeryToken] public async Task <IActionResult> SetPassword(SetPasswordModel model) { if (!ModelState.IsValid) { return(View(model).WithError(JoinWithHtmlLineBreak(ModelState.GetErrorMessages()))); } try { var result = await _userService.SetPasswordAsync(model.UserId, model.Password); return(result.Succeeded ? RedirectToDefault.WithSuccess("Password was set with success.") : View(model).WithError(JoinWithHtmlLineBreak(result.GetAllErrors()))); } catch (ValidationException validationException) { return(View(model).WithError(validationException.Message)); } catch (Exception exception) { _appLogger.LogError(exception); return(View(model).WithError(MessagesOptions.GenericErrorMessage)); } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> SignIn(SignInModel model) { if (User.Identity.IsAuthenticated) { return(RedirectToDefault); } if (!ModelState.IsValid) { return(RedirectToDefault.WithError(JoinWithHtmlLineBreak(ModelState.GetErrorMessages()))); } try { var signInResult = await _authService.SignInAsync(model.NameOrEmail, model.Password, false); if (signInResult.IsLockedOut) { return(View("Lockout")); } return(signInResult.Succeeded ? RedirectToDefault : RedirectToDefault.WithError(MessagesOptions.LoginFailed)); } catch (Exception exception) { _appLogger.LogError(exception); return(RedirectToDefault.WithError(exception.Message)); } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Register(RegisterModel model) { if (User.Identity.IsAuthenticated) { return(RedirectToDefault); } if (!ModelState.IsValid) { return(RedirectToDefault.WithError(JoinWithHtmlLineBreak(ModelState.GetErrorMessages()))); } try { var createResult = await _userService.CreateAsync(Mapper.Map <UserCreateDto>(model)); if (!createResult.Succeeded) { return(RedirectToDefault.WithError(JoinWithHtmlLineBreak(createResult.GetAllErrors()))); } var signInResult = await _authService.SignInAsync(model.UserName, model.Password, false); return(signInResult.Succeeded ? RedirectToDefault : RedirectToDefault.WithError(GenericErrorMessage)); } catch (Exception exception) { _appLogger.LogError(exception); return(RedirectToDefault.WithError(exception.Message)); } }
public async Task <IActionResult> ExternalLoginCallback(string remoteError = null) { if (!string.IsNullOrEmpty(remoteError)) { return(RedirectToDefault.WithError(remoteError)); } var result = await _authService.ExternalSignInAsync(); if (result.Succeeded) { return(RedirectToDefault); } if (result.IsLockedOut) { return(View("Lockout")); } var externalInfo = await _authService.GetExternalLoginInfoAsync(); var provider = externalInfo.LoginProvider; var email = externalInfo.Principal.FindFirstValue(ClaimTypes.Email); var userName = email.Split('@')[0]; var confirmationModel = new ExternalLoginConfirmationModel { Provider = provider, Email = email, UserName = userName }; return(View("ExternalLoginConfirmation", confirmationModel)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> EditUser(EditUserModel model) { if (!model.WithPasswordChange) { ModelState .ClearKey(nameof(model.CurrentPassword)) .ClearKey(nameof(model.NewPassword)) .ClearKey(nameof(model.NewPasswordRepeat)); } if (!ModelState.IsValid) { return(View(model).WithError(JoinWithHtmlLineBreak(ModelState.GetErrorMessages()))); } try { var result = model.WithPasswordChange ? await _userService.EditAsync(model.UserId, model.UserName, model.CurrentPassword, model.NewPassword) : await _userService.EditAsync(model.UserId, model.UserName); if (result.Succeeded) { await _signInManager.SignOutAsync(); await _signInManager.SignInAsync(_currentUserAccessor.ApplicationUser, true); } return(result.Succeeded ? RedirectToDefault.WithSuccess("Edited with success.") : View(model).WithError(JoinWithHtmlLineBreak(result.GetAllErrors()))); } catch (ValidationException validationException) { return(View(model).WithError(validationException.Message)); } catch (Exception exception) { _appLogger.LogError(exception); return(View(model).WithError(MessagesOptions.GenericErrorMessage)); } }