/// <summary> /// 邮箱登录获取token /// </summary> /// <param name="emailLoginDTO"></param> /// <returns></returns> public TResultModel <TokenDTO> Login(EmailLoginDTO emailLoginDTO) { var md5Password = Md5Helper.GenerateMD5(emailLoginDTO.Password); var member = _memberRepository.GetByEmail(emailLoginDTO.Email); if (member == null || md5Password != member.Password) { return(new TResultModel <TokenDTO>(-1, "用户名或密码错误")); } else { var jwtStr = JwtHelper.BuildJwtToken(new Claim[3] { new Claim(ClaimTypes.Role, "Admin"), new Claim("Name", member.NickName), new Claim("Id", member.Id.ToString()) }, _permissionRequirement); return(new TResultModel <TokenDTO>(1, "success") { TModel = new TokenDTO() { Token = jwtStr } }); } }
public IActionResult Get(string email, string password) { var result = new TResultModel <TokenVModel>(1); return(this.Wrapper(ref result, () => { var md5Password = Md5Helper.GenerateMD5(password); var user = _userRepository.GetByEmail(email); if (user == null || md5Password != user.Pwd) { result.ResultNo = -1; result.Message = "用户名或密码错误"; return; } else { var jwtstr = JwtHelper.BuildJwtToken(new Claim[3] { // new Claim(ClaimTypes.Role,"admin"), new Claim("userName", user.Name), new Claim("userId", user.Id.ToString()), new Claim("email", user.Email), }, _permissionRequirement); result.TModel = new TokenVModel() { token = jwtstr }; } }, false)); }
/// <summary> /// 邮箱注册 /// </summary> /// <param name="registerDTO"></param> /// <returns></returns> public ResultModel Register(RegisterDTO registerDTO) { var key = $"VerificationCodel:Email:{registerDTO.Email}"; var localVerificationCode = new CsRedisBase().Get(key); if (string.IsNullOrWhiteSpace(localVerificationCode)) { return(new ResultModel(-1, "未发送验证码或验证码已过期")); } if (localVerificationCode != registerDTO.VerificationCode) { return(new ResultModel(-1, "验证码错误")); } registerDTO.Password = Md5Helper.GenerateMD5(registerDTO.Password); var registerCommand = _mapper.Map <RegisterCommand>(registerDTO); return(_memberService.Register(registerCommand)); }
public IActionResult Post([FromBody] RegisterVModel model) { var result = new ResultModel(); return(this.Wrapper(ref result, () => { var user = _userRepository.GetByEmail(model.email); if (user != null) { result.ResultNo = -1; result.Message = "该邮箱已经注册过账号"; return; } var key = $"VerificationCodel:Email:{model.email}"; if ("3197" != model.verificationCode) { result.ResultNo = -1; result.Message = "验证码错误"; return; } var pwd = Md5Helper.GenerateMD5(model.password); var newUser = new HeyTom.Manage.Model.User() { Email = model.email, Icon = "", Name = model.nickName, Pwd = pwd, Remark = "", Status = 1, CreateDate = DateTime.Now }; result = _userRepository.Add(newUser); _userRoleRepository.Add(new HeyTom.Manage.Model.UserRole() { RoleId = 4, UserId = newUser.Id }); }, true)); }