public JsonResult Register([FromBody] t_user clientModel) { //参数过滤 if (string.IsNullOrEmpty(clientModel.userAccount)) { return(Json(Rsp.Fail("账号不能为空", -1))); } if (string.IsNullOrEmpty(clientModel.userPwd)) { return(Json(Rsp.Fail("密码不能为空", -2))); } var userModel = _userService.GetUserInfo(clientModel.userAccount); if (userModel != null) { return(Json(Rsp.Fail("账号已存在", -3))); } else { //密码加密 clientModel.userPwd = EncryptHelper.AESEncrypt(clientModel.userPwd, "DNLiCore"); int resultInt = _userService.AddUser(clientModel); return(Json(Rsp.Success(resultInt.ToString()))); } }
public void OnAuthorization(AuthorizationFilterContext context) { if (IsHaveAllow(context.Filters)) { return; } //需要登录权限的,先从header中拿 string Authorization = context.HttpContext.Request.Headers["Authorization"].ToString(); if (!string.IsNullOrEmpty(Authorization)) { //验证token是否正常 var cacheAuthor = _cache.Get(Authorization); if (cacheAuthor != null) { //刷新当前token时间 _cache.Set(Authorization, cacheAuthor, new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromHours(3) }); } else { //已经过期了 var jsonModel = Rsp.Fail("已过期", -999); context.Result = new JsonResult(jsonModel); } } else { // 返回未登录的信息 var jsonModel = Rsp.Fail("未登录", -999); context.Result = new JsonResult(jsonModel); } }