| | |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Configuration; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Net; |
| | |
| | | //定义全局信息返回变量 |
| | | ToMessage mes = new ToMessage(); |
| | | RedisHelper redis = new RedisHelper(); |
| | | //获取企业配置Enterprise |
| | | private static readonly string Enterprise = ConfigurationManager.AppSettings["Enterprise"]; |
| | | |
| | | |
| | | |
| | | #region[PC用户登录] |
| | | /// <summary> |
| | |
| | | ms.username = dt.Rows[0]["USERNAME"].ToString(); |
| | | ms.password = dt.Rows[0]["PASSWORD"].ToString(); |
| | | ms.usertype = usertype; |
| | | ms.rediskey = "LoginUserID" + ms.usertype + ms.userid; |
| | | ms.rediskey = Enterprise+"LoginUserID" + ms.usertype + ms.userid; |
| | | mss.Add(ms); |
| | | HttpContext.Current.Session.Clear(); //从会话状态集合中删除所有的键值 |
| | | //HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //User loginUser = JsonConvert.DeserializeObject<User>(HttpContext.Current.Session["User"].ToString()); |
| | | User loginUser = JsonConvert.DeserializeObject<User>(JsonConvert.SerializeObject(ms)); |
| | | //如果redis登录用户中不存在当前用户 |
| | | if (redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0) == null) |
| | | if (redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 0) == null) |
| | | { |
| | | //redis.Remove("LoginUserID" + ms.userid, 0); |
| | | //写入redis(注意:redis类里面的失效时间必须在key创建完成之后才生效) |
| | | redis.Set<User>("LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0); |
| | | redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0); |
| | | //登录信息写入session |
| | | HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //写入登录操作记录 |
| | |
| | | else //如果存在 |
| | | { |
| | | //获取redis中当前用户信息 |
| | | User r_loginUser = redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0); |
| | | User r_loginUser = redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 0); |
| | | //如果session中的用户usercode和redis中的用户usercode匹配 |
| | | if ((r_loginUser.usercode + r_loginUser.usertype).Equals(loginUser.usercode + loginUser.usertype)) |
| | | { |
| | |
| | | else |
| | | { |
| | | //重置过期时间(注意:redis类里面的失效时间必须在key创建完成之后才生效) |
| | | redis.Set<User>("LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0); |
| | | redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0); |
| | | //登录信息写入session |
| | | HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //写入登录操作记录 |
| | |
| | | sql = @"update [dbo].[TUser] set rid=@rid where usercode=@usercode"; |
| | | list.Add(new { str = sql, parm = new { rid = rid, usercode = username } }); |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | redis.Remove("LoginUserID" + usertype + userid, 1); //删除redis |
| | | redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 1); //删除redis |
| | | } |
| | | else |
| | | { |
| | | redis.Remove("LoginUserID" + usertype + userid, 0); //删除redis |
| | | redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 0); //删除redis |
| | | } |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[密码重置] |
| | | /// <summary> |
| | | /// 密码重置 |
| | | /// </summary> |
| | | /// <param name="usercode">用户编号</param> |
| | | /// <param name="username">用户名称</param> |
| | | /// <returns></returns> |
| | | [ChannelActionFilter, Route(template: "ResettUserPassword")] |
| | | [HttpPost] |
| | | public HttpResponseMessage ResettUserPassword(string usercode, string username) |
| | | { |
| | | mes = LoginBLL.ResettUserPassword(usercode, username); |
| | | return mes.ResponseMess(mes); |
| | | } |
| | | #endregion |
| | | |
| | | #region[PC登出] |
| | | /// <summary> |
| | | /// PC登出 |
| | |
| | | ms.username = dt.Rows[0]["USERNAME"].ToString(); |
| | | ms.password = dt.Rows[0]["PASSWORD"].ToString(); |
| | | ms.usertype = usertype; |
| | | ms.rediskey = "LoginUserID" + ms.usertype + ms.userid; |
| | | ms.rediskey = Enterprise+"LoginUserID" + ms.usertype + ms.userid; |
| | | mss.Add(ms); |
| | | HttpContext.Current.Session.Clear(); //从会话状态集合中删除所有的键值 |
| | | User loginUser = JsonConvert.DeserializeObject<User>(JsonConvert.SerializeObject(ms)); |
| | | //如果redis登录用户中不存在当前用户 |
| | | if (redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 1) == null) |
| | | if (redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 1) == null) |
| | | { |
| | | //写入redis(注意:redis类里面的失效时间必须在key创建完成之后才生效) |
| | | redis.Set<User>("LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 1); |
| | | redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 1); |
| | | //登录信息写入session |
| | | HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //更新rid |
| | |
| | | else //如果存在 |
| | | { |
| | | //获取redis中当前用户信息 |
| | | User r_loginUser = redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 1); |
| | | User r_loginUser = redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 1); |
| | | //如果session中的用户usercode和redis中的用户usercode匹配 |
| | | if ((r_loginUser.usercode + r_loginUser.usertype).Equals(loginUser.usercode + loginUser.usertype)) |
| | | { |
| | |
| | | else |
| | | { |
| | | //重置过期时间(注意:redis类里面的失效时间必须在key创建完成之后才生效) |
| | | redis.Set<User>("LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 1); |
| | | redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 1); |
| | | //登录信息写入session |
| | | HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //更新rid |
| | |
| | | public HttpResponseMessage LoginAppAnDonMessage(string rid, string usercode, string username, string usertype) |
| | | { |
| | | mes = LoginBLL.LoginAppAnDonMessage(rid, usercode, username, usertype); |
| | | return mes.ResponseMess(mes); |
| | | return TJson.toJson(mes); |
| | | //return mes.ResponseMess(mes); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | } |
| | | } |