Beispiel #1
0
        // 登录
        public JsonResult Ajax_Login()
        {
            var stream = new StreamReader(Request.InputStream);
            var str    = stream.ReadToEnd();
            JavaScriptSerializer js = new JavaScriptSerializer();
            var datas = js.Deserialize <Dictionary <string, string> >(str);

            try
            {
                if (!service.Verify(datas["username"], datas["password"])) //如果密码不正确,或用户名不存在
                {
                    throw new Exception("");
                }
                Account account;
                if (datas["username"].ToLower().StartsWith("sdt")) // 如果用工号登录
                {
                    account = service.GetOneAccountByjobnumber(datas["username"]);
                }
                else
                {
                    account = service.GetOneAccount(AccountIdentifier.of(datas["username"]));
                }
                sessionService.Login(account.Id.UserName, false);
                sessionService.SaveAccount(account);

                var result = new
                {
                    Result = "成功"
                };
                return(Json(result, JsonRequestBehavior.DenyGet));
            }
            catch
            {
                var result = new
                {
                    Result = "用户名或密码错误!"
                };
                return(Json(result, JsonRequestBehavior.DenyGet));
            }
        }
Beispiel #2
0
 public ActionResult Login(FormCollection FC)
 {
     if (string.IsNullOrEmpty(FC[Keys.UserName]) ||
         string.IsNullOrEmpty(FC[Keys.PassWord]))
     {
         ViewData[Keys.ErrorMessage] = "用户名或密码不能为空!";
         return(View());
     }
     if (string.IsNullOrEmpty(FC[Keys.VefCode]))
     {
         ViewData[Keys.ErrorMessage] = "验证码不能为空!";
         return(View());
     }
     if (sessionService.GetVefCode().ToLower() != FC[Keys.VefCode].ToLower())
     {
         ViewData[Keys.ErrorMessage] = "验证码错误!";
         return(View());
     }
     try
     {
         if (!service.Verify(FC[Keys.UserName], FC[Keys.PassWord])) //如果密码不正确,或用户名不存在
         {
             throw new Exception("");
         }
         var account = service.GetOneAccount(AccountIdentifier.of(FC[Keys.UserName]));
         sessionService.Login(FC[Keys.UserName], false);
         sessionService.SaveAccount(account);
         if ((account.Roles & (int)Role.Admin) == (int)Role.Admin)
         {
             return(RedirectToAction("Index", "Admin", new { Area = "Admin" }));
         }
         //return RedirectToAction("Index", "User", new {Area = "User"});
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception e)
     {
         ViewData[Keys.ErrorMessage] = "用户名或密码错误!";
         return(View());
     }
 }
        // 登录
        public JsonResult Ajax_Login()
        {
            var datas = tool.Deserialize <Dictionary <string, string> >(Request.InputStream);

            try
            {
                if (!service.Verify(datas["username"], datas["password"])) //如果密码不正确,或用户名不存在
                {
                    throw new Exception("有户名或密码错误");
                }
                Account account;
                if (datas["username"].ToLower().StartsWith("sdt")) // 如果用工号登录
                {
                    account = service.GetOneAccountByjobnumber(datas["username"]);
                }
                else
                {
                    account = service.GetOneAccount(AccountIdentifier.of(datas["username"]));
                }
                sessionService.Login(account.Id.UserName, false);
                sessionService.SaveAccount(account);

                var result = new
                {
                    Result = "成功"
                };
                return(Json(result, JsonRequestBehavior.DenyGet));
            }
            catch (Exception err)
            {
                var result = new
                {
                    Result = err.Message
                };
                return(Json(result, JsonRequestBehavior.DenyGet));
            }
        }