authenticator() public static method

public static authenticator ( ) : Gdn_Auth
return Gdn_Auth
Example #1
0
 public function startAuthenticator()
 {
     if (!c('Garden.Installed', false)) {
         return;
     }
     // Start the 'session'
     Gdn::session()->start(false, false);
     // Get list of enabled authenticators
     $AuthenticationSchemes = Gdn::config('Garden.Authenticator.EnabledSchemes', array());
     // Bring all enabled authenticator classes into the defined scope to allow them to be picked up by the plugin manager
     foreach ($AuthenticationSchemes as $AuthenticationSchemeAlias) {
         $Registered = $this->registerAuthenticator($AuthenticationSchemeAlias);
     }
     $this->_Started = true;
     $this->wakeUpAuthenticators();
     if (Gdn::session()->isValid() && !Gdn::session()->checkPermission('Garden.SignIn.Allow')) {
         return Gdn::authenticator()->authenticateWith('user')->deauthenticate();
     }
 }
 /**
  * Does actual de-authentication of a user. Used by SignOut().
  *
  * @access public
  * @since 2.0.0
  *
  * @param string $AuthenticationSchemeAlias
  * @param string $TransientKey Unique value to prove intent.
  */
 public function leave($AuthenticationSchemeAlias = 'default', $TransientKey = '')
 {
     deprecated(__FUNCTION__);
     $this->EventArguments['AuthenticationSchemeAlias'] = $AuthenticationSchemeAlias;
     $this->fireEvent('BeforeLeave');
     // Allow hijacking deauth type
     $AuthenticationSchemeAlias = $this->EventArguments['AuthenticationSchemeAlias'];
     try {
         $Authenticator = Gdn::authenticator()->authenticateWith($AuthenticationSchemeAlias);
     } catch (Exception $e) {
         $Authenticator = Gdn::authenticator()->authenticateWith('default');
     }
     // Only sign the user out if this is an authenticated postback! Start off pessimistic
     $this->Leaving = false;
     $Result = Gdn_Authenticator::REACT_RENDER;
     // Build these before doing anything desctructive as they are supposed to have user context
     $LogoutResponse = $Authenticator->logoutResponse();
     $LoginResponse = $Authenticator->loginResponse();
     $AuthenticatedPostbackRequired = $Authenticator->requireLogoutTransientKey();
     if (!$AuthenticatedPostbackRequired || Gdn::session()->validateTransientKey($TransientKey)) {
         $Result = $Authenticator->deauthenticate();
         $this->Leaving = true;
     }
     if ($Result == Gdn_Authenticator::AUTH_SUCCESS) {
         $this->View = 'leave';
         $Reaction = $LogoutResponse;
     } else {
         $this->View = 'auth/' . $Authenticator->getAuthenticationSchemeAlias();
         $Reaction = $LoginResponse;
     }
     switch ($Reaction) {
         case Gdn_Authenticator::REACT_RENDER:
             break;
         case Gdn_Authenticator::REACT_EXIT:
             exit;
             break;
         case Gdn_Authenticator::REACT_REMOTE:
             // Render the view, but set the delivery type to VIEW
             $this->_DeliveryType = DELIVERY_TYPE_VIEW;
             break;
         case Gdn_Authenticator::REACT_REDIRECT:
         default:
             // If we're just told to redirect, but not where... try to figure out somewhere that makes sense.
             if ($Reaction == Gdn_Authenticator::REACT_REDIRECT) {
                 $Route = '/';
                 $Target = $this->target();
                 if (!is_null($Target)) {
                     $Route = $Target;
                 }
             } else {
                 $Route = $Reaction;
             }
             if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
                 $this->RedirectUrl = url($Route);
             } else {
                 if ($Route !== false) {
                     redirect($Route);
                 } else {
                     redirect(Gdn::router()->getDestination('DefaultController'));
                 }
             }
             break;
     }
     $this->render();
 }
Example #3
0
Gdn::themeManager()->start();
// Plugins startup
Gdn::pluginManager()->start();
/**
 * Locales
 *
 * Install any custom locales provided by applications and plugins, and set up
 * the locale management system.
 */
// Load the Garden locale system
$gdnLocale = new Gdn_Locale(c('Garden.Locale', 'en'), Gdn::addonManager());
Gdn::factoryInstall(Gdn::AliasLocale, 'Gdn_Locale', null, Gdn::FactorySingleton, $gdnLocale);
unset($gdnLocale);
require_once PATH_LIBRARY_CORE . '/functions.validation.php';
// Start Authenticators
Gdn::authenticator()->startAuthenticator();
/**
 * Bootstrap After
 *
 * After the bootstrap has finished loading, this hook allows developers a last
 * chance to customize Garden's runtime environment before the actual request
 * is handled.
 */
if (file_exists(PATH_ROOT . '/conf/bootstrap.after.php')) {
    require_once PATH_ROOT . '/conf/bootstrap.after.php';
}
// Include "Render" functions now - this way pluggables and custom confs can override them.
require_once PATH_LIBRARY_CORE . '/functions.render.php';
if (!defined('CLIENT_NAME')) {
    define('CLIENT_NAME', 'vanilla');
}
Example #4
0
 /**
  * Returns the transient key for the authenticated user.
  *
  * @return string
  */
 public function transientKey($NewKey = null)
 {
     if (!is_null($NewKey)) {
         $this->_TransientKey = Gdn::authenticator()->getUserModel()->setTransientKey($this->UserID, $NewKey);
     }
     //      if ($this->_TransientKey)
     return $this->_TransientKey;
     //      else
     //         return RandomString(12); // Postbacks will never be authenticated if transientkey is not defined.
 }
 /**
  *
  *
  * @param $UserID
  * @param bool $Persist
  */
 public function setIdentity($UserID, $Persist = true)
 {
     $AuthenticationSchemeAlias = $this->getAuthenticationSchemeAlias();
     Gdn::authenticator()->setIdentity($UserID, $Persist);
     Gdn::session()->start();
     if ($UserID > 0) {
         Gdn::session()->setPreference('Authenticator', $AuthenticationSchemeAlias);
     } else {
         Gdn::session()->setPreference('Authenticator', '');
     }
 }
    function writeEmbedCommentForm()
    {
        $Session = Gdn::session();
        $Controller = Gdn::controller();
        $Discussion = $Controller->data('Discussion');
        if ($Discussion && $Discussion->Closed == '1') {
            ?>
            <div class="Foot Closed">
                <div class="Note Closed"><?php 
            echo t('This discussion has been closed.');
            ?>
</div>
            </div>
        <?php 
        } else {
            ?>
            <h2><?php 
            echo t('Leave a comment');
            ?>
</h2>
            <div class="MessageForm CommentForm EmbedCommentForm">
                <?php 
            echo $Controller->Form->open(array('id' => 'Form_Comment'));
            echo $Controller->Form->errors();
            echo $Controller->Form->Hidden('Name');
            echo wrap($Controller->Form->textBox('Body', array('MultiLine' => TRUE)), 'div', array('class' => 'TextBoxWrapper'));
            echo "<div class=\"Buttons\">\n";
            $AllowSigninPopup = c('Garden.SignIn.Popup');
            $Attributes = array('tabindex' => '-1', 'target' => '_top');
            // If we aren't ajaxing this call then we need to target the url of the parent frame.
            $ReturnUrl = $Controller->data('ForeignSource.vanilla_url', Gdn::request()->PathAndQuery());
            if ($Session->isValid()) {
                $AuthenticationUrl = Gdn::authenticator()->SignOutUrl($ReturnUrl);
                echo wrap(sprintf(t('Commenting as %1$s (%2$s)', 'Commenting as %1$s <span class="SignOutWrap">(%2$s)</span>'), Gdn_Format::text($Session->User->Name), anchor(t('Sign Out'), $AuthenticationUrl, 'SignOut', $Attributes)), 'div', array('class' => 'Author'));
                echo $Controller->Form->button('Post Comment', array('class' => 'Button CommentButton'));
            } else {
                $AuthenticationUrl = url(SignInUrl($ReturnUrl), true);
                if ($AllowSigninPopup) {
                    $CssClass = 'SignInPopup Button Stash';
                } else {
                    $CssClass = 'Button Stash';
                }
                echo anchor(t('Comment As ...'), $AuthenticationUrl, $CssClass, $Attributes);
            }
            echo "</div>\n";
            echo $Controller->Form->close();
            ?>
            </div>
        <?php 
        }
    }
 /**
  * Configure authentication method.
  *
  * @since 2.0.3
  * @access public
  *
  * @param string $AuthenticationSchemeAlias
  */
 public function configure($AuthenticationSchemeAlias = null)
 {
     $Message = t("Please choose an authenticator to configure.");
     if (!is_null($AuthenticationSchemeAlias)) {
         $AuthenticatorInfo = Gdn::authenticator()->getAuthenticatorInfo($AuthenticationSchemeAlias);
         if ($AuthenticatorInfo !== false) {
             $this->AuthenticatorChoice = $AuthenticationSchemeAlias;
             if (array_key_exists($AuthenticationSchemeAlias, $this->ConfigureList) && $this->ConfigureList[$AuthenticationSchemeAlias] !== false) {
                 echo Gdn::slice($this->ConfigureList[$AuthenticationSchemeAlias]);
                 return;
             } else {
                 $Message = sprintf(t("The %s Authenticator does not have any custom configuration options."), $AuthenticatorInfo['Name']);
             }
         }
     }
     $this->setData('ConfigureMessage', $Message);
     $this->render();
 }