public async Task <bool> Login(Login login) { if (login.LoginMethod == LoginMethod.ACCOUNT) { var signInResult = await _signInManager.PasswordSignInAsync(login.Username, login.Password, true, false); if (signInResult.Succeeded) { _logger.LogInformation($"User {login.Username} logged in at {DateTime.UtcNow} UTC Time"); } else { _logger.LogWarning($"User {login.Username} failed a login attempt."); } return(signInResult.Succeeded); } var user = await _db.Users.SingleOrDefaultAsync(u => u.EmailConfirmed && (u.NormalizedUserName == login.Username.ToUpper() || u.NormalizedEmail == login.Username.ToUpper())); if (user == null) { return(false); } user.EmailVerificationCode = Guid.NewGuid(); user.EmailVerificationCreated = DateTime.Now; await _db.SaveChangesAsync(); await _emailService.SendEmail(user.Email, "BadMelon: Login link requested", $@"Hello {user.UserName}, You can login with the following URL for the next 10 minutes. http://localhost:9000/api/auth/code/{user.EmailVerificationCode} If you did not request this, someone is trying to hack you. Thanks, Bad Melon "); return(true); }
public async Task AddMany(ICollection <T> models) { await _db.Set <T>().AddRangeAsync(models); await _db.SaveChangesAsync(); }