Esempio n. 1
0
        public IActionResult Login(LoginPassword model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var auth = _authService.CanProvideToken(model.Login, model.Password);

            if (!auth.Item1)
            {
                ModelState.AddModelError(nameof(model.Login), "Wrong login or password");
                return(BadRequest(ModelState));
            }

            var token = _tokenService.CreateToken(auth.Item2);

            _httpContext.AddAuthorizationHeader(token);

            return(Ok($"Bearer {token}"));
        }
Esempio n. 2
0
        public async Task <UserModel> LoginActiveDirectory([FromBody] LoginModel model)
        {
            if (await ldapRepository.Login(model) == OperationStatus.OK)
            {
                HttpContext.AddAuthorizationHeader(encryptor.Encrypt(model.Username.Substring(0, model.Username.IndexOf("@"))));
                var user = await applicationUserService.GetUserByName(model.Username);

                return(user);
            }

            Unauthorized();
            return(null);
        }
Esempio n. 3
0
        public async Task <UserModel> Login([FromBody] LoginModel model)
        {
            if (await applicationUserService.Login(model) == OperationStatus.OK)
            {
                HttpContext.AddAuthorizationHeader(encryptor.Encrypt(model.Username));
                var user = await applicationUserService.GetUserByName(model.Username);

                return(user);
            }

            Unauthorized();
            return(null);
        }
Esempio n. 4
0
        public async Task <bool> Login([FromBody] LoginModel model)
        {
            var result = await safeAccountService.Login(model);

            if (!string.IsNullOrEmpty(result))
            {
                HttpContext.AddAuthorizationHeader(result);
                return(true);
            }
            else
            {
                HttpContext.Response.StatusCode = 401;
                return(false);
            }
        }
Esempio n. 5
0
        public async Task <UserModel> Register([FromBody] RegisterModel model)
        {
            if (model.Password.Length < 5)
            {
                BadRequest();
                return(null);
            }

            var user = await applicationUserService.Register(model);

            if (user != null)
            {
                HttpContext.AddAuthorizationHeader(encryptor.Encrypt(user.UserName));
                return(user);
            }

            BadRequest();
            return(null);
        }