예제 #1
0
function save_user($cj, $user_status, $Acct, $allow_modification)
{
    global $Conf, $Me, $Opt, $OK, $newProfile;
    if ($newProfile) {
        $Acct = null;
    }
    // check for missing fields
    UserStatus::normalize_name($cj);
    if ($newProfile && !isset($cj->email)) {
        $user_status->set_error("email", "Email address required.");
        return false;
    }
    // check email
    if ($newProfile || $cj->email != $Acct->email) {
        if ($new_acct = Contact::find_by_email($cj->email)) {
            if ($allow_modification) {
                $cj->id = $new_acct->contactId;
            } else {
                $msg = "Email address “" . htmlspecialchars($cj->email) . "” is already in use.";
                if ($Me->privChair) {
                    $msg = str_replace("an account", "<a href=\"" . hoturl("profile", "u=" . urlencode($cj->email)) . "\">an account</a>", $msg);
                }
                if (!$newProfile) {
                    $msg .= " You may want to <a href=\"" . hoturl("mergeaccounts") . "\">merge these accounts</a>.";
                }
                return $user_status->set_error("email", $msg);
            }
        } else {
            if (Contact::external_login()) {
                if ($cj->email === "") {
                    return $user_status->set_error("email", "Not a valid username.");
                }
            } else {
                if ($cj->email === "") {
                    return $user_status->set_error("email", "You must supply an email address.");
                } else {
                    if (!validate_email($cj->email)) {
                        return $user_status->set_error("email", "“" . htmlspecialchars($cj->email) . "” is not a valid email address.");
                    }
                }
            }
        }
        if (!$newProfile && !$Me->privChair) {
            $old_preferredEmail = $Acct->preferredEmail;
            $Acct->preferredEmail = $cj->email;
            $capmgr = $Conf->capability_manager();
            $rest = array("capability" => $capmgr->create(CAPTYPE_CHANGEEMAIL, array("user" => $Acct, "timeExpires" => time() + 259200, "data" => json_encode(array("uemail" => $cj->email)))));
            $mailer = new HotCRPMailer($Acct, null, $rest);
            $prep = $mailer->make_preparation("@changeemail", $rest);
            if ($prep->sendable) {
                Mailer::send_preparation($prep);
                $Conf->warnMsg("Mail has been sent to " . htmlspecialchars($cj->email) . ". Use the link it contains to confirm your email change request.");
            } else {
                Conf::msg_error("Mail cannot be sent to " . htmlspecialchars($cj->email) . " at this time. Your email address was unchanged.");
            }
            // Save changes *except* for new email, by restoring old email.
            $cj->email = $Acct->email;
            $Acct->preferredEmail = $old_preferredEmail;
        }
    }
    // save account
    return $user_status->save($cj, $Acct, $Me);
}