public async Task <IActionResult> PutAppUserByCurrentUser([FromBody] EditCurrentUser dto) { int userid = base.GetCurrentUserId(); var appUser = await _appUseRepository.GetAsync(userid); if (dto.Pwd.IsNotNullOrEmpty()) { if (!appUser.Pwd.IsNullOrEmpty()) { if (Md5Common.Get32Md5One(dto.OldPwd) != appUser.Pwd) { return(BadRequest("旧密码不正确!")); } } dto.Pwd = Md5Common.Get32Md5One(dto.Pwd); } else { dto.Pwd = appUser.Pwd; } appUser.NickName = dto.NickName; appUser.Sex = dto.Sex; _unitOfWork.SaveChanges(); return(Ok()); }
public async Task <IActionResult> ResetPwd(AppUserInputDto resetDto) { var appUser = await _appUseRepository.GetAsync(resetDto.Id); appUser.Pwd = Md5Common.Get32Md5One(resetDto.Pwd); _unitOfWork.SaveChanges(); return(Ok()); }
public async Task <IActionResult> PutAppUser([FromBody] AppUserInputDto dto) { bool isExist = _appUseRepository.GetAll().Any(r => r.LoginName == dto.LoginName && r.Id != dto.Id); if (isExist) { return(new BadRequestObjectResult("用户名已存在!")); } var appUser = await _appUseRepository.GetAsync(dto.Id); dto.Pwd = dto.Pwd.IsNullOrEmpty() ? appUser.Pwd : Md5Common.Get32Md5One(appUser.Pwd); dto.MapTo(appUser); _unitOfWork.SaveChanges(); return(Ok()); }
public async Task <IActionResult> PostAppUser([FromBody] AppUserInputDto dto) { bool isExist = _appUseRepository.GetAll().Any(r => r.LoginName == dto.LoginName); if (isExist) { return(new BadRequestObjectResult("用户名已存在!")); } var appUser = Mapper.Map <AppUserInputDto, AppUser>(dto); if (appUser.Pwd.IsNullOrEmpty()) { appUser.Pwd = "123456"; } appUser.Pwd = Md5Common.Get32Md5One(appUser.Pwd); await _appUseRepository.InsertAsync(appUser); _unitOfWork.SaveChanges(); return(Ok()); }
public void Get32Md5One() { string result = Md5Common.Get32Md5One("123qwe"); }