예제 #1
0
        public ActionResult Login(UsersLoginVM model)
        {
            if (ModelState.IsValid)
            {
                AuthenticationManager.AuthenticateUser(model.Username, model.Password, model.UserType);
                if (AuthenticationManager.LoggedUser != null && AuthenticationManager.LoggedUser.IsActive)
                {
                    TempData.FlashMessage("", "Welcome, " + AuthenticationManager.LoggedUser.Username, FlashMessageTypeEnum.Green);

                    if (AuthenticationManager.IsAdmin)
                    {
                        return(RedirectToAction("Index", "Admin"));
                    }
                    else if (AuthenticationManager.IsStudent)
                    {
                        return(RedirectToAction("Index", "Student"));
                    }
                    else if (AuthenticationManager.IsTeacher)
                    {
                        return(RedirectToAction("Index", "Teacher"));
                    }
                }
                ModelState.AddModelError("", "Invalid data! Try again!");
            }

            return(View(model));
        }
예제 #2
0
        public ActionResult Login(UsersLoginVM model)
        {
            if (AuthenticationManager.LoggedUser != null)
            {
                return(Redirect("~/Account/Index"));
            }

            if (ModelState.IsValid)
            {
                AuthenticationManager.AuthenticateUser(model.Username, model.Password);
                if (AuthenticationManager.LoggedUser != null)
                {
                    // Successful log
                    return(Redirect("/Contacts"));
                }
                ModelState.AddModelError("", "Invalid data! Try again!");
            }

            // Unsuccessfull log
            return(View(model));
        }