public async Task <IActionResult> Authenticate(PasswordAuthModel authModel) { UserTicketModel ticket = await _authenticationService.AuthenticateAsync(authModel); if (ticket.Id == 0) { return(BadRequest()); } return(Ok(ticket)); }
public async Task <UserTicketModel> AuthenticateAsync(PasswordAuthModel authModel) { User user = await _unitOfWork .AuthenticationRepository .GetUserAsync(authModel.UserName); if (user == null) { return(new UserTicketModel { Id = 0 }); } string providedPassword = authModel.Password; string actualPassword = user.Password; if (providedPassword == actualPassword) { _unitOfWork.JournalRepository .AddRegistrationEntryAsync( new RegistrationJournal { UserId = user.Id } ); _unitOfWork.JournalRepository .AddOperationEntryAsync( new OperationJournal { UserId = user.Id, LoginSuccess = true } ); await _unitOfWork.Save(); return(new UserTicketModel { Id = user.Id, UserName = user.UserName }); } _unitOfWork.JournalRepository .AddOperationEntryAsync( new OperationJournal { UserId = user.Id, LoginSuccess = false } ); return(new UserTicketModel { Id = 0 }); }