示例#1
0
        public async Task <TData <long> > ChangePassword(ChangePasswordParam param)
        {
            TData <long> obj = new TData <long>();

            if (param.Id > 0)
            {
                if (string.IsNullOrEmpty(param.Password) || string.IsNullOrEmpty(param.NewPassword))
                {
                    obj.Message = "新密码不能为空";
                    return(obj);
                }
                UserEntity dbUserEntity = await userService.GetEntity(param.Id.Value);

                if (dbUserEntity.Password != EncryptUserPassword(param.Password, dbUserEntity.Salt))
                {
                    obj.Message = "旧密码不正确";
                    return(obj);
                }
                dbUserEntity.Salt     = GetPasswordSalt();
                dbUserEntity.Password = EncryptUserPassword(param.NewPassword, dbUserEntity.Salt);
                await userService.ResetPassword(dbUserEntity);

                await RemoveCacheById(param.Id.Value);

                obj.Data = dbUserEntity.Id.Value;
                obj.Tag  = 1;
            }
            return(obj);
        }
示例#2
0
        public async Task <Result> ChangePassword(ChangePasswordParam model)
        {
            var currentUser = await _workContext.GetCurrentUserAsync();

            if (currentUser == null)
            {
                throw new Exception("用户信息异常,请重新登录");
            }
            var user = await _userManager.FindByIdAsync(currentUser.Id.ToString());

            if (user == null)
            {
                throw new Exception("用户信息异常,请重新登录");
            }
            var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                // await _signInManager.SignInAsync(user, isPersistent: false);
                await _signInManager.SignOutAsync();

                _tokenService.RemoveUserToken(user.Id);
                return(Result.Ok());
            }
            return(Result.Fail(result.Errors?.FirstOrDefault()?.Description));
        }
        /// <summary>
        /// Sets the new password for a customer.
        /// </summary>
        /// <param name="changePasswordParam">Service call params <see cref="ChangePasswordParam"/></param>
        /// <returns>
        ///  The updated Customer and a status representing a possible cause of errors
        /// </returns>
        public virtual async Task <ChangePasswordViewModel> ChangePasswordAsync(ChangePasswordParam changePasswordParam)
        {
            if (changePasswordParam == null)
            {
                throw new ArgumentNullException("changePasswordParam");
            }
            if (changePasswordParam.CultureInfo == null)
            {
                throw new ArgumentException("changePasswordParam.CultureInfo");
            }
            if (changePasswordParam.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("changePasswordParam.CustomerId");
            }
            if (string.IsNullOrWhiteSpace(changePasswordParam.Scope))
            {
                throw new ArgumentException("changePasswordParam.Scope");
            }
            if (string.IsNullOrWhiteSpace(changePasswordParam.NewPassword))
            {
                throw new ArgumentException("changePasswordParam.NewPassword");
            }
            if (string.IsNullOrWhiteSpace(changePasswordParam.OldPassword))
            {
                throw new ArgumentException("changePasswordParam.OldPassword");
            }

            var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
            {
                CustomerId  = changePasswordParam.CustomerId,
                CultureInfo = changePasswordParam.CultureInfo,
                Scope       = changePasswordParam.Scope
            }).ConfigureAwait(false);

            if (customer == null)
            {
                return(GetChangePasswordViewModel(new GetChangePasswordViewModelParam
                {
                    Status = MyAccountStatus.Failed,
                    ReturnUrl = changePasswordParam.ReturnUrl,
                    CultureInfo = changePasswordParam.CultureInfo
                }));
            }

            await CustomerRepository.ChangePasswordAsync(
                customer.Username,
                changePasswordParam.Scope,
                changePasswordParam.OldPassword,
                changePasswordParam.NewPassword
                );

            return(GetChangePasswordViewModel(new GetChangePasswordViewModelParam
            {
                Status = MyAccountStatus.Success,
                Customer = customer,
                ReturnUrl = changePasswordParam.ReturnUrl,
                CultureInfo = changePasswordParam.CultureInfo
            }));
        }
    public async Task <IdentityResult> ChangePasswordAsync(ChangePasswordParam model)
    {
        var user = await _manager.FindByNameAsync(model.UserName);

        return(await _manager.ChangePasswordAsync(
                   user,
                   model.CurrentPassword,
                   model.NewPassword
                   ));
    }
示例#5
0
        public static MQActionVoidResult ChangePassword(string sessionId, ChangePasswordParam param)
        {
            Session session = SessionPool.GetByClientId(sessionId, ClientTypeEnum.Client);

            if (session == null)
            {
                return(MQActionVoidResult.Error(CommonErrors.NotConnectingCenterServer));
            }

            string result = SysMemberService.Instance.ChangePassword(session.SysmemberId, param);

            if (result == "1")
            {
                return(MQActionVoidResult.Ok());
            }
            else
            {
                return(MQActionVoidResult.Error(result));
            }
        }
示例#6
0
        public async Task <IActionResult> ChangePasswordJson(ChangePasswordParam entity)
        {
            TData <long> obj = await userBLL.ChangePassword(entity);

            return(Json(obj));
        }
示例#7
0
 /// <summary>
 /// 更改系统会员密码
 /// </summary>
 public string ChangePassword(int id, ChangePasswordParam param)
 {
     return("1");
 }