public async Task <UserModel> LoginAsync(LoginModel loginModel) { var user = await _userManager.FindByEmailAsync(loginModel.Email); var userModel = new UserModel(); if (user is null) { userModel.Errors.Add(USER_NOT_FOUND_ERROR); return(userModel); } if (!user.IsActive) { userModel.Errors.Add(USER_IS_BLOCKED_ERROR); } if (!user.EmailConfirmed) { userModel.Errors.Add(EMAIL_IS_NOT_CONFIRMED_ERROR); } if (user.IsRemoved) { userModel.Errors.Add(USER_IS_REMOVED_ERROR); } if (userModel.Errors.Any()) { return(userModel); } var result = await _signInManager.PasswordSignInAsync(user, loginModel.Password, false, false); if (!result.Succeeded) { userModel.Errors.Add(INCORRECT_LOGIN_DATA_ERROR); return(userModel); } userModel = _userModelMapper.Map(user); userModel.Roles = await GetRolesAsync(userModel.Email); _jwtProvider.SetToken(userModel); return(userModel); }