public async Task <IActionResult> Post([FromBody] DTOModels.User user) { try { if (!ModelState.IsValid) { return(BadRequest(new { message = ServerMessage.NOT_VALID_PARAMETERS })); } string passwordHash = hashGenerator.GetHash(user.Password); var userData = await repository.GetUser(user.Login, passwordHash); if (userData == null) { return(StatusCode(401, new { message = ServerMessage.USER_NOT_AUTHORIZED })); } if (!userData.IsActive) { return(StatusCode(401, new { message = ServerMessage.USER_ACCOUNT_DEACTIVATED })); } var userIdentityClaim = userIdentityProvider.GetIdentity(userData.Login); var jwtToken = jWTProvider.GetToken(userIdentityClaim); return(Ok(new { token = jWTProvider.WriteToken(jwtToken), user = new CRM.DTOModels.User { Login = userData.Login, Name = userData.Name, RoleId = userData.UserRoleId, RoleName = userData.UserRole.Name } })); } catch (Exception ex) { logger.LogError(ex); return(StatusCode((int)HttpStatusCode.InternalServerError, new { message = ServerMessage.INTERNAL_SERVER_ERROR })); } }