// GET: Account public ActionResult Login() { HttpContext.Session.Set("LoginUser", UserInfoServices.LoadFirst(u => u.UserName == "admin")); return(Redirect("/Home/Index")); try { string userInfo = "";//CookieHelper.GetCookieValue("user"); if (!String.IsNullOrEmpty(userInfo)) { JObject jobj = JObject.Parse(userInfo); string userName = jobj["UserName"]?.ToString(), password = jobj["Password"]?.ToString(); UserInfo user = UserInfoServices .LoadFirst(entity => entity.UserName == userName && entity.Password == password); if (user != null) { SetUser(user); return(RedirectToAction("Index", "Home")); } } return(View()); } catch (Exception ex) { return(View()); } }
protected string ActionName; //当前Action小写名称 public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); ControllerName = filterContext.RouteData.Values["controller"] as string; ActionName = filterContext.RouteData.Values["action"] as string; Function = this.GetType().GetMethods().FirstOrDefault(u => "index".Equals(u.Name, StringComparison.InvariantCultureIgnoreCase)); if (Function == null) { throw new Exception("未能找到Action"); } UserInfo = HttpContext.Session.Get <UserInfo>("LoginUser"); if (UserInfo == null) { filterContext.Result = new RedirectResult("/Account/Login"); return; } #if DEBUG if (UserInfo == null) { //IUserInfoServices userInfoServices = AutoFacConfig.Container.Resolve<IUserInfoServices>(); UserInfo = UserInfoServices.LoadFirst(u => u.UserName == "admin"); } #endif }
public ActionResult Edit(UserEdit userEdit) { UserInfo user = UserInfoServices .LoadFirst(u => u.ID == userEdit.ID.Value); if (user == null) { return(NotFound(new Result { State = 0, Message = "修改的用户不存在" })); } user = Mapper.Map(userEdit, user); if (UserInfoServices.EditEntity(user)) { return(Ok(new Result { State = 1, Message = "修改成功" })); } else { return(BadRequest(new Result { State = 1, Message = "修改失败" })); } }
public ActionResult <IEnumerable <object> > Get() { string username = Cache.GetString("user") ?? "admin"; UserInfo user = UserInfoServices.LoadFirst(u => u.UserName == username); List <Module> modules = ModuleServices.LoadSelectModules(user); return(Ok(new Result <object> { State = 1, Data = modules .Where(m => m.Parent == null) .Select(m => new { m.ID, m.Name, m.IconName, m.Url, m.Sort, Children = modules .Where(c => c.Parent?.ID == m.ID) .Select(c => new { c.ID, c.Name, c.IconName, c.Url, c.Sort, Children = new object[0] }) }) })); }
public IActionResult Login([FromBody] JObject jobj) { //if (!string.Equals(HttpContext.Session.Get<string>("verCode") // , login.VerifyCode, StringComparison.InvariantCultureIgnoreCase)) //{ // return BadRequest(new Result // { // State = 0, // Message = "验证码错误" // }); //} //string s = jobj["fsfsf"].ToString(); string username = jobj["username"]?.ToString(), password = jobj["password"]?.ToString(); if (IsValidUserAndPasswordCombination(username, password)) { return(BadRequest(new Result { State = 0, Message = "用户名或密码不能为空" })); } password = Md5Encryption.Encrypt(Md5Encryption.Encrypt(password, Md5EncryptionType.Strong)); UserInfo userInfo = UserInfoServices .LoadFirst(entity => entity.UserName == username && entity.Password == password); if (userInfo == null) { return(BadRequest(new Result { State = 0, Message = "用户名或密码不正确" })); } if (userInfo.IsCanUse == false) { return(BadRequest(new Result { State = 0, Message = "当前用户不可用" })); } string token = GenerateToken(username); Cache.SetString(token, userInfo.UserName); return(Ok(new Result <string> { State = 1, Message = "登陆成功", Data = token })); }
public ActionResult Edit(UserEdit userEdit) { if (ModelState.IsValid) { UserInfo user = UserInfoServices .LoadFirst(u => u.ID == userEdit.ID.Value); if (user == null) { return(Json(new Result { State = 0, Message = "修改的用户不存在" })); } user = Mapper.Map(userEdit, user); if (UserInfoServices.EditEntity(user)) { return(Json(new Result { State = 1, Message = "修改成功" })); } else { return(Json(new Result { State = 1, Message = "修改失败" })); } } else { IEnumerable <object> errors = ModelStateToJson(); return(Json(new Result <object> { State = 0, Message = "错误", Data = errors })); } }