Пример #1
0
        public ActionResult Login(LoginViewModel loginViewModel)
        {
            if (loginViewModel == null)
            {
                throw new ArgumentNullException("loginViewModel");
            }

            if (this.ModelState.IsValid)
            {
                var user = this.userService.GetUserByUserName(loginViewModel.Name);
                if (user != null)
                {
                    if (!user.IsActive)
                    {
                        this.ModelState.AddModelError(
                            "Name", "Please activate your account first by clicking on the link in your " + 
                            "activation email.");
                        return this.View("Login", loginViewModel);
                    }

                    var hashedPassword = this.formsAuthenticationService.HashAndSalt(
                        loginViewModel.Name,
                        loginViewModel.Password);

                    if(hashedPassword == user.Password)
                    {
                        this.formsAuthenticationService.SetAuthCookie(user.UserName, false);
                        if (user is Child)
                        {
                            return this.RedirectToAction("ChildView", "Account");
                        }
                        else
                        {
                            return this.RedirectToAction("Index", "Child");
                        }
                    }
                    this.ModelState.AddModelError("Password", "Invalid Password");
                }
                else
                {
                    this.ModelState.AddModelError("Name", "Invalid Name");
                }
            }

            return this.View("Login", loginViewModel);
        }
Пример #2
0
 public ActionResult Login()
 {
     var loginViewModel = new LoginViewModel
     {
         Name = "",
         Password = ""
     };
     return this.View("Login", loginViewModel);
 }