| | |
| | | protected function generateToken(string $email, string $type, array $data = []): string |
| | | { |
| | | $token = wp_generate_password(32, false); |
| | | error_log('Generated Token: '.$token); |
| | | |
| | | $token_data = array_merge([ |
| | | 'email' => $email, |
| | |
| | | if ($type === self::TYPE_REFERRAL) { |
| | | $this->referral_cache->set($token, $token_data); |
| | | } else { |
| | | error_log('Setting to $this->cache'); |
| | | $this->cache->set($token, $token_data); |
| | | } |
| | | |
| | | error_log('Generated token: '.print_r($token_data, true)); |
| | | |
| | | return $token; |
| | | } |
| | | |
| | |
| | | */ |
| | | public function verifyToken(string $token, string $email): array|WP_Error |
| | | { |
| | | error_log('Verifying token: '.$token); |
| | | // Try regular cache first, then referral cache |
| | | $token_data = $this->cache->get($token); |
| | | error_log('Got token data from cache: '.print_r($token_data, true)); |
| | | |
| | | if (!$token_data) { |
| | | $token_data = $this->referral_cache->get($token); |
| | |
| | | if (!isset($_GET['magic_token']) || !isset($_GET['action']) || !isset($_GET['email'])) { |
| | | return; |
| | | } |
| | | |
| | | $action = sanitize_text_field($_GET['action']); |
| | | $token = sanitize_text_field($_GET['magic_token']); |
| | | $email = sanitize_email(rawurldecode($_GET['email'])); |
| | |
| | | |
| | | if (is_wp_error($token_data)) { |
| | | $this->cleanURL(); |
| | | return; |
| | | } |
| | | |
| | | switch ($action) { |
| | |
| | | $user = get_user_by('ID', $token_data['user_id']); |
| | | |
| | | if (!$user) { |
| | | error_log('No user found: '.print_r($user, true)); |
| | | wp_die('Invalid user'); |
| | | } |
| | | |