public ResponseResult SaveUser([FromBody] JObject data) { //定义 ResponseResult result = new ResponseResult(); string msg = ""; if (data["username"] != null && data["password"] != null) { SYS_USER_INFO model = new SYS_USER_INFO(); var dtNow = DateTime.Now; string username = data["username"].ToString(); string password = data["password"].ToString(); //获取操作用户 GetByToken(data["Token"].ToString()); model.UserName = username; model.PassWord = Common.Helper.SecureHelper.AESEncrypt(password); model.QQ = data["qq"] == null ? null : data["qq"].ToString(); model.Phone = data["phone"] == null ? null : data["phone"].ToString(); model.RealName = data["realname"] == null ? null : data["realname"].ToString(); model.State = 0; model.CreateTime = dtNow; model.CreateUser = LoginedUserName; //保存 if (SYS_USER_INFO_BLL.getInstance().AddUser(model, ref msg)) { result.return_code = RETURN_CODE.SUCCESS.ToString(); result.return_msg = "新增成功"; } else { result.return_code = RETURN_CODE.FAIL.ToString(); result.return_msg = msg; } } else { msg = "用户名或密码不能为空"; } return(result); }
/// <summary> /// 登录 /// </summary> /// <returns></returns> public ResponseResult Login([FromBody] JObject data) { //返回实体 ResponseResult result = new ResponseResult(); try { string msg = ""; if (data["username"] != null && data["password"] != null) //&& data["validatecode"] != null && data["pictureId"]!=null) { var dtNow = DateTime.Now; string username = data["username"].ToString(); string password = data["password"].ToString(); //string validatecode = data["validatecode"].ToString(); //string pictureId = data["pictureId"].ToString(); //if (validatecode != CacheHelper.GetCache(pictureId).ToString()) //{ // result.return_code = "FAIL"; // result.return_msg = "验证码错误"; // return result; //} //登录 var model = SYS_USER_INFO_BLL.getInstance().GetLoginModel(username, password, ref msg); //账号 密码验证通过 if (model != null) { //Common.Enum.LoginStatus.Success; //生成票据 string Token = Common.Helper.DESEncrypt.Encrypt(System.Guid.NewGuid().ToString()); int userid = model.Id; //直接清除 SYS_TICKET_AUTH_BLL.getInstance().DeleteTicketAuthByUserId(userid); #region 将身份信息保存票据表中,验证当前请求是否是有效请求 SYS_TICKET_AUTH ticket = new SYS_TICKET_AUTH(); ticket.UserId = model.Id; ticket.UserName = model.UserName; ticket.Token = Token; ticket.ExprieTime = dtNow.AddMinutes(30); //30分钟过期 ticket.CreateTime = dtNow; //新增ticket SYS_TICKET_AUTH_BLL.getInstance().SavaTicketAuth(ticket); #endregion JObject logininfo = new JObject(); logininfo.Add("userid", model.Id); logininfo.Add("loginname", model.UserName); logininfo.Add("token", Token); result.return_code = Common.Enum.RETURN_CODE.SUCCESS.ToString(); result.return_info = logininfo; } //账号密码验证错误 else { result.return_code = Common.Enum.RETURN_CODE.FAIL.ToString(); } } else { result.return_code = Common.Enum.RETURN_CODE.ERROR.ToString(); result.return_msg = "参数不完整"; result.return_info = null; } result.return_msg = msg; //var resultObj = JsonConvert.SerializeObject(obj, Formatting.Indented); //HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(resultObj, Encoding.GetEncoding("UTF-8"), "application/json") }; //return result; } catch (Exception ex) { Logger.Error(string.Format("登录异常,异常信息:{0}", ex.ToString())); } return(result); }
public void init() { SYS_USER_INFO_BLL.getInstance().InitAdmin(); }