| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data;
- using Curtain.DataAccess;
- using DK.XuWei.WebMes;
- /// <summary>
- /// Login 的摘要说明
- /// </summary>
- namespace DK.XuWei.WebMes
- {
- public static partial class dkmes
- {
- public static JsonResult LoginByAD1(string userCodeAD)
- {
- JsonResult result = new JsonResult();
- using (IDataAccess conn = DataAccess.Create())
- {
- string userId = "";
- DateTime today = DateTime.Now;
- string guid = Guid.NewGuid().ToString();
- //开启事务
- conn.BeginTransaction();
- #region 读取用户信息
- DataTable userTable = conn.ExecuteDatatable(@"
- SELECT
- u.ACCOUNTID,
- u.ACCOUNTCODE,
- u.USERID,
- u.USERCODE,
- u.USERNAME,
- u.PASSWORD,
- u.ORGANIZATIONID,
- u.ISWORKER,
- u.LIMITSTARTTIME,
- u.LIMITENDTIME
- FROM
- TP_MST_USER u
- WHERE
- u.VALUEFLAG = '1'
- AND u.ad_user_code = @ad_user_code@
- ",
- new CDAParameter("ad_user_code", userCodeAD)
- );
- #endregion
- //验证用户密码
- if (userTable.Rows.Count == 1)
- {
- userId = userTable.Rows[0]["USERID"].ToString();
- result.success = true;
- result.message = "用户登录成功!";
- //if (userTable.Rows[0]["PASSWORD"].ToString() == userPassword)
- //{
- //}
- //else
- //{
- // //更新密码错误次数
- // conn.ExecuteNonQuery(@"
- // UPDATE
- // TP_MST_USERLOGIN
- // SET
- // MISSTIMES = MISSTIMES + 1
- // WHERE
- // USERID = @USERID@
- // ",
- // new CDAParameter("USERID", userId)
- // );
- // //读取错误次数
- // string missTimes = conn.ExecuteScalar(@"
- // SELECT
- // MISSTIMES
- // FROM
- // TP_MST_USERLOGIN
- // WHERE
- // USERID = @USERID@
- // ",
- // new CDAParameter("USERID", userId)
- // ).ToString();
- // result.success = false;
- // result.message = "用户名或密码错误!";
- // result.message += "登录失败次数:" + missTimes + ",";
- // result.message += "连续登录失败 " + LoginSetting.MissTimes.ToString() + " 次,";
- // result.message += "您的账号将被锁定 " + LoginSetting.LockHour.ToString() + " 小时!";
- // //错误次数上限锁定操作
- // //更新锁定标识
- // int isLock = conn.ExecuteNonQuery(@"
- // UPDATE
- // TP_MST_USERLOGIN
- // SET
- // ISLOCKED = '1',
- // LOCKTIME = @LOCKTIME@
- // WHERE
- // USERID = @USERID@
- // AND MISSTIMES >= @MISSTIMES@
- // ",
- // new CDAParameter("LOCKTIME", today),
- // new CDAParameter("USERID", userId),
- // new CDAParameter("MISSTIMES", LoginSetting.MissTimes)
- // );
- // //写入锁定时间
- // if(isLock>0)
- // {
- // conn.ExecuteNonQuery(@"
- // UPDATE
- // TP_MST_USER
- // SET
- // LIMITSTARTTIME = @LIMITSTARTTIME@,
- // LIMITENDTIME = @LIMITENDTIME@
- // WHERE
- // USERID = @USERID@
- // ",
- // new CDAParameter("LIMITSTARTTIME", today),
- // new CDAParameter("LIMITENDTIME", today.AddHours(LoginSetting.LockHour)),
- // new CDAParameter("USERID", userId)
- // );
- // result.success = false;
- // result.message = "用户账户已被锁定!";
- // result.message += " 锁定时间:" + today.ToString() + " 至 " + today.AddHours(LoginSetting.LockHour);
- // }
- //}
- }
- else
- {
- result.success = false;
- result.message = "用户名错误!";
- }
- //验证是否被锁定
- //if (result.success == true)
- //{
- // DataTable lockTable = conn.ExecuteDatatable(@"
- // SELECT
- // u.LIMITSTARTTIME,
- // u.LIMITENDTIME
- // FROM
- // TP_MST_USER u
- // LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID
- // WHERE
- // l.USERID = @USERID@
- // AND l.ISLOCKED = '1'
- // AND @LIMITSTARTTIME@ > u.LIMITSTARTTIME
- // AND @LIMITENDTIME@ < u.LIMITENDTIME
- // ",
- // new CDAParameter("USERID", userId),
- // new CDAParameter("LIMITSTARTTIME", today),
- // new CDAParameter("LIMITENDTIME", today)
- // );
- // if (lockTable.Rows.Count == 0)
- // {
- // result.success = true;
- // result.message = "用户登录成功!";
- // }
- // else
- // {
- // result.success = false;
- // result.message = "用户账户已被锁定!";
- // result.message += " 锁定时间:" + lockTable.Rows[0]["LIMITSTARTTIME"].ToString() + " 至 " + lockTable.Rows[0]["LIMITENDTIME"].ToString();
- // }
- //}
- //更新登录信息并记录Session
- if (result.success == true)
- {
- //重置密码错误次数 更新最后登录时间 更新SessionKey 更新登录状态
- conn.ExecuteNonQuery(@"
- UPDATE
- TP_MST_USERLOGIN
- SET
- ISLOCKED = '0',
- MISSTIMES = 0,
- LASTLOGINTIME = @LASTLOGINTIME@,
- WEBISLOGIN = '1',
- WEBSESSIONKEY = @WEBSESSIONKEY@
- WHERE
- USERID = @USERID@
- ",
- new CDAParameter("LASTLOGINTIME", today),
- new CDAParameter("WEBSESSIONKEY", guid),
- new CDAParameter("USERID", userId)
- );
- //记录Session
- HttpContext.Current.Session["accountId"] = userTable.Rows[0]["ACCOUNTID"].ToString();
- HttpContext.Current.Session["accountCode"] = userTable.Rows[0]["ACCOUNTCODE"].ToString();
- HttpContext.Current.Session["userId"] = userTable.Rows[0]["USERID"].ToString();
- HttpContext.Current.Session["userCode"] = userTable.Rows[0]["USERCODE"].ToString();
- HttpContext.Current.Session["userPassword"] = userTable.Rows[0]["PASSWORD"].ToString();
- HttpContext.Current.Session["webSessionKey"] = guid;
- //如果是成检 必须更新 sessionKey 会顶掉PC或PDA登录的相同用户
- //if (productCheck)
- //{
- // conn.ExecuteNonQuery(@"
- // UPDATE
- // TP_MST_USERLOGIN
- // SET
- // SESSIONKEY = @SESSIONKEY@
- // WHERE
- // USERID = @USERID@
- // ",
- // new CDAParameter("SESSIONKEY", guid),
- // new CDAParameter("USERID", userId)
- // );
- // HttpContext.Current.Session["sessionKey"] = guid;
- //}
- }
- //提交数据
- conn.Commit();
- return result;
- }
- }
- }
- }
|