| | |
| | | <?php |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\base\Site; |
| | | use JetBrains\PhpStorm\NoReturn;use JVBase\base\Site; |
| | | use JVBase\forms\TaxonomySelector; |
| | | use JVBase\Instance;use JVBase\integrations\services\Cloudflare;use JVBase\meta\Form; |
| | | |
| | |
| | | $this->routes = new LoginRoutes(); |
| | | // $this->cache = Cache::for('login'); |
| | | // $this->cache->flush(); |
| | | // Initialize magic link support if enabled |
| | | if (Site::has('magic_link')) { |
| | | $this->initMagicLinkSupport(); |
| | | } |
| | | |
| | | // Create login page if it doesn't exist |
| | | $this->ensureLoginPageExists(); |
| | |
| | | $config = $registrar->getConfig('register'); |
| | | $icon = $registrar->getIcon('user'); |
| | | $icon = ($icon !== '') ? jvbIcon($icon) : ''; |
| | | $select[$role] = '<span class="label">'.$icon.$registrar->getSingular().'</span><span class="text">'.$config['description']??Site::login()->getDescription('register')??''.'</span>'; |
| | | $desc = $config['description']??Site::login()->getDescription('register')??''; |
| | | $select[$role] = '<span class="label">'.$icon.$registrar->getSingular().'</span><span class="text">'.$desc.'</span>'; |
| | | if (!empty($config['fields'])){ |
| | | foreach ($config['fields'] as $field) { |
| | | $field['condition'] = [ |
| | |
| | | return $self->isLoginPage(); |
| | | } |
| | | |
| | | protected function initMagicLinkSupport(): void |
| | | { |
| | | if (!Site::has('magic_link')) { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | /********************************************************************* |
| | | RENDERING |
| | | *********************************************************************/ |
| | |
| | | protected function getAction():string |
| | | { |
| | | if (array_key_exists('action', $_GET)) { |
| | | switch ($_GET['action']){ |
| | | case 'lostpassword': |
| | | case 'retrievepassword': // Alias |
| | | $action = 'lostpassword'; |
| | | break; |
| | | case 'rp': |
| | | case 'resetpass': |
| | | $action = 'resetpass'; |
| | | break; |
| | | default: |
| | | $action = $_GET['action']; |
| | | } |
| | | $action=match($_GET['action']){'lostpassword','retrievepassword'=>'lostpassword','rp','resetpass'=>'resetpass',default=>$_GET['action'],}; |
| | | } else { |
| | | $action = 'login'; |
| | | } |
| | |
| | | |
| | | protected function setupTitle():void |
| | | { |
| | | switch ($this->action) { |
| | | case 'lostpassword': |
| | | $title = 'Lost Your Password?'; |
| | | break; |
| | | case 'resetpass': |
| | | $title = 'Reset Your Password'; |
| | | break; |
| | | case 'register': |
| | | $title = 'Create Your Account'; |
| | | break; |
| | | default: |
| | | $title = 'Log In To Your Account'; |
| | | } |
| | | $title=match($this->action){'lostpassword'=>'Lost Your Password?','resetpass'=>'Reset Your Password','register'=>'Create Your Account',default=>'Log In To Your Account',}; |
| | | $this->title = $title; |
| | | } |
| | | |
| | |
| | | |
| | | protected function getDefaultLabels(): array |
| | | { |
| | | switch ($this->action) { |
| | | case 'register': |
| | | return Site::login()->getLabels('register'); |
| | | case 'lostpassword': |
| | | return Site::login()->getLabels('lostPassword'); |
| | | case 'resetpass': |
| | | case 'rp': |
| | | return Site::login()->getLabels('resetPassword'); |
| | | case 'logout': |
| | | return Site::login()->getLabels('logout'); |
| | | case 'magic': |
| | | return Site::login()->getLabels('magic'); |
| | | case 'login': |
| | | default: |
| | | return Site::login()->getLabels('login'); |
| | | } |
| | | return match($this->action){'register'=>Site::login()->getLabels('register'),'lostpassword'=>Site::login()->getLabels('lostPassword'),'resetpass','rp'=>Site::login()->getLabels('resetPassword'),'logout'=>Site::login()->getLabels('logout'),'magic'=>Site::login()->getLabels('magic'),default=>Site::login()->getLabels('login'),}; |
| | | } |
| | | |
| | | protected function maybeMagicLink(): void |
| | |
| | | /** |
| | | * Handle login errors |
| | | */ |
| | | protected function handleLoginError(WP_Error $error): void |
| | | #[NoReturn]protected function handleLoginError(WP_Error $error): void |
| | | { |
| | | $login_url = wp_login_url(); |
| | | $login_url = add_query_arg('login_error', urlencode($error->get_error_code()), $login_url); |