public string login(string username, string password, string code, string uuid, RequestBasicInfo info) { string verifyKey = YouGeSystemConst.CAPTCHA_CODE_KEY + uuid; string captcha = YouGeRedisHelper.Get(verifyKey); YouGeRedisHelper.Del(verifyKey); if (captcha == null) { //启动线程 记录日志 var ta = new Task(() => sysLoginRepository.recordLogininfor(username, YouGeSystemConst.FAIL, "没有验证码", info) ); ta.Start(); throw new CaptchaExpireException(); } if (!string.Equals(code, captcha, StringComparison.OrdinalIgnoreCase)) { var tb = new Task(() => sysLoginRepository.recordLogininfor(username, YouGeSystemConst.FAIL, "验证码已失效", info) ); tb.Start(); throw new CaptchaException(); } try { LoginUser loginUser = this.loadUserByUsername(username, password); var tf = new Task(() => sysLoginRepository.recordLogininfor(username, YouGeSystemConst.SUCCESS, "登录成功", info) ); tf.Start(); // 生成token return(tokenService.createToken(loginUser, info)); } catch (Exception e) { if (e.Message.Contains("密码错误")) { var tc = new Task(() => sysLoginRepository.recordLogininfor(username, YouGeSystemConst.FAIL, "用户不存在/密码错误", info) ); tc.Start(); throw new UserPasswordNotMatchException(); } else { var td = new Task(() => sysLoginRepository.recordLogininfor(username, YouGeSystemConst.FAIL, e.Message, info) ); td.Start(); throw new CustomException(e.Message); } } }
public LoginUser getLoginUser(HttpRequest request) { // 获取请求携带的令牌 string token = getToken(request); if (!string.IsNullOrEmpty(token)) { List <Claim> claims = parseToken(token); // 解析对应的权限以及用户信息\ string uuid = claims.Where(U => U.Type == YouGeSystemConst.LOGIN_USER_KEY).FirstOrDefault().Value; // string uuid = (string)claims.get(); string userKey = getTokenKey(uuid); LoginUser user = YouGeRedisHelper.Get <LoginUser>(userKey); return(user); } return(null); }