Example #1
0
if (!empty($password)) {
    $values = array('user_password_hash' => sha1($password), 'user_authoritative_source' => 'reason');
    reason_update_entity($user_entity->id(), $caller_entity->id(), $values);
    echo 'Updated password for ' . $username . "\n";
}
if (!empty($options['s'])) {
    $site_uname = (string) $options['s'];
    if (!reason_unique_name_exists($site_uname)) {
        echo 'Site ' . $site_uname . ' not found (Bad unique name). Unable to provide access.' . "\n";
    } else {
        $site_id = id_of($site_uname);
        $site_entity = new entity($site_id);
        if ($site_entity->get_value('type') != id_of('site')) {
            echo 'Site ' . $site_uname . ' not found (Unique name does not belong to a site). Unable to provide access.' . "\n";
        } else {
            if ($user->add_user_to_site($username, $site_id)) {
                echo $username . ' now has access to the site ' . $site_uname . "\n";
            } else {
                echo $username . ' already had access to the site ' . $site_uname . "\n";
            }
        }
    }
}
if (!empty($options['r'])) {
    $role_uname = (string) $options['r'];
    if (!reason_unique_name_exists($role_uname)) {
        echo 'Role ' . $role_uname . ' not found (Bad unique name). Unable to assign role.' . "\n";
    } else {
        $role_id = id_of($role_uname);
        $role_entity = new entity($role_id);
        if ($role_entity->get_value('type') != id_of('user_role')) {