Esempio n. 1
0
/**
 * Allows users to delete OpenID locations from their account.
 */
require_login();
$messages = array();
$errors = array();
$identity = require_post("identity");
// make sure we aren't deleting our last identity
$q = db()->prepare("SELECT COUNT(*) AS c FROM user_openid_identities WHERE user_id=?");
$q->execute(array(user_id()));
$count = $q->fetch();
// or we have an OAuth2 identity
$q = db()->prepare("SELECT * FROM user_oauth2_identities WHERE user_id=? LIMIT 1");
$q->execute(array(user_id()));
$oauth2 = $q->fetch();
// or we have a password hash
$q = db()->prepare("SELECT * FROM user_passwords WHERE user_id=?");
$q->execute(array(user_id()));
$password_hash = $q->fetch();
if ($count['c'] <= 1 && !$password_hash && !$oauth2) {
    $errors[] = t("Cannot remove that OpenID identity; at least one identity must be defined.");
    set_temporary_messages($messages);
    set_temporary_errors($errors);
    redirect(url_for('user#user_openid'));
}
$user = \Users\User::getInstance(db());
\Users\UserOpenID::removeIdentity(db(), $user, $identity);
$messages[] = t("Removed OpenID identity ':identity'.", array(':identity' => $identity));
set_temporary_messages($messages);
set_temporary_errors($errors);
redirect(url_for('user#user_openid'));
Esempio n. 2
0
            return false;
        }
        throw new Exception("Cannot set temporary messages with no session");
    }
    if ($m === null) {
        unset($_SESSION["temporary_messages"]);
    } else {
        if (!is_array($m)) {
            $m = array($m);
        }
        $_SESSION["temporary_messages"] = $m;
    }
}
$global_temporary_messages = isset($_SESSION["temporary_messages"]) ? $_SESSION["temporary_messages"] : null;
// only lasts a single request
set_temporary_messages(null);
// reset
function get_temporary_messages()
{
    global $global_temporary_messages;
    return $global_temporary_messages === null ? array() : $global_temporary_messages;
}
function set_temporary_errors($m)
{
    if (defined('NO_SESSION')) {
        if ($m === null) {
            // does nothing
            return false;
        }
        throw new Exception("Cannot set temporary errors with no session");
    }