private CredsValidator ValidateCreds(ClientCreds clientCreds) { var credsValidator = new CredsValidator() { Error = false, Message = "Valid" }; if (credsValidator == null) { credsValidator.Error = true; credsValidator.Message = "Creds null"; } if (clientCreds.ClientName == null || clientCreds.ClientName.Equals("")) { credsValidator.Error = true; credsValidator.Message = "Client name null or empty"; } if (clientCreds.Password == null || clientCreds.Password.Equals("")) { credsValidator.Error = true; credsValidator.Message = "Client password null or empty"; } return(credsValidator); }
public async Task <IActionResult> Login([FromBody] ClientCreds clientCreds) { var validation = ValidateCreds(clientCreds); if (validation.Error) { return(BadRequest(CreateAuthResponse(true, validation.Message))); } try { var client = await authServices.ClientAuth(clientCreds); if (client == null) { return(Unauthorized()); } else { var authResponse = CreateAuthResponse(false, "Valid"); authResponse.Client = client; authResponse.Token = client.CreateJwtToken(configuration); return(Ok(authResponse)); } } catch (Exception e) { return(StatusCode(500, CreateAuthResponse(true, e.Message))); } }
private async Task PerformLoginAction() { if (ValidateControls()) { var clientCreds = new ClientCreds() { Clientname = tbClientName.Text, Password = tbPassword.Text }; AuthResponse authResponse = await authHandler.Authenticate(clientCreds); if (authResponse == null) { MessageBox.Show("Auth failed, response is null"); } else { if (authResponse.Error) { MessageBox.Show("Auth error, message: " + authResponse.Message); } else { Core.Auth = authResponse; TicketScannerForm mainForm = new TicketScannerForm(); mainForm.Show(); } } } }
public async Task <Clients> ClientAuth(ClientCreds clientCreds) { var client = await db.Clients.FirstOrDefaultAsync(c => c.Username == clientCreds.ClientName); if (client != null) { if (client.Password.Equals(clientCreds.Password)) { return(client); } } return(null); }
public async Task <AuthResponse> Authenticate(ClientCreds creds) { using (HttpResponseMessage responseMessage = await HttpClientBuilder.HttpClient.PostAsJsonAsync($"{HttpClientBuilder.BaseUrl}auth", creds)) { if (responseMessage.IsSuccessStatusCode) { AuthResponse authResponse = await responseMessage.Content.ReadAsAsync <AuthResponse>(); return(authResponse); } else { return(new AuthResponse() { Error = true, Message = responseMessage.ReasonPhrase }); } } }
public void Register([FromBody] ClientCreds clientCreds) { }