/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new UserStatus(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['UserStatus'])) { $model->attributes = $_POST['UserStatus']; if ($model->save()) { Yii::app()->user->setFlash('success', 'Saved successfully'); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
} while ($cdb->more_results()) { Dbl::free($cdb->next_result()); } } // Create initial administrator user. $Admin = Contact::create(array("email" => "chair@_.com", "name" => "Jane Chair", "password" => "testchair")); $Admin->save_roles(Contact::ROLE_ADMIN | Contact::ROLE_CHAIR | Contact::ROLE_PC, $Admin); // Load data. $json = json_decode(file_get_contents("{$ConfSitePATH}/test/db.json")); if (!$json) { die_hard("* test/testdb.json error: " . json_last_error_msg() . "\n"); } foreach ($json->contacts as $c) { $us = new UserStatus(); if (!$us->save($c)) { die_hard("* failed to create user {$c->email}\n"); } } foreach ($json->papers as $p) { $ps = new PaperStatus(null); if (!$ps->save_paper_json($p)) { die_hard("* failed to create paper {$p->title}:\n" . htmlspecialchars_decode(join("\n", $ps->error_html())) . "\n"); } } $assignset = new AssignmentSet($Admin, true); $assignset->parse($json->assignments_1, null, null); $assignset->execute(); class Xassert { public static $n = 0;
function do_tags() { global $Conf, $Me, $papersel; // check tags $tagger = new Tagger($Me); $t1 = array(); $errors = array(); foreach (preg_split('/[\\s,]+/', (string) @$_REQUEST["tag"]) as $t) { if ($t === "") { /* nada */ } else { if (!($t = $tagger->check($t, Tagger::NOPRIVATE))) { $errors[] = $tagger->error_html; } else { if (TagInfo::base($t) === "pc") { $errors[] = "The “pc” user tag is set automatically for all PC members."; } else { $t1[] = $t; } } } } if (count($errors)) { return Conf::msg_error(join("<br>", $errors)); } else { if (!count($t1)) { return $Conf->warnMsg("Nothing to do."); } } // modify database Dbl::qe("lock tables ContactInfo write"); Conf::$no_invalidate_caches = true; $users = array(); if ($_REQUEST["tagtype"] === "s") { // erase existing tags $likes = array(); $removes = array(); foreach ($t1 as $t) { list($tag, $index) = TagInfo::split_index($t); $removes[] = $t; $likes[] = "contactTags like " . Dbl::utf8ci("'% " . sqlq_for_like($tag) . "#%'"); } foreach (Dbl::fetch_first_columns(Dbl::qe("select contactId from ContactInfo where " . join(" or ", $likes))) as $cid) { $users[(int) $cid] = (object) array("id" => (int) $cid, "add_tags" => [], "remove_tags" => $removes); } } // account for request $key = $_REQUEST["tagtype"] === "d" ? "remove_tags" : "add_tags"; foreach ($papersel as $cid) { if (!isset($users[(int) $cid])) { $users[(int) $cid] = (object) array("id" => (int) $cid, "add_tags" => [], "remove_tags" => []); } $users[(int) $cid]->{$key} = array_merge($users[(int) $cid]->{$key}, $t1); } // apply modifications foreach ($users as $cid => $cj) { $us = new UserStatus(array("send_email" => false)); if (!$us->save($cj)) { $errors = array_merge($errors, $us->error_messages()); } } Dbl::qe("unlock tables"); Conf::$no_invalidate_caches = false; $Conf->invalidateCaches(["pc" => true]); // report if (!count($errors)) { $Conf->confirmMsg("Tags saved."); redirectSelf(array("tagact" => null, "tag" => null)); } else { Conf::msg_error(join("<br>", $errors)); } }
function crpmerge($MiniMe) { global $Conf, $Me, $MergeError; if (!$MiniMe->contactId && !$Me->contactId) { return $MergeError = "Neither of those accounts has any data associated with this conference."; } // XXX `act as` merging might be useful? if (strcasecmp($Me->email, $_SESSION["trueuser"]->email)) { return $MergeError = "You can’t merge accounts when acting as a different user."; } // determine old & new users if (@$_REQUEST["prefer"]) { list($old_user, $new_user) = [$Me, $MiniMe]; } else { list($old_user, $new_user) = [$MiniMe, $Me]; } // send mail at start of process HotCRPMailer::send_to($old_user, "@mergeaccount", null, array("cc" => Text::user_email_to($new_user), "other_contact" => $new_user)); // actually merge users or change email if ($old_user->contactId && $new_user->contactId) { crpmerge_database($old_user, $new_user); } else { if ($old_user->contactId) { $user_status = new UserStatus(["send_email" => false]); $user_status->save($user_status->user_to_json($new_user), $old_user); } } // update trueuser if (strcasecmp($_SESSION["trueuser"]->email, $new_user->email)) { $_SESSION["trueuser"] = (object) ["email" => $new_user->email]; } if ($MergeError == "") { $Conf->confirmMsg("Merged account " . htmlspecialchars($old_user->email) . "."); $new_user->log_activity("Merged account {$old_user->email}"); go(hoturl("index")); } else { $new_user->log_activity("Merged account {$old_user->email} with errors"); $MergeError .= $Conf->db_error_html(true); } }
save_password($marina, ' $$2y$10$/URgqlFgQHpfE6mg4NzJhOZbg9Cc2cng58pA4cikzRD9F0qIuygnm', true); save_password($marina, '', false); xassert(user($marina)->check_password("isdevitch")); xassert_eqq(password($marina, true), ' $$2y$10$/URgqlFgQHpfE6mg4NzJhOZbg9Cc2cng58pA4cikzRD9F0qIuygnm'); } // insert someone into the contactdb $result = Dbl::qe(Contact::contactdb(), "insert into ContactInfo set firstName='Te', lastName='Thamrongrattanarit', email='te@_.com', affiliation='Brandeis University', collaborators='Computational Linguistics Magazine', password='******'"); assert(!!$result); Dbl::free($result); xassert(!user("te@_.com")); $u = Contact::contactdb_find_by_email("te@_.com"); xassert(!!$u); xassert_eqq($u->firstName, "Te"); // inserting them should succeed and borrow their data $us = new UserStatus(array("send_email" => false)); $acct = $us->save((object) array("email" => "te@_.com")); xassert(!!$acct); $te = user("te@_.com"); xassert(!!$te); xassert_eqq($te->firstName, "Te"); xassert_eqq($te->lastName, "Thamrongrattanarit"); xassert_eqq($te->affiliation, "Brandeis University"); if (function_exists("password_needs_rehash")) { xassert($te->check_password("isdevitch")); } xassert_eqq($te->collaborators, "Computational Linguistics Magazine"); // changing email should work too, but not change cdb except for defaults $result = Dbl::qe(Contact::contactdb(), "insert into ContactInfo set firstName='', lastName='Thamrongrattanarit 2', email='te2@_.com', affiliation='Brandeis University or something', collaborators='Newsweek Magazine', password='******'"); xassert(!!$result); Dbl::free($result); $acct = $us->save((object) ["email" => "te2@_.com", "lastName" => "Thamrongrattanarit 1", "firstName" => "Te 1"], $te);