public async Task <ActionResult <AuthenticateResponse> > Login([FromBody] AuthUserData authUser) { var authResponse = await authenticationService.IsSignInSuccessful(authUser); switch (authResponse.Message) { case AuthResponseMessage.LoginAndPasswordNotProvided: case AuthResponseMessage.LoginNotProvided: case AuthResponseMessage.PasswordNotProvided: // note that not providing password does not count as login attempt default: return(BadRequest(authResponse)); case AuthResponseMessage.UserWithThisLoginNotExists: return(Conflict(authResponse.Message)); case AuthResponseMessage.WrongPassword: { int userId = await userService.GetUserIdByLogin(authUser.Login); bool shouldBeBlocked = await loginHistoryService.CheckIfLogInShouldBeBlocked(userId); if (shouldBeBlocked) { return(Conflict("Too many bad attempts. Try later.")); } await loginHistoryService.AddLoginHistory(userId, false); return(Conflict(authResponse.Message)); } case AuthResponseMessage.LoggedSucessfuly: { int userId = await userService.GetUserIdByLogin(authUser.Login); bool shouldBeBlocked = await loginHistoryService.CheckIfLogInShouldBeBlocked(userId); if (shouldBeBlocked) { return(Conflict("Too many bad attempts. Try later.")); } await loginHistoryService.AddLoginHistory(userId, true); return(Ok(authResponse)); } } }
public IHttpActionResult AddLoginHistory([FromBody] LoginHistoryDTO loginHistoryDTO) { if (loginHistoryDTO == null) { return(BadRequest()); } var results = _loginHistoryService.AddLoginHistory(loginHistoryDTO); return(Ok(results)); }