public bool TrySignIn( string email, string password, out AccessToken token) { if (email == null) { throw new ArgumentNullException(nameof(email)); } if (password == null) { throw new ArgumentNullException(nameof(password)); } User user = _usersRepository.GetByEmail(email); if (user == null || !user.IsPasswordValid(password)) { token = null; return(false); } token = new AccessToken { ValidUntilValue = GetExprirationTime().UtcDateTime, Token = Guid.NewGuid().ToString(), UserId = user.Id, }; _accessTokenRepository.Insert(token); _accessTokenRepository.SaveChanges(); return(true); }
public List <SystemTaskResult> Execute() { List <SystemTaskResult> results = new List <SystemTaskResult>(); try { _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, "Deleting access tokens")); var accessTokens = _accessTokensRepository.RemoveAllExpired(); _accessTokensRepository.SaveChanges(); _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForInformationMessage(0, 0, $"Deleted {accessTokens.Count()} access tokens")); } catch (Exception exception) { results.Add(new SystemTaskResult(SystemTaskResult.ResultTypes.Error, Id, $"Error deleting access tokens: {exception.Message}")); } return(results); }