public HttpResponseMessage Login(Sys_Users model) { string token = ""; ReturnData result = new ReturnData(); if (userBLL.Exists(model)) { //TODO: 2、获取用户权限,将token和权限键值对缓存 3、将菜单目录、权限返回前端 result.S = true; MyPlatform.Model.Sys_Users u = userBLL.GetModelByAccount(model.Account); Dictionary <string, object> dicPayload = new Dictionary <string, object>(); dicPayload.Add("Account", model.Account); dicPayload.Add("UserName", model.UserName); //生成Token token = Common.JWTTokenHelper.GenerateToken(dicPayload, Common.JWTTokenHelper.SetTimeOut(0)); result.D = u; } else { result.SetErrorMsg("账号/密码错误!"); } HttpResponseMessage rep = MyPlatform.Utils.MyResponseMessage.SuccessJson(result); rep.Headers.Add("Access-Control-Expose-Headers", "Token"); rep.Headers.Add("Token", token); return(rep); }
//public HttpResponseMessage Register([FromBody]string json) public HttpResponseMessage Register(MyPlatform.Model.Sys_Users model) { // MyPlatform.Model.Sys_Users model = MyPlatform.Common.JSONUtil.ParseFromJson<MyPlatform.Model.Sys_Users>(json); ReturnData returnData = new ReturnData();//返回数据 #region 验证数据 if (string.IsNullOrEmpty(model.Account)) { returnData.SetErrorMsg("账号不能为空!"); } if (string.IsNullOrEmpty(model.Password)) { returnData.SetErrorMsg("密码不能为空!"); } if (string.IsNullOrEmpty(model.CreatedBy)) { model.CreatedBy = model.UserName; } if (!string.IsNullOrEmpty(returnData.M))//数据校验不通过,返回校验结果 { return(MyResponseMessage.SuccessJson <ReturnData>(returnData)); } #endregion model.CreatedDate = DateTime.Now; if (userBLL.Exists(model.Account))//判断账号是否已注册 { returnData.SetErrorMsg("账号已被注册"); } else//账号未被注册,进行新增操作 { if (userBLL.Add(model) > 0) { returnData.SetSuccessMsg("创建成功!"); } else { returnData.SetErrorMsg("创建失败!"); } } return(MyResponseMessage.SuccessJson <ReturnData>(returnData)); }
public int Add(MyPlatform.Model.Sys_Users model) { return(dal.Add(model)); }
public bool Exists(MyPlatform.Model.Sys_Users model) { return(dal.Exists(model)); }