public ActionResult GetLogin(tAdminDTO t) { if (t.Code != Session["ValidateCode"].ToString()) { ModelState.AddModelError("Code", "验证码不正确!"); return(View("Login")); } if (ModelState.IsValid) { //string User_Name = this.Request.Form["UserName"]; //string User_Pw = this.Request.Form["PassWord"]; if (!string.IsNullOrEmpty(t.Name) && !string.IsNullOrEmpty(t.Password)) { db_BFSEntities ent = new db_BFSEntities(); var login = (from p in ent.tAdmin where p.Name == t.Name && p.Password == t.Password select p).Distinct().ToList(); if (login.Count > 0) { tAdmin tadmin = login.FirstOrDefault(); Session[WebConstants.UserSession] = tadmin; Session[WebConstants.UserRoleMenu] = GetMenuByUserID(login.First().Name); System.Web.HttpContext.Current.Session["username"] = login.First().Name.ToString(); Session["tUsers"] = login.ToList(); string fromurl = Request.UrlReferrer.Query; if (fromurl.IndexOf("?fromurl=") > -1) { fromurl = fromurl.Substring(9); return(Redirect(fromurl)); } else { return(this.RedirectToAction("Index", "Account")); } } else { ModelState.AddModelError("Name", "登陆失败!"); } } } return(View("Login")); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { bool Pass = false; try { var websession = httpContext.Session[WebConstants.UserSession]; if (websession == null) { httpContext.Response.StatusCode = 401;//无权限状态码 Pass = false; IsLogin = false; } else { tAdmin user = httpContext.Session[WebConstants.UserSession] as tAdmin; if (user == null) { httpContext.Response.StatusCode = 401;//无权限状态码 Pass = false; IsLogin = false; } else if (!IsMenuRole(httpContext)) { httpContext.Response.StatusCode = 401;//无权限状态码 Pass = false; IsLogin = true; } else { Pass = true; } } } catch (Exception) { return(Pass); } return(Pass); }
public long Insert(tAdmin user) { db.tAdmins.Add(user); db.SaveChanges(); return(user.ID); }