예제 #1
0
 //
 // GET : /Account/LogIn
 public ActionResult LogIn()
 {
     // We check if the user is currently authenticated/logged in.
     // We do not display the Login screen if the user is authenticated
     // TODO : Refactor this taking the authentication wrapper into consideration
     if(!User.Identity.IsAuthenticated)
     {
         // Case : User is not authenticated
         var loginViewModel = new UserLoginViewModel();
         return View(loginViewModel);
     }
     else
     {
         // Case : User is authenticated/logged in so we rediredt it
         return RedirectToAction("Index", "Home");
     }
 }
예제 #2
0
        public ActionResult LogIn(UserLoginViewModel model)
        {
            // Check if the model state is valid based on the Data anotations for the view model
            if(ModelState.IsValid)
            {
                // Try and validate the user using the User Service
                var user = _userService.ValidateUser(model.Username, model.Password);

                // If the service returns a user object the validation/authentication is successful
                if(user != null)
                {
                    // TODO : Refactor this or totally remove the Authentication Wrapper
                    // Set the authentication wrapper helper, based on the used UI/Framework layer
                    _authWrapper.SetAuthenticationHelper(Response);

                    // Sign in the user using the authentication wrapper
                    _authWrapper.SignIn(user.Username, false, user.Id);

                    // Redirect the user to the main application page after logging in
                    return RedirectToAction("Index", "Application");
                }
                else
                {
                    // If there is no user returned from the user service validation call,
                    // there is no user with the given credentials, or something went wrong.
                    ModelState.AddModelError("", "Wrong username or password. Please try again.");

                    return View(model);
                }
            }
            else
            {
                //Case: The model state is not valid
                return View(model);
            }
        }