/// <summary> /// 登录页面 /// </summary> /// <returns></returns> public ActionResult Index() { return(View()); //开发的时候,只需要注释此行代码 #if DEBUG //Debug 测试时使用 AccountBLL accountBLL = new BLL.AccountBLL(); SysPerson person = accountBLL.ValidateUser("Admin", EncryptAndDecrypte.EncryptString("123456")); if (person != null) {//登录成功 Account account = new Account(); account.Name = person.MyName; account.PersonName = person.Name; account.Id = person.Id.ToString(); account.LastLogonIP = person.LastLogonIP; account.LastLogonTime = person.LastLogonTime; account.LogonNum = person.LogonNum; account.Theme = person.PageStyle; //Session["account"] = account; Utils.WriteCookie("account", account, 7); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); #else //Release 正式平台使用 return(View()); #endif }
public ActionResult Index(LogOnModel model) { #region 验证码验证 if (Session["__VCode"] == null || (Session["__VCode"] != null && model.ValidateCode != Session["__VCode"].ToString())) { ModelState.AddModelError("PersonName", "验证码错误!"); //return ""; return View(); } #endregion if (ModelState.IsValid) { AccountBLL accountBLL = new BLL.AccountBLL(); SysPerson person = accountBLL.ValidateUser(model.PersonName, EncryptAndDecrypte.EncryptString(model.Password)); if (person != null) {//登录成功 Account account = new Account(); account.Name = person.MyName; account.PersonName = person.Name; account.Id = person.Id.ToString(); account.LastLogonIP = person.LastLogonIP; account.LastLogonTime = person.LastLogonTime; account.LogonNum = person.LogonNum; Session["account"] = account; return RedirectToAction("Index", "Home"); } } ModelState.AddModelError("PersonName", "用户名或者密码出错。"); return View(); }
public ActionResult Index(LogOnModel model) { #region 验证码验证 if (Session["__VCode"] == null || (Session["__VCode"] != null && model.ValidateCode != Session["__VCode"].ToString())) { ModelState.AddModelError("PersonName", "验证码错误!"); //return ""; return(View()); } #endregion if (ModelState.IsValid) { IAccountBLL accountBLL = new BLL.AccountBLL(); SysPerson person = accountBLL.ValidateUser(model.PersonName, EncryptAndDecrypte.EncryptString(model.Password)); if (person != null) {//登录成功 Account account = new Account(); account.Name = person.Name; account.PersonName = person.MyName; account.Id = person.Id.ToString(); account.LastLogonIP = person.LastLogonIP; account.LastLogonTime = person.LastLogonTime; account.LogonNum = person.LogonNum; Utils.WriteCookie("account", account, 7); //Session["account"] = account; return(RedirectToAction("Index", "Home")); } } ModelState.AddModelError("PersonName", "用户名或者密码出错。"); return(View()); }
/// <summary> /// 登录页面 /// </summary> /// <returns></returns> public ActionResult Index() { return View(); //开发的时候,只需要注释此行代码 #if DEBUG //Debug 测试时使用 AccountBLL accountBLL = new BLL.AccountBLL(); SysPerson person = accountBLL.ValidateUser("Admin", EncryptAndDecrypte.EncryptString("123456")); if (person != null) {//登录成功 Account account = new Account(); account.Name = person.MyName; account.PersonName = person.Name; account.Id = person.Id.ToString(); account.LastLogonIP = person.LastLogonIP; account.LastLogonTime = person.LastLogonTime; account.LogonNum = person.LogonNum; Session["account"] = account; return RedirectToAction("Index", "Home"); } return RedirectToAction("Index", "Home"); #else //Release 正式平台使用 return View(); #endif }
public ActionResult Login(string lname, string pwd) { try { // dynamic login = this.LoginCheck(lname, pwd, "3");//用户登录(调用API接口) BLL.AccountBLL account = new BLL.AccountBLL(); var data = account.ValidateUser(lname, pwd); //if (lname != "admin" || pwd != "123456") //{ // return Json(new { Code = "0", Message = "用户名或密码错误!" }); //} //dynamic login = new { Code = "ok" }; if (data != null)//登录成功 { HttpCookie loginCookie = new HttpCookie("Login"); //loginCookie.Values["CompanyID"] = login.Result.CompanyID; //loginCookie.Values["CompanyName"] = login.Result.CompanyName; //loginCookie.Values["UserID"] = login.Result.UserID;//登录人ID //loginCookie.Values["UserCode"] = login.Result.UserCode;//人员编码(暂时无用) //loginCookie.Values["LoginName"] = login.Result.LoginName;//登录名 //loginCookie.Values["RealName"] = login.Result.RealName;//登录人真实姓名 //loginCookie.Values["Sex"] = login.Result.Sex;//性别 //loginCookie.Values["DepartmentID"] = login.Result.DepartmentID;//所属部门ID //loginCookie.Values["DepartmentName"] = login.Result.DepartmentName;//所属部门名称 //loginCookie.Values["BranchID"] = login.Result.BranchID;//直属机构ID //loginCookie.Values["BranchName"] = login.Result.BranchName;//直属机构名称 //loginCookie.Values["PositionID"] = login.Result.PositionID;//所属岗位ID //loginCookie.Values["PositionName"] = login.Result.PositionName;//所属岗位名称 //loginCookie.Values["UserName"] = "******" + login.Result.DepartmentName + "】" + login.Result.RealName; //loginCookie.Values["CompanyCityCode"] = login.Result.CompanyCityCode; loginCookie.Values["CompanyID"] = "1"; loginCookie.Values["CompanyName"] = "创英"; loginCookie.Values["UserID"] = data.ID.ToString(); //登录人ID loginCookie.Values["UserCode"] = data.ID.ToString(); //人员编码(暂时无用) loginCookie.Values["LoginName"] = lname; //登录名 loginCookie.Values["RealName"] = data.RName; //登录人真实姓名 loginCookie.Values["Sex"] = data.Sex; //性别 loginCookie.Values["DepartmentID"] = data.ORG_Department_ID.ToString(); //所属部门ID loginCookie.Values["DepartmentName"] = "创英"; //所属部门名称 loginCookie.Values["BranchID"] = "1"; //直属机构ID loginCookie.Values["BranchName"] = "创英"; //直属机构名称 loginCookie.Values["PositionID"] = "2"; //所属岗位ID loginCookie.Values["PositionName"] = "创英"; //所属岗位名称 loginCookie.Values["UserName"] = "******"; loginCookie.Values["CompanyCityCode"] = "110199"; #region 获取用户权限 Database dbEntity = EnterpriseLibraryContainer.Current.GetInstance <Database>("connStr"); DbCommand cmd = dbEntity.GetStoredProcCommand("Pro_GetUserAuthority"); dbEntity.AddInParameter(cmd, "@userID", DbType.Int32, "1");//data.ID cmd.CommandTimeout = 0; dbEntity.ExecuteNonQuery(cmd); DataSet ds = dbEntity.ExecuteDataSet(cmd); DataTable authorityMenu = ds.Tables[0]; //菜单及菜单操作权限 DataTable authorityDepartmentScope = ds.Tables[1]; //部门范围权限 DataTable authorityDepartment = ds.Tables[2]; //部门业务权限 //loginCookie.Values["AuthorityMenu"] = Common.EncryptAndDecrypte.EncryptString(Newtonsoft.Json.JsonConvert.SerializeObject(authorityMenu)); //loginCookie.Values["AuthorityDepartmentScope"] = Common.EncryptAndDecrypte.EncryptString(Newtonsoft.Json.JsonConvert.SerializeObject(authorityDepartmentScope)); //loginCookie.Values["AuthorityDepartment"] = Common.EncryptAndDecrypte.EncryptString(Newtonsoft.Json.JsonConvert.SerializeObject(authorityDepartment)); Session["AuthorityMenu"] = Common.EncryptAndDecrypte.EncryptString(Newtonsoft.Json.JsonConvert.SerializeObject(authorityMenu)); Session["AuthorityDepartmentScope"] = Common.EncryptAndDecrypte.EncryptString(Newtonsoft.Json.JsonConvert.SerializeObject(authorityDepartmentScope)); Session["AuthorityDepartment"] = Common.EncryptAndDecrypte.EncryptString(Newtonsoft.Json.JsonConvert.SerializeObject(authorityDepartment)); #endregion Response.Cookies.Add(loginCookie); return(Json(new { Code = "ok" })); } else { string code = "0"; string message = "用户名或密码错误!"; return(Json(new { Code = code, Message = message })); } } catch (Exception ex) { return(Json(new { Code = "-1", Message = "系统错误:" + ex.ToString() })); } }