public IActionResult Register([FromBody] UsersRegisterDto parm) { var captchaCode = RedisServer.Cache.Get($"Captcha:{parm.Uuid}"); RedisServer.Cache.Del($"Captcha:{parm.Uuid}"); if (parm.Code.ToUpper() != captchaCode) { return(ToResponse(StatusCodeType.Error, "输入验证码无效")); } //判断用户名是否存在 if (_usersService.Any(m => m.UserName == parm.UserName)) { return(ToResponse(StatusCodeType.Error, $"添加 {parm.UserID} 失败,该用户名已存在,不能重复!")); } //判断手机号是否存在 if (_usersService.Any(m => m.Phone == parm.Phone)) { return(ToResponse(StatusCodeType.Error, $"添加 {parm.UserID} 失败,该手机号已存在,不能重复!")); } parm.UserID = Guid.NewGuid().ToString(); //从Dto映射到实体 var userInfo = parm.Adapt <Sys_Users>(); userInfo.Password = PasswordUtil.CreateDbPassword(userInfo.UserID, userInfo.Password.Trim()); return(ToResponse(_usersService.Add(userInfo))); }
public IActionResult Create([FromBody] UsersCreateDto parm) { //判断用户是否已经存在 if (_usersService.Any(m => m.UserID == parm.UserID)) { return(toResponse(StatusCodeType.Error, $"添加 {parm.UserID} 失败,该用户已存在,不能重复!")); } //从 Dto 映射到 实体 var userInfo = parm.Adapt <Sys_Users>().ToCreate(_tokenManager.GetSessionInfo()); userInfo.Password = PasswordUtil.CreateDbPassword(userInfo.UserID, userInfo.Password.Trim()); return(toResponse(_usersService.Add(userInfo))); }