/** * get url redirect to a specified opi */ public static function get($opi = false, $redirect_url = false) { if (!$opi) { $opi = OAuthConfig::getOpi(); } if (!$opi) { throw new Exception("You must pass OPI as param, or define it in <data> part of oauthconf.xml"); } $params = array("id" => urlencode(UserApi::getUserLoggedOid()), "sc" => urlencode(OAuthConfig::getBrand()), "carry_url" => urlencode($redirect_url)); $info = UserApi::getUserLogged(); $opi_age = false; $opi_gender = false; try { $birthday = isset($info->user->user_data->birthday) ? $info->user->user_data->birthday->value : null; if ($birthday != null) { $birthday = explode("/", $birthday); $age = date("md", date("U", mktime(0, 0, 0, $birthday[2], $birthday[1], $birthday[0]))) > date("md") ? date("Y") - $birthday[2] - 1 : date("Y") - $birthday[2]; if (18 <= $age && $age <= 24) { $opi_age = 1; } else { if (25 <= $age && $age <= 34) { $opi_age = 2; } } if (35 <= $age && $age <= 44) { $opi_age = 3; } if (45 <= $age && $age <= 64) { $opi_age = 4; } } } catch (Exception $e) { } try { $gender = isset($info->user->user_data->gender) ? $info->user->user_data->gender->vid : null; if ($gender == 1) { $opi_gender = 2; } else { if ($gender == 2) { $opi_gender = 1; } } } catch (Exception $e) { } if ($opi_age) { $params["carry_edad"] = $opi_age; } if ($opi_gender) { $params["carry_sexo"] = $opi_gender; } $query = array(); foreach ($params as $param => $value) { $query[] = "{$param}={$value}"; } return OAuthConfig::getApiUrl('opi', 'base_url') . OAuthConfig::getApiUrl('opi', 'rules') . "/" . $opi . "?" . implode('&', $query); }
/** * Performs the logout process. * * It makes: * - The logout call to Genetsis ID * - Clear cookies * - Purge Tokens and local data for the logged user * * @return void * @throws Exception */ public static function logoutUser() { try { if (self::$gid_things->getAccessToken() != null && self::$gid_things->getRefreshToken() != null) { self::$logger->info('User Single Sign Logout'); UserApi::deleteCacheUser(self::$gid_things->getLoginStatus()->getCkUsid()); OAuth::doLogout(OauthConfig::getEndpointUrl('logout_endpoint')); self::clearLocalSessionData(); } } catch (Exception $e) { self::$logger->error($e->getMessage()); } }
<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(); } ?> </p> <h4>The code:</h4> <script src="https://gist.github.com/saspelo/3eba49c3be6e84cf4e9a.js"></script>
<?php require __DIR__ . "/../lib/vendor/autoload.php"; use Genetsis\Identity; use Genetsis\URLBuilder; use Genetsis\UserApi; use Genetsis\Opi; try { Identity::init(); if (!Identity::isConnected()) { header("Location: " . URLBuilder::getUrlLogin()); die; } else { Opi::open(false, "examples.dev.dru-id.com") . ">Fill Opi for " . UserApi::getUserLogged()->user->user_ids->email->value . "</a>"; } } catch (Exception $e) { echo $e->getMessage() . "\n" . $e->getTraceAsString(); die; }
/** * Method to get User Logged Profile Image available * * @param int $width (optional) 150px by default * @param int $height (optional) 150px by default * @return String url of profile image */ public static function getUserLoggedAvatarUrl($width = 150, $height = 150) { return self::getAvatarUrl(UserApi::getUserLogged()->user->oid, $width, $height); }