protected void btLogin_Click(object sender, EventArgs e) { //เช็คจำนวนผู้ใช้----------------------------------------------------------- ClientLimit cl = new ClientLimit(); cl.ClearTimeOut(); if (cl.UserCount >= cl.UserLimit) { lblError.Text = "จำนวนผู้เข้าใช้งานเต็ม"; return; } //-------------------------------------------------------------------- if (UserProvider.ValidateUser(txtUserName.Text, Text.Encrypt(txtPassword.Text), false, false) == true) { if (string.IsNullOrEmpty(Request.QueryString["returnUrl"])) { btc.UpdateStatusActivity(); Response.Redirect(FormsAuthentication.DefaultUrl); } else { btc.UpdateStatusActivity(); Response.Redirect(Request.QueryString["returnUrl"]); } } else { lblError.Text = "User Name หรือ Password ผิดพลาด"; } }
public static bool ValidateUser(string username, string password, bool savemyinfo, bool autosignin) { Connection Conn = new Connection(); string strSql = @"Select E.EmpID, E.EmpName, E.SchoolID, E.DeptCode, E.UserRoleID, MD.MainDeptCode, MSD.MainSubDeptCode, UR.UserRoleName, UR.RoleLevel From Employee E Inner Join Department D On E.DeptCode = D.DeptCode Inner Join MainSubDepartment MSD On D.MainSubDeptCode = MSD.MainSubDeptCode Inner Join MainDepartment MD On MSD.MainDeptCode = MD.MainDeptCode Inner Join UserRole UR On E.UserRoleID = UR.UserRoleID Where E.UserName = '******' And E.Pwd = '{1}' And E.DelFlag = '0' And E.Hideflag = 0 "; DataView dv = Conn.Select(string.Format(strSql, username, password)); if (dv.Count == 0) { return(false); } //àªç¤¨Ó¹Ç¹¼Ùéãªé----------------------------------------------------------- ClientLimit cl = new ClientLimit(); if (!cl.AddClient(dv[0]["EmpID"].ToString(), true)) { return(false); } //--------------------------------------------------------------------- FormsAuthentication.SetAuthCookie(username, false); Configurations.Client["my_id", true] = dv[0]["EmpID"].ToString(); Configurations.Client["my_firstname", true] = dv[0]["EmpName"].ToString(); Configurations.Client["my_deptid", true] = dv[0]["DeptCode"].ToString(); Configurations.Client["my_maindeptid", true] = dv[0]["MainDeptCode"].ToString(); Configurations.Client["my_mainsubdeptid", true] = dv[0]["MainSubDeptCode"].ToString(); Configurations.Client["my_schoolid", true] = dv[0]["SchoolID"].ToString(); Configurations.Client["my_userroleid", true] = dv[0]["UserRoleID"].ToString(); Configurations.Client["my_rolelevel", true] = dv[0]["RoleLevel"].ToString(); Configurations.Client["my_lastlogin", true] = DateTime.Now.ToString("d/M/yyyy HH:mm"); if (savemyinfo) { Configurations.Client["starSSOuser", true] = username; Configurations.Client["starSSOpwd", true] = password; } Configurations.Client["starSSOsave", true] = savemyinfo.ToString().ToLower(); Configurations.Client["starSSOauto", true] = autosignin.ToString().ToLower(); return(true); }
public static void CheckTimeOut() { //¼Ùéãªé§Ò¹Ãкº ËÁ´àÇÅÒ â´ÂäÁè·Ó§Ò¹Ãкº ËÃ×Í ÍÍ¡¨Ò¡Ãкºâ´ÂäÁè¡´ÍÍ¡¨Ò¡â»Ãá¡ÃÁ ClientLimit cl = new ClientLimit(); cl.CheckClient(CurrentUser.ID, FormsAuthentication.DefaultUrl); }