示例#1
0
 public async Task <ServiceResponse <bool> > ChangePassword(ChangePassordDTO model)
 {
     return(await HandleApiOperationAsync(async() => {
         var result = await _userSvc.ChangePassword(User.FindFirst(JwtClaimTypes.Name)?.Value, model);
         return new ServiceResponse <bool>(result);
     }));
 }
示例#2
0
        public async Task <bool> ChangePassword(string usernameOrEmail, ChangePassordDTO model)
        {
            if (string.IsNullOrEmpty(usernameOrEmail))
            {
                throw await _svcHelper.GetExceptionAsync(ErrorConstants.USER_ACCOUNT_NOT_EXIST);
            }

            var user = await FindByNameAsync(usernameOrEmail) ?? await FindByEmailAsync(usernameOrEmail);

            await ValidateUser(user);

            var result = await _userManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword);

            if (!result.Succeeded)
            {
                throw await _svcHelper.GetExceptionAsync(result.Errors?.FirstOrDefault().Description);
            }

            return(true);
        }