Ejemplo n.º 1
0
        protected override async Task <AuthenticateResult> HandleAuthenticateAsync()
        {
            if (!Request.Headers.ContainsKey("Authorization"))
            {
                return(AuthenticateResult.Fail("Missing authorization header"));
            }

            Faktura.Model.Korisnik user = null;

            try
            {
                var authHeader      = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
                var credentialBytes = Convert.FromBase64String(authHeader.Parameter);
                var credentials     = Encoding.UTF8.GetString(credentialBytes).Split(':');
                var username        = credentials[0];
                var password        = credentials[1];

                user = await _korisnikService.Login(username, password);
            }
            catch (Exception ex)
            {
                return(AuthenticateResult.Fail("Incorrect username or password"));
            }

            var claims = new List <Claim> {
                new Claim(ClaimTypes.NameIdentifier, user.KorisnickoIme),
                new Claim(ClaimTypes.Name, user.Ime),
            };

            var identity  = new ClaimsIdentity(claims, Scheme.Name);
            var principal = new ClaimsPrincipal(identity);
            var ticket    = new AuthenticationTicket(principal, Scheme.Name);

            return(AuthenticateResult.Success(ticket));
        }
Ejemplo n.º 2
0
        public void Login()
        {
            var email    = _view.Email;
            var password = _view.Password;

            User user;

            try
            {
                user = _userService.Login(email, password);
            } catch (UserException)
            {
                _view.Password = "";
                MessageBox.Show("Check E-mail and password.");
                return;
            }

            var newForm = _factory.createMainView(user, _view);

            _view.Email    = "";
            _view.Password = "";
            _view.Hide();
            newForm.Show();
        }
Ejemplo n.º 3
0
 public KorisnikModel Login([FromQuery] LoginRequest request)
 {
     return(_korisnikService.Login(request));
 }