예제 #1
0
파일: auth.php 프로젝트: jeanvoye/utb
 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;
 }
예제 #2
0
파일: config.php 프로젝트: jeanvoye/utb
 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();
<?php

require_once 'tutorial_autoload.php';
// no headers should be sent before calling $session->start()
$options = new ezcAuthenticationSessionOptions();
// setting 60 seconds timeout for session for testing purposes only
$options->validity = 60;
$session = new ezcAuthenticationSession($options);
$session->start();
$identity = $session->load();
$url = isset($_GET['openid_identifier']) ? $_GET['openid_identifier'] : $identity;
$action = isset($_GET['action']) ? strtolower($_GET['action']) : null;
$credentials = new ezcAuthenticationIdCredentials($url);
$authentication = new ezcAuthentication($credentials);
$authentication->session = $session;
if ($action === 'logout') {
    $session->destroy();
}
if (!$authentication->run()) {
    // authentication did not succeed, so inform the user
    ?>

<script language="JavaScript">
    var xmlhttp = false;

    /*@cc_on @*/
    /*@if ( @_jscript_version >= 5 )
    try
    {
        xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
    }
<?php

require_once 'tutorial_autoload.php';
// no headers should be sent before calling $session->start()
$session = new ezcAuthenticationSession();
$session->start();
// $token is used as a key in the session to store the authenticated state between requests
$token = isset($_GET['token']) ? $_GET['token'] : $session->load();
$credentials = new ezcAuthenticationIdCredentials($token);
$authentication = new ezcAuthentication($credentials);
$authentication->session = $session;
$filter = new ezcAuthenticationTypekeyFilter();
$authentication->addFilter($filter);
// add other filters if needed
if (!$authentication->run()) {
    // authentication did not succeed, so inform the user
    $status = $authentication->getStatus();
    $err = array('ezcAuthenticationTypekeyFilter' => array(ezcAuthenticationTypekeyFilter::STATUS_SIGNATURE_INCORRECT => 'Signature returned by TypeKey is incorrect', ezcAuthenticationTypekeyFilter::STATUS_SIGNATURE_EXPIRED => 'The signature returned by TypeKey expired'), 'ezcAuthenticationSession' => array(ezcAuthenticationSession::STATUS_EMPTY => '', ezcAuthenticationSession::STATUS_EXPIRED => 'Session expired'));
    foreach ($status as $line) {
        list($key, $value) = each($line);
        echo $err[$key][$value] . "\n";
    }
    ?>
<form method="GET" action="https://www.typekey.com/t/typekey/login" onsubmit="document.getElementById('_return').value += '?token=' + document.getElementById('t').value;">
TypeKey token: <input type="text" name="t" id="t" />
<input type="hidden" name="_return" id="_return" value="http://localhost/typekey.php" />
<input type="submit" />
</form>
<?php 
} else {
    // authentication succeeded, so allow the user to see his content
예제 #6
0
파일: filter.php 프로젝트: bmdevel/ezc
 /**
  * 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();
 }
<?php

require_once 'tutorial_autoload.php';
// no headers should be sent before calling $session->start()
$session = new ezcAuthenticationSession();
$session->start();
$user = isset($_POST['user']) ? $_POST['user'] : $session->load();
$password = isset($_POST['password']) ? $_POST['password'] : null;
$credentials = new ezcAuthenticationPasswordCredentials($user, $password);
$authentication = new ezcAuthentication($credentials);
$authentication->session = $session;
$authentication->addFilter(new ezcAuthenticationHtpasswdFilter('/etc/htpasswd'));
// add other filters if needed
if (!$authentication->run()) {
    // authentication did not succeed, so inform the user
    $status = $authentication->getStatus();
    $err = array('ezcAuthenticationHtpasswdFilter' => array(ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username', ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'), 'ezcAuthenticationSession' => array(ezcAuthenticationSession::STATUS_EMPTY => '', ezcAuthenticationSession::STATUS_EXPIRED => 'Session expired'));
    foreach ($status as $line) {
        list($key, $value) = each($line);
        echo $err[$key][$value] . "\n";
    }
} else {
    // authentication succeeded, so allow the user to see his content
}
예제 #8
0
<?php

include "../engine/engine.php";
$session = new ezcAuthenticationSession();
$session->start();
$user = isset($_POST['username']) ? $_POST['username'] : $session->load();
$password = isset($_POST['password']) ? $_POST['password'] : null;
$credentials = new ezcAuthenticationPasswordCredentials($user, $password);
$authentication = new ezcAuthentication($credentials);
$authentication->session = $session;
$authentication->addFilter(new ezcAuthenticationHtpasswdFilter($enginePath . '/passwords'));
if (isset($_GET['page']) && $_GET['page'] == "logout") {
    $session->destroy();
    $user = null;
    $password = null;
}
// add other filters if needed
if (!$authentication->run()) {
    $caption = "";
    if ($user != "") {
        // authentication did not succeed, so inform the user
        $status = $authentication->getStatus();
        $err = array('ezcAuthenticationHtpasswdFilter' => array(ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username', ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'), 'ezcAuthenticationSession' => array(ezcAuthenticationSession::STATUS_EMPTY => '', ezcAuthenticationSession::STATUS_EXPIRED => 'Session expired'));
        foreach ($status as $line) {
            list($key, $value) = each($line);
            $caption .= $err[$key][$value] . "<br/>";
        }
    }
    include "_inithtml.php";
    $title = "eDiasporas Atlas &mdash; Admin : Identification";
    include "_head.php";
예제 #9
0
 public function testSessionOptionsGetSet()
 {
     $options = new ezcAuthenticationSessionOptions();
     $filter = new ezcAuthenticationSession();
     $filter->setOptions($options);
     $this->assertEquals($options, $filter->getOptions());
 }