private void ExpireToken(DomainToken token) { token.IsExpired = true; _iUnitOfWork.SaveChanges(); }
private void SaveToken(Guid guid, string login, string userId, DateTime date) { var token = new DomainToken(guid, login, userId, date); var existingToken = _iUnitOfWork.TokenRepository.GetByCustomerId(userId); if (existingToken != null) { existingToken.Guid = guid; existingToken.GenerationDate = date; existingToken.Login = login; existingToken.UserId = userId; existingToken.IsExpired = false; } else { _iUnitOfWork.TokenRepository.Add(Mapper.Map<Token>(token)); } _iUnitOfWork.SaveChanges(); }
private void CheckTokenValidity(DomainToken token) { var databaseToken = _iUnitOfWork.TokenRepository.GetByGuid(token.Guid); if (databaseToken == null || databaseToken.IsExpired) { throw TokenExpiredException.ThrowTokenExpiredException(); } if (DateTime.UtcNow - databaseToken.GenerationDate <= TimeSpan.FromDays(21)) { return; } ExpireToken(token); throw TokenExpiredException.ThrowTokenExpiredException(); }