Example #1
0
 public function doLogout()
 {
     $options = new ezcAuthenticationSessionOptions();
     $options->validity = 86400;
     $session = new ezcAuthenticationSession($options);
     $session->start();
     $session->destroy();
     $res = new ezcMvcResult();
     $res->status = new ezcMvcExternalRedirect('/');
     return $res;
 }
Example #2
0
 private function runAuthRequiredFilter($request)
 {
     $database = new ezcAuthenticationDatabaseInfo(ezcDbInstance::get(), 'user', array('id', 'password'));
     $databaseFilter = new ezcAuthenticationDatabaseFilter($database);
     // use the options object when creating a new Session object
     $options = new ezcAuthenticationSessionOptions();
     $options->validity = 86400;
     $session = new ezcAuthenticationSession($options);
     $session->start();
     $user = $session->load();
     $password = null;
     $loginWithForm = true;
     $credentials = new ezcAuthenticationPasswordCredentials($user, md5($password));
     $authentication = new ezcAuthentication($credentials);
     $authentication->session = $session;
     $authentication->addFilter($databaseFilter);
     if (!$authentication->run()) {
         $status = $authentication->getStatus();
         $request->variables['redirUrl'] = $request->uri;
         $request->variables['reasons'] = $status;
         $request->uri = '/login-required';
         debugLogger::log(var_export($status, true), ezcLog::DEBUG, array("source" => __METHOD__));
         return new ezcMvcInternalRedirect($request);
     }
     if (isset($_SESSION['ezcAuth_id'])) {
         /*
         $q = ezcDbInstance::get()->createSelectQuery();
         $q->select( '*' )
           ->from( 'user' )
           ->leftJoin( 'user_pref', 'user.id', 'user_pref.user_id' )
           ->where( $q->expr->eq( 'id', $q->bindValue( $_SESSION['ezcAuth_id'] ) ) );
         $s = $q->prepare();
         $s->execute();
         $r = $s->fetchAll();
         
         $userName = $r[0]['fullname'];
         */
         $q = ezcDbInstance::get()->createSelectQuery();
         $q->select('*')->from('user')->where($q->expr->eq('id', $q->bindValue($_SESSION['ezcAuth_id'])));
         $s = $q->prepare();
         $s->execute();
         $r = $s->fetchAll();
         $userName = $r[0]['fullname'];
         date_default_timezone_set($r[0]['timezone']);
     }
     $request->variables['user'] = $userName;
 }
<?php

require_once 'tutorial_autoload.php';
// no headers should be sent before calling $session->start()
$options = new ezcAuthenticationSessionOptions();
$session = new ezcAuthenticationSession($options);
$session->start();
// URL after returning from OpenID authentication
$url = isset($_GET['openid_identity']) ? $_GET['openid_identity'] : $session->load();
if ($url === null) {
    // URL at the start of authentication
    $url = isset($_GET['openid_identifier']) ? $_GET['openid_identifier'] : $session->load();
}
$action = isset($_GET['action']) ? strtolower($_GET['action']) : null;
$credentials = new ezcAuthenticationIdCredentials($url);
$authentication = new ezcAuthentication($credentials);
$authentication->session = $session;
if ($action === 'logout') {
    $session->destroy();
} else {
    $options = new ezcAuthenticationOpenidOptions();
    $options->mode = ezcAuthenticationOpenidFilter::MODE_SMART;
    $options->openidVersion = ezcAuthenticationOpenidFilter::VERSION_2_0;
    $options->store = new ezcAuthenticationOpenidFileStore('/tmp/store');
    $filter = new ezcAuthenticationOpenidFilter($options);
    $filter->registerFetchData(array('fullname', 'gender', 'country', 'language'));
    $authentication->addFilter($filter);
}
if (!$authentication->run()) {
    // authentication did not succeed, so inform the user
    $status = $authentication->getStatus();
Example #4
0
 /**
  * Method to be called from the controller's logout action to log a user out.
  *
  * @param ezcMvcRequest $request
  */
 public function logout(ezcMvcRequest $request)
 {
     $options = new ezcAuthenticationSessionOptions();
     $options->validity = 86400;
     $session = new ezcAuthenticationSession($options);
     $session->start();
     unset($_SESSION[$this->options->sessionUserIdKey]);
     $session->destroy();
 }