public async Task <CommonResult> ResetPasswordAsync(ResetPasswordModel criterias) { ValidateResetPassword(criterias); var user = await _userManager.FindByEmailAsync(criterias.Email); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) { throw new UnauthorizedAccessException("ResetPasswordFailed"); } var result = await _userManager.ResetPasswordAsync(user, criterias.Key, criterias.Password); if (!result.Succeeded) { var errors = result.Errors.Select(x => new CommonError() { Message = x.Description, Code = x.Code }); return(CommonResult.Failed(errors)); } await _userManager.RemoveAuthenticationTokenAsync(user, ServiceProvidersNameConst.CAMINO_API_AUTH, criterias.Key); return(CommonResult.Success()); }
public async Task <CommonResult> ActiveAsync(ActiveUserModel criterias) { var user = await _userManager.FindByNameAsync(criterias.Email); if (!await _userManager.IsEmailConfirmedAsync(user)) { var result = await _userManager.ConfirmEmailAsync(user, criterias.ActiveKey); if (result.Succeeded) { return(CommonResult.Success()); } var errors = result.Errors.Select(x => new CommonError() { Message = x.Description, Code = x.Code }); return(CommonResult.Failed(errors)); } return(CommonResult.Failed(new CommonError() { Message = "The user is already confirmed" })); }
public async Task <CommonResult> ForgotPasswordAsync(ForgotPasswordModel criterias) { ValidateForgotPassword(criterias); var user = await _userManager.FindByEmailAsync(criterias.Email); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) { throw new CaminoApplicationException("ForgotPasswordConfirmation"); } var resetPasswordToken = await _userManager.GeneratePasswordResetTokenAsync(user); var result = await _userManager.SetAuthenticationTokenAsync(user, ServiceProvidersNameConst.CAMINO_API_AUTH, IdentitySettings.RESET_PASSWORD_PURPOSE, resetPasswordToken); if (!result.Succeeded) { var errors = result.Errors.Select(x => new CommonError { Message = x.Description, Code = x.Code }); return(CommonResult.Failed(errors)); } await SendPasswordChangeAsync(criterias, user, resetPasswordToken); return(CommonResult.Success()); }
public async Task <CommonResult> SignupAsync(SignupModel criterias) { var user = new ApplicationUser() { BirthDate = criterias.BirthDate, DisplayName = $"{criterias.Lastname} {criterias.Firstname}", Email = criterias.Email, Firstname = criterias.Firstname, Lastname = criterias.Lastname, GenderId = (byte)criterias.GenderId, StatusId = (byte)UserStatus.Pending, UserName = criterias.Email, }; try { var result = await _userManager.CreateAsync(user, criterias.Password); if (result.Succeeded) { user = await _userManager.FindByNameAsync(user.UserName); var confirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(user); await SendActiveEmailAsync(user, confirmationToken); } else { return(CommonResult.Failed(result.Errors.Select(x => new CommonError() { Code = x.Code, Message = x.Description }))); } return(CommonResult.Success()); } catch (Exception ex) { return(CommonResult.Failed(new CommonError() { Message = ex.Message })); } }
public CommonResult ValidateImageUrl(ImageValidationModel criterias) { _validationStrategyContext.SetStrategy(new ImageUrlValidationStrategy()); if (criterias == null || string.IsNullOrEmpty(criterias.Url)) { return(CommonResult.Failed(new CommonError())); } bool canUpdate = _validationStrategyContext.Validate(criterias.Url); if (!canUpdate) { _validationStrategyContext.SetStrategy(new Base64ImageValidationStrategy()); canUpdate = _validationStrategyContext.Validate(criterias.Url); } if (canUpdate) { return(CommonResult.Success()); } return(CommonResult.Failed(new CommonError())); }