public async Task <ActionResult> SignIn(UserSignInModel userView) { User user = await userManager.Users .Include(u => u.LockRecord) .Where(u => u.Email == userView.Email || u.UserName == userView.UserName) .FirstOrDefaultAsync(); if (user != null) { var result = await signInManager.CheckPasswordSignInAsync(user, userView.Password, true); if (result.Succeeded && user.EmailConfirmed) { logger.LogInformation($"Account/SignIn: User {user.Email} successfully signed in"); IList <string> roles = await userManager.GetRolesAsync(user); return(Ok(new { id = user.Id, userName = user.UserName, email = user.Email, accessToken = tokensService.GetAccessToken(user, roles), refreshToken = tokensService.GetRefreshToken(user), roles })); } else if (result.IsLockedOut) { logger.LogInformation($"Account/SignIn: User {user.Email} has been blocked"); return(Unauthorized(new { error = $"Account blocked: {user.ReasonOfLockOut}" })); } else { return(Unauthorized(new { error = "Email is not confirmed" })); } } return(UnprocessableEntity(new { error = "Wrong email or password" })); }