コード例 #1
0
ファイル: URLBuilder.php プロジェクト: dru-id/druid-php-sdk
 /**
  * This method is commonly used for promotions or sweepstakes: if a
  * user wants to participate in a promotion, the web client must
  * ensure that the user is logged and have all the fields filled
  * in order to let him participate.
  *
  * - If it is not logged, will return the login URL.
  * - If it is logged the method will check
  *     - If the user have not enough PII to access to a section,
  *       returns the URL needed to force a consumer to fill all the
  *       PII needed to enter into a section
  *     - Else will return false (user logged and completed)
  *
  * The "scope" (section) is a group of fields configured in Genetsis ID for
  * a web client.
  *
  * A section can be also defined as a "part" (section) of the website
  * (web client) that only can be accesed by a user who have filled a
  * set of personal information configured in Genetsis ID (all of the fields
  * required for that section).
  *
  * @param string Section-key Identifier of the web client. The
  *     section-key is located in "oauthconf.xml" file.
  * @return string With generated URL. If the user is not connected,
  *     will return login URL.
  * @throws Exception if scope is empty.
  */
 public static function buildSignupPromotionUrl($scope)
 {
     try {
         if (self::checkParam($scope)) {
             throw new \Exception('Scope section is empty');
         }
         if (!Identity::isConnected()) {
             return sefl::getUrlLogin($scope);
         } else {
             if (!Identity::checkUserComplete($scope)) {
                 return self::getUrlCompleteAccount($scope);
             }
         }
         return false;
     } catch (\Exception $e) {
         Identity::getLogger()->debug('Error [' . __FUNCTION__ . '] - ' . $e->getMessage());
     }
 }
コード例 #2
0
ファイル: index.php プロジェクト: dru-id/druid-php-skel
<a href="http://developers.dru-id.com/" style="max-height: 88px;" target="_blank">
    <img width="300" height="100" alt="DRUID Developers" src="/assets/img/Druid_logo_solo.png" style="max-height: 88px;">
</a>

<h1>Welcome to DRUID</h1>
<h2>Se how easy is integrate DRUID with your applications using the php SDK</h2>

<h3>(you have more examples available at <a href="http://developers.dru-id.com/sdks/php-sdk/sdk-code-examples/">http://developers.dru-id.com/sdks/php-sdk/sdk-code-examples/</a>)</h3>

<h4>This page demostrates how to create login and registration links for not connected users, and show logout link and retrieve user email when user is connected:</h4>


<p style="background-color:#e5ffff; border: thin solid #99ffff; padding: 20px">
<?php 
try {
    if (!Identity::isConnected()) {
        echo "<a href=" . URLBuilder::getUrlLogin() . ">Login</a> ";
        echo "<a href=" . URLBuilder::getUrlRegister() . ">Register</a>";
    } else {
        $info = UserApi::getUserLogged();
        $picture = UserApi::getUserLoggedAvatarUrl();
        echo "<img src='{$picture}' onerror='this.src=/assets/img/placeholder.png' width='32'/>";
        echo " Welcome " . $info->user->user_ids->email->value;
        echo "<br/><br/>";
        echo "<a href=\"opi.php\">Fill Opi</a>";
        echo "<br/><br/>";
        echo "<a href=\"/actions/logout\">Logout</a>";
    }
} catch (Exception $e) {
    echo $e->getMessage() . "\n" . $e->getTraceAsString();
}
コード例 #3
0
ファイル: callback.php プロジェクト: dru-id/druid-php-skel
 * Please write similar code using your mvc framework (if you are using any) and implement your on logic
 */
require __DIR__ . "/../../lib/vendor/autoload.php";
use Genetsis\Identity;
try {
    Identity::init();
} catch (Exception $e) {
    echo $e->getMessage() . "\n" . $e->getTraceAsString();
    die;
}
$error = $_GET['error'];
$uid = $_GET['uid'];
$gohome = true;
if (!$error) {
    $code = $_GET['code'];
    if (!Identity::isConnected() && (isset($code) || trim($code) != '')) {
        Identity::authorizeUser($code);
    }
} else {
    if ('user_cancel' != $error) {
        $error_description = $_GET['error_description'];
        echo $error . " -> " . $error_description;
        $gohome = false;
    }
}
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/myactions/callback.php')) {
    include $_SERVER['DOCUMENT_ROOT'] . '/myactions/callback.php';
}
if ($gohome) {
    // redirect to home as example
    header("Location: /");