コード例 #1
0
        public ActionResult Login()
        {
            if (Request.IsAuthenticated)
            {
                return RedirectToAction("Index", "Video");
            }

            var model = new UserAuthenticateModel();
            return View(model);
        }
コード例 #2
0
        public bool Authenticate(UserAuthenticateModel model)
        {
            var user = Entities.Users.FirstOrDefault(u => u.Email == model.Email);
            if (user == null)
            {
                throw new ArgumentException(Strings.IncorrectCombination);
            }

            var hash = Security.HashSHA1(model.Password);
            if (hash != user.PasswordHash)
            {
                throw new ArgumentException(Strings.IncorrectCombination);
            }

            return true;
        }
コード例 #3
0
        public ActionResult Login(UserAuthenticateModel model)
        {
            if (!ModelState.IsValid)
            {
                model.IsValid = false;
                model.ErrorMessage = Strings.FixValidationErrors;
                return View(model);
            }

            try
            {
                if (_security.Authenticate(model))
                {
                    FormsAuthentication.RedirectFromLoginPage(model.Email, false);
                }
            }
            catch (ArgumentException ex)
            {
                model.IsValid = false;
                model.ErrorMessage = ex.Message;
                return View(model);
            }
            catch (Exception)
            {
                model.IsValid = false;
                model.ErrorMessage = Strings.ErrorOccured;
                return View(model);
            }

            return View(model);
        }