public async Task <ActionResult> ResetPassword([FromBody] ResetPasswordRequest request, [FromServices] IAuthenticationManager authentication, [FromServices] IEmailConfirmationService emailConfirmationService) { using (var repository = new Repository <User>(_provider)) { var user = await repository.Get(x => x.Id == request.UserId).SingleOrDefaultAsync(); if (user == null) { return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Указаны неверные данные"))); } var validateConfirmationResult = emailConfirmationService.ValidateConfirmationCode(user, request.Code); if (!validateConfirmationResult) { return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Указаны неверные данные либо ссылка для восстановления уже использовалась ранее"))); } var doPasswordMatch = await authentication.PasswordsMatched(user, request.Password); if (doPasswordMatch) { return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Старый пароль и новый совпадают"))); } await authentication.EditPasswordAsync(new UserAccountRequest { Email = user.Email, Password = request.Password, PasswordConfirm = request.ConfirmPassword }); return(Json(ApiResponse.Success(true))); } }
public async Task <IActionResult> ConfirmEmail([FromBody] ConfirmEmailRequest confirmEmailRequest, [FromServices] IEmailConfirmationService emailConfirmationService) { using (var repository = new Repository <User>(_provider)) { var user = await repository.Get(x => x.Id == confirmEmailRequest.UserId).SingleAsync(); if (user.Confirmed.HasValue) { return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Данная регистрация была подтверждена ранее"))); } var result = emailConfirmationService.ValidateConfirmationCode(user, confirmEmailRequest.Code); if (result) { var notificationSettingsRep = new Repository <NotificationSettings>(repository); var notificationSettings = new NotificationSettings { DocumentReceived = true, DocumentRejected = true, DocumentRetired = true, DocumentSend = true, InviteSend = true, ProfileAdd = true, ProfileRemove = true, DocumentSign = true, User = user }; await notificationSettingsRep.InsertAsync(notificationSettings); user.Confirmed = DateTime.Now; repository.Update(user); repository.Commit(); } return(Json(ApiResponse.Success(result))); } }