Back to CMSApplication class

Method checkUserRequireReset

protected void
checkUserRequireReset
(mixed $option, mixed $view, mixed $layout, mixed $tasks)
Check if the user is required to reset their password.
Parameters
  • string $option The option that manage the password reset
  • string $view The view that manage the password reset
  • string $layout The layout of the view that manage the password reset
  • string $tasks Permitted tasks
Returns
  • void
-
  • \Exception

Method checkUserRequireReset - Source code

/**
 * Check if the user is required to reset their password.
 *
 * If the user is required to reset their password will be redirected to the page that manage the password reset.
 *
 * @param   string  $option  The option that manage the password reset
 * @param   string  $view    The view that manage the password reset
 * @param   string  $layout  The layout of the view that manage the password reset
 * @param   string  $tasks   Permitted tasks
 *
 * @return  void
 *
 * @throws  \Exception
 */
protected function checkUserRequireReset($option, $view, $layout, $tasks)
{
    if (Factory::getUser()->get('requireReset', 0)) {
        $redirect = false;
        /*
         * By default user profile edit page is used.
         * That page allows you to change more than just the password and might not be the desired behavior.
         * This allows a developer to override the page that manage the password reset.
         * (can be configured using the file: configuration.php, or if extended, through the global configuration form)
         */
        $name = $this->getName();
        if ($this->get($name . '_reset_password_override', 0)) {
            $option = $this->get($name . '_reset_password_option', '');
            $view = $this->get($name . '_reset_password_view', '');
            $layout = $this->get($name . '_reset_password_layout', '');
            $tasks = $this->get($name . '_reset_password_tasks', '');
        }
        $task = $this->input->getCmd('task', '');
        // Check task or option/view/layout
        if (!empty($task)) {
            $tasks = explode(',', $tasks);
            // Check full task version "option/task"
            if (array_search($this->input->getCmd('option', '') . '/' . $task, $tasks) === false) {
                // Check short task version, must be on the same option of the view
                if ($this->input->getCmd('option', '') !== $option || array_search($task, $tasks) === false) {
                    // Not permitted task
                    $redirect = true;
                }
            }
        } else {
            if ($this->input->getCmd('option', '') !== $option || $this->input->getCmd('view', '') !== $view || $this->input->getCmd('layout', '') !== $layout) {
                // Requested a different option/view/layout
                $redirect = true;
            }
        }
        if ($redirect) {
            // Redirect to the profile edit page
            $this->enqueueMessage(Text::_('JGLOBAL_PASSWORD_RESET_REQUIRED'), 'notice');
            $url = Route::_('index.php?option=' . $option . '&view=' . $view . '&layout=' . $layout, false);
            // In the administrator we need a different URL
            if (strtolower($name) === 'administrator') {
                $user = Factory::getApplication()->getIdentity();
                $url = Route::_('index.php?option=' . $option . '&task=' . $view . '.' . $layout . '&id=' . $user->id, false);
            }
            $this->redirect($url);
        }
    }
}