| | |
| | | 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[用户登录] |
| | | |
| | | |
| | | #region[PC用户登录] |
| | | /// <summary> |
| | | /// 用户登录 |
| | | /// PC用户登录 |
| | | /// </summary> |
| | | /// <param name="username">用户编码</param> |
| | | /// <param name="password">密码</param> |
| | |
| | | /// <returns></returns> |
| | | [Route(template: "LoginSave")] |
| | | [HttpGet] |
| | | public HttpResponseMessage LoginSave(string username, string password,string usertype) |
| | | public HttpResponseMessage LoginSave(string username, string password, string usertype) |
| | | { |
| | | try |
| | | { |
| | |
| | | { |
| | | List<User> mss = new List<User>(); |
| | | User ms = new User(); |
| | | ms.guid = username + password + Guid.NewGuid().ToString(); |
| | | ms.guid = usertype+username + password + Guid.NewGuid().ToString(); |
| | | ms.userid = Convert.ToInt32(dt.Rows[0]["ID"].ToString()); |
| | | ms.usercode = dt.Rows[0]["USERCODE"].ToString(); |
| | | ms.username = dt.Rows[0]["USERNAME"].ToString(); |
| | | ms.password = dt.Rows[0]["PASSWORD"].ToString(); |
| | | ms.usertype = usertype; |
| | | 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.Equals(loginUser.usercode)) |
| | | if ((r_loginUser.usercode + r_loginUser.usertype).Equals(loginUser.usercode + loginUser.usertype)) |
| | | { |
| | | mes.data = ms; |
| | | mes.code = "302"; |
| | |
| | | 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); |
| | | //写入登录操作记录 |
| | | mes = LoginBLL.LoginBas(ms.usercode, ms.usertype); |
| | | mes.data = ms; |
| | | mes.code = "200"; |
| | | mes.Message = "登录成功!"; |
| | | } |
| | |
| | | /// <param name="usercode">用户编码</param> |
| | | /// <param name="username">用户名</param> |
| | | /// <param name="usertype">操作端PC/APP</param> |
| | | /// <param name="rid">rid极光推送获取设备id</param> |
| | | /// <returns></returns> |
| | | [Route(template: "ForcedOffline")] |
| | | [HttpPost] |
| | | public HttpResponseMessage ForcedOffline(int userid, string usercode, string username, string usertype) |
| | | public HttpResponseMessage ForcedOffline(int userid, string usercode, string username, string usertype,string rid) |
| | | { |
| | | string sql=""; |
| | | List<object> list = new List<object>(); |
| | | try |
| | | { |
| | | redis.Remove("LoginUserID" + usertype + userid, 0); //删除redis |
| | | if (usertype == "APP") |
| | | { |
| | | //更新rid |
| | | 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(Enterprise+"LoginUserID" + usertype + userid, 1); //删除redis |
| | | } |
| | | else |
| | | { |
| | | redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 0); //删除redis |
| | | } |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.Message = "强制下线成功!"; |
| | |
| | | /// 查询登录菜单 |
| | | /// </summary> |
| | | /// <param name="usertype">操作端类型(PC APP)</param> |
| | | /// <param name="usercode">登录用户编码</param> |
| | | /// <returns></returns> |
| | | [Route(template: "LoginMenu")] |
| | | [HttpGet] |
| | | public HttpResponseMessage LoginMenu(string usertype) |
| | | public HttpResponseMessage LoginMenu(string usertype, string usercode) |
| | | { |
| | | try |
| | | { |
| | | var usercode = HttpContext.Current.Request.Cookies["navTabId"].Value.ToString(); |
| | | //var usercode = HttpContext.Current.Request.Cookies["navTabId"].Value.ToString(); |
| | | mes = LoginBLL.LoginMenu(usercode, usertype); |
| | | } |
| | | catch (Exception e) |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[登出] |
| | | #region[PC登出] |
| | | /// <summary> |
| | | /// 登出 |
| | | /// PC登出 |
| | | /// </summary> |
| | | /// <param name="userid">用户id</param> |
| | | /// <param name="usercode">用户编码</param> |
| | |
| | | [ChannelActionFilter] |
| | | public HttpResponseMessage LoginOut(int userid, string usercode, string username, string usertype) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | mes = LoginBLL.LoginOut(userid, usercode, username, usertype); |
| | | return mes.ResponseMess(mes); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region[APP用户登录] |
| | | /// <summary> |
| | | /// APP用户登录 |
| | | /// </summary> |
| | | /// <param name="username">用户编码</param> |
| | | /// <param name="password">密码</param> |
| | | /// <param name="usertype">操作端类型(PC APP)</param> |
| | | /// <param name="rid">极光推送获取设备的id(唯一)</param> |
| | | /// <returns></returns> |
| | | [Route(template: "LoginAppSave")] |
| | | [HttpGet] |
| | | public HttpResponseMessage LoginAppSave(string username, string password, string usertype, string rid) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | try |
| | | { |
| | | DataTable dt = LoginBLL.LoginSearch(username, password); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | List<User> mss = new List<User>(); |
| | | User ms = new User(); |
| | | ms.guid = usertype+username + password + Guid.NewGuid().ToString(); |
| | | ms.userid = Convert.ToInt32(dt.Rows[0]["ID"].ToString()); |
| | | ms.usercode = dt.Rows[0]["USERCODE"].ToString(); |
| | | ms.username = dt.Rows[0]["USERNAME"].ToString(); |
| | | ms.password = dt.Rows[0]["PASSWORD"].ToString(); |
| | | ms.usertype = usertype; |
| | | 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>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 1) == null) |
| | | { |
| | | //写入redis(注意:redis类里面的失效时间必须在key创建完成之后才生效) |
| | | redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 1); |
| | | //登录信息写入session |
| | | HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //更新rid |
| | | 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); |
| | | //写入登录操作记录 |
| | | mes = LoginBLL.LoginBas(ms.usercode, ms.usertype); |
| | | mes.code = "200"; |
| | | mes.Message = "登录成功!"; |
| | | mes.data = ms; |
| | | } |
| | | else //如果存在 |
| | | { |
| | | //获取redis中当前用户信息 |
| | | 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)) |
| | | { |
| | | mes.data = ms; |
| | | mes.code = "302"; |
| | | mes.Message = "当前账号已登录,是否强制下线!"; |
| | | } |
| | | else |
| | | { |
| | | //重置过期时间(注意:redis类里面的失效时间必须在key创建完成之后才生效) |
| | | redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 1); |
| | | //登录信息写入session |
| | | HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms); |
| | | //更新rid |
| | | 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); |
| | | //写入登录操作记录 |
| | | mes = LoginBLL.LoginBas(ms.usercode, ms.usertype); |
| | | mes.data = ms; |
| | | mes.code = "200"; |
| | | mes.Message = "登录成功!"; |
| | | } |
| | | } |
| | | |
| | | |
| | | ////写入登录操作记录 |
| | | //mes = LoginBLL.LoginBas(username, usertype); |
| | | ////更新rid |
| | | //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); |
| | | |
| | | //List<User> mss = new List<User>(); |
| | | //User ms = new User(); |
| | | ////ms.guid = username + password + Guid.NewGuid().ToString(); |
| | | //ms.guid = rid.ToString(); |
| | | //ms.userid = Convert.ToInt32(dt.Rows[0]["ID"].ToString()); |
| | | //ms.usercode = dt.Rows[0]["USERCODE"].ToString(); |
| | | //ms.username = dt.Rows[0]["USERNAME"].ToString(); |
| | | //ms.password = dt.Rows[0]["PASSWORD"].ToString(); |
| | | //ms.usertype = usertype; |
| | | //mss.Add(ms); |
| | | |
| | | //mes.code = "200"; |
| | | //mes.Message = "登录成功!"; |
| | | //mes.data = ms; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = "账号或密码不正确!"; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = e.Message; |
| | | } |
| | | |
| | | return mes.ResponseMess(mes); |
| | | } |
| | | #endregion |
| | | |
| | | #region[APP登出] |
| | | /// <summary> |
| | | /// APP登出 |
| | | /// </summary> |
| | | /// <param name="userid">用户id</param> |
| | | /// <param name="usercode">用户编码</param> |
| | | /// <param name="username">用户名</param> |
| | | /// <param name="usertype">操作端PC/APP</param> |
| | | /// <returns></returns> |
| | | [Route(template: "LoginAppOut")] |
| | | [HttpPost] |
| | | public HttpResponseMessage LoginAppOut(int userid, string usercode, string username, string usertype) |
| | | { |
| | | mes = LoginBLL.LoginAppOut(userid, usercode, username, usertype); |
| | | return mes.ResponseMess(mes); |
| | | } |
| | | #endregion |
| | | |
| | | #region[App登录查询安灯呼叫信息] |
| | | /// <summary> |
| | | /// App登录查询安灯呼叫信息 |
| | | /// </summary> |
| | | /// <param name="rid">手机设备id(极光生成)</param> |
| | | /// <param name="usercode">用户编码</param> |
| | | /// <param name="username">用户名称</param> |
| | | /// <param name="usertype">操作端PC/APP</param> |
| | | /// <returns></returns> |
| | | [Route(template: "LoginAppAnDonMessage")] |
| | | [HttpPost] |
| | | public HttpResponseMessage LoginAppAnDonMessage(string rid, string usercode, string username, string usertype) |
| | | { |
| | | mes = LoginBLL.LoginAppAnDonMessage(rid, usercode, username, usertype); |
| | | return TJson.toJson(mes); |
| | | //return mes.ResponseMess(mes); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | } |
| | | } |