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}")); }
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); }
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); }
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); } }
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); }