Ejemplo n.º 1
0
        //ajax 实现登录功能
        public ActionResult DoLogin(string userName, string password)
        {
            if (userName == "")
            {
                return Json(new { IsSuccess = false, message = "请输入用户名" });
            }
            if (password == "")
            {
                return Json(new { IsSuccess = false, message = "请输入密码" });
            }

            UserModel user = new UserModel();
            user = UserManager.Get(userName, password);
            if (user == null)
            {
                return Json(new { IsSuccess = false, message = "用户名或密码错误" });
            }
            if (!user.IsEnabled)
            {
                return Json(new { IsSuccess = false, message = "用户已经冻结" });
            }
            else
            {
                Session.Add("user", user);
                return Json(new { IsSuccess = true, message = "登陆成功", action = "/Admin/Index" });
            }

        }
Ejemplo n.º 2
0
 public ActionResult Info()
 {
     UserModel user = new UserModel();
     user = Session["user"] as UserModel;
     ViewData["userName"] = user.Account;
     return PartialView();
 }
Ejemplo n.º 3
0
 public ActionResult Login(UserModel user, string strReturnUrl)
 {
     user = UserManager.Get(user.Account, user.Password);
     if (user == null)
     {
         ModelState.AddModelError("IsEnabled", "用户名或密码错误");
         return View(user);
     }
     if (!user.IsEnabled)
     {
         ModelState.AddModelError("IsEnabled", "用户已经被禁用");
         return View(user);
     }
     else
     {
         Session.Add("user", user);
         if (Url.IsLocalUrl(strReturnUrl) && strReturnUrl.Length > 1 && strReturnUrl.StartsWith("/") && !strReturnUrl.StartsWith("//") && !strReturnUrl.StartsWith("/\\"))
         {
             return Redirect(strReturnUrl);
         }
         else
         {
             return RedirectToAction("Index", "Admin");
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 设置初始账号
 /// </summary>
 private void SetInitAccount()
 {
     IApplicationContext cxt = ContextRegistry.GetContext();
     IUserManager manger = (IUserManager)cxt.GetObject("Manager.User");
     IMailManager mangerFolder = (IMailManager)cxt.GetObject("Manager.Mail");
     const string account = "admin";
     var user = manger.Get(account);
     if (user == null)
     {
         user = new UserModel
         {
             Account = account,
             Name = "管理员",
             ID = Guid.NewGuid(),
             CreateTime = DateTime.Now,
             IsEnabled = true
         };
         manger.Save(user);
     }
 }