Lockout.a.User.Account.mp4
{
opt.Lockout.AllowedForNewUsers = true;
opt.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
opt.Lockout.MaxFailedAccessAttempts = 3;
})
public async Task<LoginServiceResponseDto> Login(Login login)
{
var user = await _userManager.FindByEmailAsync(login.Email);
if (user is null)
throw new UnauthorizedAccessException("Email or Password is incorrect!");
if (await _userManager.IsLockedOutAsync(user))
{
throw new UnauthorizedAccessException("Your account is locked. Please try again after 15 min.");
}
var result = await _userManager.CheckPasswordAsync(user, login.Password);
if (!result)
{
await _userManager.AccessFailedAsync(user);
throw new UnauthorizedAccessException("Email or Password is incorrect!");
}
await _userManager.ResetAccessFailedCountAsync(user);
var jwtSecurityToken = await _tokenService.CreateJwtToken(user);
var userInfo = new UserInfoResult
{
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Id = user.Id,
UserName = user.UserName
};
return new LoginServiceResponseDto
{
Token = new JwtSecurityTokenHandler().WriteToken(jwtSecurityToken),
UserInfo = userInfo
};
}