Exemplo n.º 1
0
        public async Task <ApiRequestResult> UpdateAsync([FromBody] UserParam param)
        {
            var user = await _iTUserRepository.GetAsync(c => c.Id == param.Id);

            user = param.EntityMap <TUser, UserParam>(user);
            await _iTUserRepository.UpdateAsync(user);

            var identityUser = await _userManager.FindByNameAsync(param.UserName);

            identityUser.UserName    = param.UserName;
            identityUser.Email       = param.Email;
            identityUser.PhoneNumber = param.PhoneNumber;

            var result = await _userManager.UpdateAsync(identityUser);

            if (result.Succeeded)
            {
                return(ApiRequestResult.Success("修改成功"));
            }
            return(ApiRequestResult.Error(result.Errors.FirstOrDefault().Description));
        }
Exemplo n.º 2
0
        public async Task <ApiRequestResult> UpdatePassword(UpdatePasswordModel model)
        {
            var user = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                return(ApiRequestResult.Error("未登录"));
            }
            var checkResult = await _userManager.CheckPasswordAsync(user, model.OldPassword);

            if (!checkResult)
            {
                return(ApiRequestResult.Error("原密码输入错误"));
            }

            var tUser = await _userRepository.GetAsync(c => c.Id == Guid.Parse(user.Id));

            if (tUser == null)
            {
                return(ApiRequestResult.Error("获取用户信息失败"));
            }

            //修改密码
            var passwordHash = _userManager.PasswordHasher.HashPassword(user, model.NewPassword);

            user.PasswordHash = passwordHash;

            tUser.Password = passwordHash;
            await _userRepository.UpdateAsync(tUser);

            var result = await _userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                return(ApiRequestResult.Success("修改成功"));
            }
            var err = result.Errors.FirstOrDefault();

            return(ApiRequestResult.Error(err.Code + ":" + err.Description));
        }