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;
        }
        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);
        }