Esempio n. 1
0
function getAllValidUsers()
{
    if (!$GLOBALS["usersByName"]) {
        $byEmail = $byName = array();
        foreach (getSQLusers(True) as $uid => $row) {
            $byEmail[$row["email"]] = array("gecos" => $row["gecos"], "uid" => $uid);
        }
        foreach (getLocalUsers(True) as $uid => $row) {
            $byEmail[$row["email"]] = array("gecos" => $row["gecos"], "uid" => $uid);
        }
        foreach ($byEmail as $id => $row) {
            $login = eregi_replace("@.*", "", $id);
            if (eregi("@nordita", $id) && posix_getpwnam($login)) {
                $id = $login;
            }
            $byName[$row["gecos"]] = array("uid" => $row["uid"], "username" => $id);
        }
        ksort($byName);
        $GLOBALS["usersByName"] = $byName;
    }
    return $GLOBALS["usersByName"];
}
Esempio n. 2
0
function add_SQLuser()
{
    global $t, $links, $tabs, $dbClass, $authClass;
    if (!$_REQUEST["t"]) {
        $_REQUEST["t"] = "event";
    }
    $accE = $_REQUEST["t"] == "event";
    $error = array();
    if ($_REQUEST["button"]) {
        $users = getSQLusers();
        if ($v = $_REQUEST["full_name"]) {
            foreach ($users as $k => $u) {
                if (strToLower($u["gecos"]) == strToLower($v)) {
                    $error[] = x("li", "'{$v}' is already known as '{$u['email']}'");
                }
            }
            if ($accE && !eregi("20[0-9][0-9]\$", $v)) {
                $error[] = x("li", "'event title' must have the year at the end");
            }
        }
        if ($v = strToLower($_REQUEST["username"])) {
            foreach ($users as $k => $u) {
                if (strToLower($u["email"]) == strToLower($v)) {
                    $error[] = x("li", "'{$v}' is already known as '{$u['gecos']}'");
                }
            }
            if ($accE && !eregi("^[a-z0-9]*\$", $v)) {
                $error[] = x("li", "'{$v}' is not a valid login name");
            }
            if (!$accE && !eregi("@", $v)) {
                $error[] = x("li", "'{$v}' is not a valid e-mail address");
            }
        }
    }
    if ($error || !$_REQUEST["username"] || !$_REQUEST["full_name"]) {
        /*
         * (re)send the form
         */
        $tt = new table("cellpadding='10'", "<center>" . x("h3", "Adding new external user"));
        $tt->tr("", "valign='top' colspan='3'", x("i", "The external user account is associated either with a <ul>" . "<li> a person (identified by his e-mail and password) or</li>" . "<li> a Nordita event (program, conference, etc.)</li></ul>"));
        $tt->tro();
        $tt->td($accE ? "Both the <b>event title</b> and <b>login name</b><br>must end by the 4-digits Year." . "<br><br><b>contact e-mail</b> is a comma-separated list<br>of the organizer e-mails" : "");
        $tt->tdo("valign='top'");
        $t = new table("", "<form action='" . $links[$tabs->active] . "' method='post'>");
        if ($error) {
            str(False, "errors detected:" . x("ul", join("\n", $error)), "colspan='3' class='registered'");
        }
        $r = "input type ='radio' name='t' onchange='submit()'";
        str("account type", "<{$r} value='human' " . ($accE ? "" : "checked") . ">personal account <{$r} value='event' " . ($accE ? "checked" : "") . ">event account");
        str($accE ? "event title" : "full name", "<input type='text' name='full_name' value='{$_REQUEST['full_name']}' size='35'>");
        str($accE ? "login name" : "e-mail", "<input type='text' name='username'  value='{$_REQUEST['username']}'  size='35'>");
        if ($accE) {
            str("proposed password", "<input type='password' name='pwd'  value='{$_REQUEST['pwd']}'  size='35'>");
        }
        if ($accE) {
            str("confirm password", "<input type='password' name='pwd2' value='{$_REQUEST['pwd2']}' size='35'>");
        }
        if ($accE) {
            str("contact e-mail(s)", "<input type='text' name='contact' value='{$_REQUEST['contact']}'  size='35'>");
        }
        str(" ", "<input type='submit' name='button' value='submit'> <input type='submit' name='button' value='cancel'>");
        $t->close("</form>");
        $tt->tdc();
        $tt->trc();
        $tt->close("</center>");
    } else {
        /*
         * the form is ok. Create the account, send info mail
         */
        $users = getSQLusers();
        $uid = -1000;
        while ($users[$uid]) {
            --$uid;
        }
        if (!$_REQUEST["pwd"]) {
            $_REQUEST["pwd"] = $authClass->random_password(8);
        }
        $dbClass->query("INSERT INTO accounts (id,username,password,new_password,full_name,status,superviser) " . "VALUES ('{$uid}','{$_REQUEST['username']}','{$_REQUEST['pwd']}','{$_REQUEST['pwd']}','{$_REQUEST['full_name']}',1,'{$_REQUEST['contact']}')");
        logIt("newuser", $_REQUEST["username"], $_REQUEST["full_name"]);
        print x("h3", "New user for the Preprints Database");
        $t = new table();
        #   $t->tr("","",$uid,"uid:");
        $t->tr("", "", $_REQUEST["full_name"], "name:");
        $t->tr("", "", $_REQUEST["username"], x("b", "login name:"));
        if ($_REQUEST["contact"]) {
            $t->tr("", "", $_REQUEST["contact"], x("b", "contact e-mail:"));
        } else {
            $t->tr("", "colspan='2'", x("i", "The password is sent to " . $_REQUEST["username"]));
        }
        $t->close();
        mail2newUser($_REQUEST["username"]);
    }
}