public ActionResult Login(vLogin model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Password = Helpers.Encryt.GetMD5(model.Password.Trim());
                    var user = db.Users.Where(u => u.Number == model.Number.Trim() && u.Password == model.Password && u.RoleAsInt > 1).FirstOrDefault();
                    if (user == null)
                    {
                        ModelState.AddModelError("", "用户或密码不正确!");
                    }
                    else
                    {
                        FormsAuthentication.SetAuthCookie(model.Number, model.RememberMe);
                        return RedirectToAction("Index", "Home");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "登陆失败,请重试!");
                }

            }
            else
            {
                ModelState.AddModelError("", "信息填写错误!");
            }
            return View();
        }
Esempio n. 2
0
        public ActionResult <Employee> Authenticate(vLogin vm)
        {
            var employee = vm.Authenticate();

            if (employee != null)
            {
                return(employee);
            }

            return(BadRequest());
        }
Esempio n. 3
0
 public ActionResult Login(vLogin model)
 {
     if (ModelState.IsValid)
     {
         User user = new User();
         model.Password = Helpers.Encryt.GetMD5(model.Password);
         user = db.Users.Where(u => u.Username == model.Username && u.Password == model.Password).SingleOrDefault();
         if (user == null)
         {
             ModelState.AddModelError("", "用户名或密码错误!");
         }
         else
         {
             FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
             return RedirectToAction("Index", "Home");
         }
     }
     else
     {
         ModelState.AddModelError("", "登陆信息错误请重新填写!");
     }
     return View(model);
 }
Esempio n. 4
0
        public ActionResult Login(vLogin model)
        {
            if (Request.UrlReferrer == null)
            {
                ViewBag.Info = "不存在这个用户!";
                return(View());
            }
            if (User.Identity.IsAuthenticated == true)
            {
                return(Redirect("/"));
            }
            User user;

            if (model.Username.IndexOf("@") > 0)
            {
                user = (from u in DbContext.Users
                        where u.Email == model.Username
                        select u).SingleOrDefault();
            }
            else
            {
                user = (from u in DbContext.Users
                        where u.Username == model.Username
                        select u).SingleOrDefault();
            }
            if (user == null)
            {
                ViewBag.Info = "不存在这个用户!";
                return(View());
            }

            //更新md5密码为sha1
            if (user.Password.Length == 32)
            {
                if (Helpers.Security.MD5(model.Password).ToUpper() == user.Password.ToUpper())
                {
                    user.Password = Helpers.Security.SHA1(model.Password);
                    DbContext.SaveChanges();
                }
            }

            //更新提交/ac数据
            if (string.IsNullOrEmpty(user.SubmitList) || string.IsNullOrEmpty(user.AcceptedList) || true)
            {
                var sub = (from s in DbContext.Statuses
                           where s.UserID == user.ID
                           select s.ProblemID).Distinct().ToList();
                user.SubmitList  = Helpers.AcList.ToString(sub);
                user.SubmitCount = (from s in DbContext.Statuses
                                    where s.UserID == user.ID
                                    select s).Count();
                var ac = (from s in DbContext.Statuses
                          where s.UserID == user.ID &&
                          s.ResultAsInt == 0
                          select s.ProblemID).Distinct().ToList();
                user.AcceptedCount = ac.Count;
                user.AcceptedList  = Helpers.AcList.ToString(ac);
                DbContext.SaveChanges();
            }

            //更新明文密码为sha1
            if (user.Password.Length < 16)
            {
                if (user.Password == model.Password)
                {
                    user.Password = Helpers.Security.SHA1(model.Password);
                    DbContext.SaveChanges();
                }
            }

            if (user.Password != Helpers.Security.SHA1(model.Password))
            {
                ViewBag.Info = "密码错误!";
                return(View());
            }
            else
            {
                if (user.Role == UserRole.Temporary)
                {
                    return(Message("您已被封号,系统禁止您登录!"));
                }
                FormsAuthentication.SetAuthCookie(user.Username, model.Remember);
                user.LastLoginTime = DateTime.Now;
                DbContext.SaveChanges();
                Helpers.Gravatar.RefreshGravatar(user.ID);
                if (Request.UrlReferrer == null)
                {
                    return(Redirect("/"));
                }
                else
                {
                    return(Redirect(Request.UrlReferrer.ToString()));
                }
            }
        }