예제 #1
0
        public async Task Login_NonexistentEmail_ReturnNull()
        {
            // Arrange, Act
            var result = await _userLoginService.Login(new UserLoginRequest
            {
                Email    = "email",
                Password = "******"
            });

            // Assert
            Assert.Null(result);
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            IUserLoginService    testLoginService    = new TestLoginService(SignInManager, UserManager);
            IUserLoginService    hogentLoginService  = new HogentLoginService(SignInManager, UserManager);
            ILoginServiceFactory loginServiceFactory = new UserLoginServiceFactory(testLoginService, hogentLoginService);
            IUserLoginService    service             = loginServiceFactory.GetLoginService(model.UserName);
            SignInStatus         result = await service.Login(model.UserName, model.Password, model.RememberMe);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Het emailadres en/of wachtwoord is onbekend.");
                return(View(model));
            }
        }
        public ActionResult Login(string email, string password)
        {
            UserAccount user = _userLoginService.Login(email, password);

            if (user != null)
            {
                ClaimsIdentity identity = new ClaimsIdentity(new Claim[]
                {
                    new Claim("id", user.Id.ToString()),
                    new Claim("name", user.Name.ToString()),
                    new Claim("email", user.Email.ToString()),
                });

                var handler       = new JwtSecurityTokenHandler();
                var securityToken = handler.CreateToken(new SecurityTokenDescriptor
                {
                    Issuer             = _tokenConfigurations.Issuer,
                    Audience           = _tokenConfigurations.Audience,
                    SigningCredentials = _signingConfigurations.SigningCredentials,
                    Subject            = identity,
                    NotBefore          = DateTime.Now,
                    Expires            = DateTime.Now +
                                         TimeSpan.FromSeconds(_tokenConfigurations.Seconds)
                });
                var token = handler.WriteToken(securityToken);

                this.Response.Headers.Add("Access-Control-Expose-Headers", "x-access-token");
                this.Response.Headers.Add("x-access-token", token);

                return(Ok(user.Id));
            }
            return(Unauthorized());
        }
예제 #4
0
 private void LoginButton_Click(object sender, EventArgs e)
 {
     ChangeEnabled(false);
     userLoginService.Login(
         usernameTextBox.Text,
         passwordTextBox.Text
         );
 }
예제 #5
0
        public async Task<IActionResult> Login(UserLoginRequest userLoginRequest)
        {
            var response = await _userLoginService.Login(userLoginRequest);

            if (response == null)
            {
                return Unauthorized();
            }

            Response.Cookies.SetToken(response.AccessToken);

            return Ok(response.LoggedInUser);
        }
예제 #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            try
            {
                await loginService.Login(userInput);

                LoginState = 1;

                return(RedirectToPage("../Index"));
            }
            catch
            {
                LoginState        = -1;
                ViewData["Error"] = "login failed!";
                return(Page());
            }
        }
예제 #7
0
 public ActionResult Login([FromBody] UserLoginModel model)
 {
     return(Ok(userLoginService.Login(model)));
 }
예제 #8
0
 public async Task <UserLoginOutputDto> LoginUser(UserInputDto inputDto)
 {
     return(await userLoginService.Login(inputDto));
 }