示例#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()
        {
            AccountLoginVM model = new AccountLoginVM();

            TryUpdateModel(model);

            AuthenticationManager.AuthenticateUser(model.Username, model.Password);

            if (AuthenticationManager.LoggedUser == null)
            {
                ModelState.AddModelError(String.Empty, "Invalid username or password.");
                return(View(model));
            }

            if (model.IsRemembered)
            {
                CookieService.CreateCookie();
            }

            if (!String.IsNullOrEmpty(model.RedirectUrl))
            {
                return(Redirect(model.RedirectUrl));
            }

            return(this.RedirectToAction <ContactsController>(c => c.List()));
        }
示例#3
0
 public IActionResult Register(HttpSession session, HttpResponse response)
 {
     if (AuthenticationManager.AuthenticateUser(session))
     {
         return(this.View());
     }
     this.Redirect(response, "/home/index");
     return(null);
 }
示例#4
0
        public IActionResult Login([FromBody] User login)
        {
            IActionResult response = Unauthorized();
            var           user     = authManager.AuthenticateUser(login);

            if (user != null)
            {
                var tokenString = JwtManager.GenerateToken(user.Username);

                var claimsPrincipal = JwtManager.GetPrincipal(tokenString);

                response = Ok(new { token = tokenString });
            }

            return(response);
        }
示例#5
0
 public IActionResult Register(HttpSession session, HttpResponse response, RegisterUserBindingModel rubm)
 {
     if (AuthenticationManager.AuthenticateUser(session))
     {
         if (!this.service.IsRegisterModelValid(rubm))
         {
             this.Redirect(response, "/users/register");
             return(null);
         }
         User user = this.service.GetUserFromRegisterBind(rubm);
         this.service.RegisterUser(user);
         this.Redirect(response, "/users/login");
         return(null);
     }
     this.Redirect(response, "/home/index");
     return(null);
 }
示例#6
0
        public IActionResult Login(HttpResponse response, HttpSession session, LoginUserBindingModel lumb)
        {
            if (AuthenticationManager.AuthenticateUser(session))
            {
                if (!service.IsLoginBindValid(lumb))
                {
                    this.Redirect(response, "/users/login");
                    return(null);
                }

                User user = this.service.GetUserFromLoginBind(lumb);
                this.service.LoginUser(session, user);
                this.Redirect(response, "/home/index");
                return(null);
            }
            this.Redirect(response, "/home/index");
            return(null);
        }
示例#7
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));
        }
示例#8
0
 private bool Authenticate(Login login)
 {
     return(_authenticationManager.AuthenticateUser(login));
 }
        public void ShouldFailToAuthenticateIfUserNotFound()
        {
            _userManager.CreateUser(new UserDisplay
            {
                Username = Username,
                Password = Password
            });

            var ex = Assert.Throws <OverseerException>(() => _authenticationManager.AuthenticateUser("FakeName", Password));

            Assert.AreEqual("invalid_username", ex.Message);
        }