Exemple #1
0
 * Allows users to add additional OAuth2 locations for their account.
 * Issue #266
 */
require_login();
// POST overrides GET
$oauth2 = require_post("oauth2", require_get("oauth2", false));
$messages = array();
$errors = array();
try {
    if ($oauth2) {
        $user = \Users\User::getInstance(db());
        $args = array("oauth2" => $oauth2);
        $url = absolute_url(url_for('oauth2_add', $args));
        $provider = Users\OAuth2Providers::createProvider($oauth2, $url);
        try {
            \Users\UserOAuth2::addIdentity(db(), $user, $provider);
            $messages[] = t("Added OAuth2 identity ':identity' to your account.", array(':identity' => htmlspecialchars($provider->getKey())));
            // redirect
            $destination = url_for('user#user_openid');
            set_temporary_messages($messages);
            set_temporary_errors($errors);
            redirect($destination);
        } catch (\Users\UserSignupException $e) {
            $errors[] = $e->getMessage();
        }
    }
} catch (Exception $e) {
    if (!$e instanceof EscapedException) {
        $e = new EscapedException(htmlspecialchars($e->getMessage()), (int) $e->getCode(), $e);
    }
    $errors[] = $e->getMessage();