namespace BLL { using System; using System.Collections.Generic; using System.Linq; using System.Web.Security; using System.Web; using EmitMapper; using Model; public static class LoginService { public static SGGLDB db = Funs.DB; /// /// 用户登录成功方法 /// /// 登录成功名 /// 未加密密码 /// 记住我开关 /// 调用页面 /// 是否登录成功 public static bool UserLogOn(string account, string password, bool rememberMe, System.Web.UI.Page page) { try { List x = (from y in Funs.DB.Sys_User where y.Account == account && y.IsPost == true && y.Password == Funs.EncryptionPassword(password) select y).ToList(); if (x.Any()) { string accValue = HttpUtility.UrlEncode(account); FormsAuthentication.SetAuthCookie(accValue, false); page.Session[SessionName.CurrUser] = x.First(); return true; } else { return false; } } catch (Exception ex) { ErrLogInfo.WriteLog("用户登陆错误:" + ex.Message); return false; } } /// /// OA 域账号登陆 /// /// /// /// /// /// public static bool UserLogOn_OA(string account, bool rememberMe, System.Web.UI.Page page) { List x = (from y in Funs.DB.Sys_User where y.Account == account && y.IsPost == true select y).ToList(); if (x.Any()) { string accValue = HttpUtility.UrlEncode(account); FormsAuthentication.SetAuthCookie(accValue, false); page.Session[SessionName.CurrUser] = x.First(); return true; } else { return false; } } /// /// 用户登录成功方法 /// /// 登录成功名 /// 未加密密码 /// 记住我开关 /// 调用页面 /// 是否登录成功 public static bool UserLogOn(string account, bool rememberMe, System.Web.UI.Page page) { List x = (from y in Funs.DB.Sys_User where y.Account == account && y.IsPost == true select y).ToList(); if (x.Any()) { string accValue = HttpUtility.UrlEncode(account); FormsAuthentication.SetAuthCookie(accValue, false); page.Session[SessionName.CurrUser] = x.First(); if (rememberMe) { System.Web.HttpCookie u = new System.Web.HttpCookie("UserInfo"); u["username"] = accValue; //u["password"] = password; // Cookies过期时间设置为一年. u.Expires = DateTime.Now.AddYears(1); page.Response.Cookies.Add(u); } else { // 当选择不保存用户名时,Cookies过期时间设置为昨天. page.Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(-1); } return true; } else { return false; } } } }