| | |
| | | */ |
| | | class MagicLinkManager |
| | | { |
| | | protected CacheManager $cache; |
| | | protected CacheManager $referral_cache; |
| | | protected Cache $cache; |
| | | protected Cache $referral_cache; |
| | | |
| | | // Token settings |
| | | protected int $token_expiry = 900; // 15 minutes in seconds |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('magic_links', $this->token_expiry); |
| | | $this->referral_cache = CacheManager::for('referral_magic_links', 14 * DAY_IN_SECONDS); |
| | | $this->cache = Cache::for('magic_links', $this->token_expiry); |
| | | $this->referral_cache = Cache::for('referral_magic_links', 14 * DAY_IN_SECONDS); |
| | | |
| | | // Hook into WordPress auth flow |
| | | add_action('template_redirect', [$this, 'handleMagicLinkClick']); |
| | |
| | | // Delete token after verification (single use) |
| | | // Check which cache it's in and delete from the correct one |
| | | if ($token_data['type'] === 'referral') { |
| | | $this->referral_cache->delete($token); |
| | | $this->referral_cache->forget($token); |
| | | } else { |
| | | $this->cache->delete($token); |
| | | $this->cache->forget($token); |
| | | } |
| | | |
| | | return $token_data; |