function fix_homonym(PlUser $user, $email) { XDB::execute('DELETE FROM email_source_account WHERE email = {?} AND type = \'alias\'', $email); $hrmid = User::makeHomonymHrmid($email); // TODO: insert twice into source_other if different domains XDB::execute('INSERT INTO email_source_other (hrmid, email, domain, type, expire) SELECT {?}, {?}, id, \'homonym\', NOW() FROM email_virtual_domains WHERE name = {?}', $hrmid, $email, $user->mainEmailDomain()); XDB::execute("INSERT INTO email_redirect_other (hrmid, redirect, type, action)\n VALUES ({?}, '', 'homonym', 'homonym')", $hrmid); require_once 'emails.inc.php'; fix_bestalias($user); }
function handler_user(PlPage $page, PlUser $authUser, $payload, $user = null, $selector = null) { // Retrieve the PlUser referenced in the request. Note that this is the // target user, not the authenticated user. $user = PlUser::getSilent($user); if (empty($user)) { return PL_NOT_FOUND; } if ($selector == 'isRegistered') { $page->jsonAssign('isRegistered', $user->isActive()); return PL_JSON; } else { return PL_NOT_FOUND; } }
public function delNonRegistered(PlPage $page, PlUser $user) { XDB::execute('DELETE FROM watch_nonins WHERE uid = {?} AND ni_id = {?}', S::i('uid'), $user->id()); S::user()->invalidWatchCache(); Platal::session()->updateNbNotifs(); }
function createAliases($subState) { global $globals; $res = XDB::query("SELECT hruid, state, type\n FROM accounts\n WHERE uid = {?} AND hruid != ''", $subState->i('uid')); if ($res->numRows() == 0) { return "Tu n'as pas d'adresse à vie pré-attribuée.<br />" . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}\">" . "support@{$globals->mail->domain}</a> en expliquant ta situation."; } else { list($forlife, $state, $type) = $res->fetchOneRow(); } if ($state == 'active') { return "Tu es déjà inscrit, si tu ne te souviens plus de ton mot de passe d'accès au site, " . "tu peux suivre <a href=\"recovery\">la procédure de récupération de mot de passe</a>."; } else { if ($state == 'disabled') { return "Ton compte a été désactivé par les administrateurs du site suite à des abus. " . "Pour plus d'information ou pour demander la réactivation du compte, tu peux t'adresser à " . "<a href=\"mailto:support@{$globals->mail->domain}\">support@{$globals->mail->domain}</a>."; } } $emailXorg = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname')); $suffix = (User::$sub_mail_domains[$type] ? substr(User::$sub_mail_domains[$type], 0, 1) : '') . substr($subState->v('yearpromo'), -2); $emailXorg2 = $emailXorg . '.' . $suffix; // Search for homonyms: // * first case: only one homonym already registered. $res = XDB::query('SELECT uid, expire FROM email_source_account WHERE email = {?} AND type != \'alias_aux\'', $emailXorg); // * second case: at least two homonyms registerd. $result = XDB::query("SELECT hrmid\n FROM email_source_other\n WHERE type = 'homonym' AND email = {?}", $emailXorg); if ($res->numRows() || $result->numRows()) { if ($res->numRows()) { list($h_id, $expire) = $res->fetchOneRow(); if (empty($expire)) { XDB::execute('UPDATE email_source_account SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH) WHERE email = {?} AND type != \'alias_aux\'', $emailXorg); $hrmid = User::makeHomonymHrmid($emailXorg); XDB::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid) VALUES ({?}, {?}), ({?}, {?})', $hrmid, $h_id, $hrmid, $subState->i('uid')); $als = XDB::fetchColumn('SELECT email FROM email_source_account WHERE uid = {?} AND type != \'alias_aux\' AND expire IS NULL', $h_id); $homonym = User::getSilentWithUID($h_id); $mailer = new PlMailer('register/lostalias.mail.tpl'); $mailer->addTo($homonym); $mailer->setSubject("Perte de ton alias {$emailXorg} dans un mois !"); $mailer->assign('emailXorg', $emailXorg); $mailer->assign('als', join(', ', $als)); $mailer->SetTxtBody(wordwrap($msg, 72)); $mailer->send(); } } else { $hrmid = $result->fetchOneCell(); XDB::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid) VALUES ({?}, {?})', $hrmid, $subState->i('uid')); // TODO: insert into source_other if new domain } $subState->set('forlife', $forlife); $subState->set('bestalias', $emailXorg2); $subState->set('emailXorg2', null); } else { $subState->set('forlife', $forlife); $subState->set('bestalias', $emailXorg); $subState->set('emailXorg2', $emailXorg2); } $subState->set('main_mail_domain', User::$sub_mail_domains[$type] . Platal::globals()->mail->domain); return true; }
/** Check that the user match the given rule. */ public function checkUser(PlUser $user) { $this->requireAccounts(); $this->buildQuery(); $count = (int) XDB::rawFetchOneCell('SELECT COUNT(*) ' . $this->query . XDB::format(' AND a.uid = {?}', $user->id())); return $count == 1; }
function handler_accounts(PlPage $page) { $page->changeTpl('admin/accounts.tpl'); $page->setTitle('Administration - Comptes'); if (Post::has('create_account')) { S::assert_xsrf_token(); $firstname = Post::t('firstname'); $lastname = mb_strtoupper(Post::t('lastname')); $sex = Post::s('sex'); $email = Post::t('email'); $type = Post::s('type'); if (!$type) { $page->trigError("Empty account type"); } elseif (!isvalid_email($email)) { $page->trigError("Invalid email address: {$email}"); } elseif (strlen(Post::s('pwhash')) != 40) { $page->trigError("Invalid password hash"); } else { $login = PlUser::makeHrid($firstname, $lastname, $type); $full_name = $firstname . ' ' . $lastname; $directory_name = $lastname . ' ' . $firstname; XDB::execute("INSERT INTO accounts (hruid, type, state, password,\n registration_date, email, full_name,\n display_name, sex, directory_name,\n lastname, firstname)\n VALUES ({?}, {?}, 'active', {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?})", $login, $type, Post::s('pwhash'), $email, $full_name, $full_name, $sex, $directory_name, $lastname, $firstname); } } $uf = new UserFilter(new UFC_AccountType('ax', 'school', 'fx')); $page->assign('users', $uf->iterUsers()); }
function build_email_alias(array $public_names) { return PlUser::makeUserName(build_first_name($public_names), build_short_last_name($public_names)); }
public static function relance(PlUser $user, $nbx = -1) { global $globals; if ($nbx < 0) { $nbx = $globals->core->NbIns; } $res = XDB::fetchOneCell('SELECT r.date, r.email, r.bestalias FROM register_pending WHERE r.hash = \'INSCRIT\' AND uid = {?}', $user->id()); if (!$res) { return false; } else { list($date, $email, $alias) = $res; } $hash = rand_url_id(12); $pass = rand_pass(); $pass_encrypted = sha1($pass); $fdate = strftime('%d %B %Y', strtotime($date)); $mymail = new PlMailer('marketing/relance.mail.tpl'); $mymail->assign('nbdix', $nbx); $mymail->assign('fdate', $fdate); $mymail->assign('lusername', $alias); $mymail->assign('nveau_pass', $pass); $mymail->assign('baseurl', $globals->baseurl); $mymail->assign('lins_id', $hash); $mymail->assign('lemail', $email); $mymail->assign('subj', ucfirst($globals->mail->domain) . ' : ' . $alias); $mymail->send(); XDB::execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_encrypted, $user->id()); return $user->fullName(); }
public function toCSV($sep = ',', $enc = '"', $asep = '|') { $nbq = count($this->questions); //require_once dirname(__FILE__) . '/../../classes/varstream.php'; VarStream::init(); global $csv_output; $csv_output = ''; $csv = fopen('var://csv_output', 'w'); $line = $this->isMode(self::MODE_XIDENT) ? array('id', 'Nom', 'Prenom', 'Promo') : array('id'); $qids = array(); for ($qid = 0; $qid < $nbq; $qid++) { $qids[$qid] = count($line); // stores the first id of a question (in case of questions with subquestions) array_splice($line, count($line), 0, $this->questions[$qid]->getCSVColumns()); // the first line contains the questions } $nbf = count($line); $users = array(); if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous $users = XDB::fetchAllAssoc('vid', 'SELECT v.id AS vid, v.uid FROM survey_votes AS v WHERE v.survey_id = {?} ORDER BY vid ASC', $this->id); } $sql = 'SELECT v.id AS vid, a.question_id AS qid, a.answer AS answer FROM survey_votes AS v INNER JOIN survey_answers AS a ON a.vote_id=v.id WHERE v.survey_id={?} ORDER BY vid ASC, qid ASC, answer ASC'; $res = XDB::iterator($sql, $this->id); // retrieves all answers from database $vid = -1; $vid_ = 0; while (($cur = $res->next()) != null) { if ($vid != $cur['vid']) { // if the vote id changes, then starts a new line fputcsv($csv, $line, $sep, $enc); // stores the former line into $csv_output $vid = $cur['vid']; $line = array_fill(0, $nbf, ''); // creates an array full of empty string $line[0] = $vid_; // the first field is a 'clean' vote id (not the one stored in database) if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous if (array_key_exists($vid, $users)) { // and if the user data can be found $user = PlUser::getWithUID($users[$vid]); $line[1] = $user->lastName(); // adds the user data (in the first fields of the line) $line[2] = $user->firstName(); $line[3] = $user->promo(); } } $vid_++; } $ans = $this->questions[$cur['qid']]->formatAnswer($cur['answer']); // formats the current answer if (!is_null($ans)) { if (is_array($ans)) { $fid = $qids[$cur['qid']] + $ans['id']; // computes the field id $a = $ans['answer']; } else { $fid = $qids[$cur['qid']]; $a = $ans; } if ($line[$fid] != '') { // if this field already contains something $line[$fid] .= $asep; // then adds a separator before adding the new answer } $line[$fid] .= $a; // adds the current answer to the correct field } } fputcsv($csv, $line, $sep, $enc); // stores the last line into $csv_output return $csv_output; }
private function changeLogin(PlPage $page, PlUser $user, $login, $req_broken = false, $req_marketing = false, $marketing_from = 'user') { // Search the user's uid. $xuser = User::getSilent($login); if (!$xuser) { $accounts = User::getPendingAccounts($login); if (!$accounts) { $page->trigError("L'identifiant {$login} ne correspond à aucun X."); return false; } else { if (count($accounts) > 1) { $page->trigError("L'identifiant {$login} correspond à plusieurs camarades."); return false; } } $xuser = User::getSilent($accounts[0]['uid']); } if (!$xuser) { return false; } // Market or suggest new redirection if required. $email = $user->bestEmail(); if ($req_broken) { $valid = new BrokenReq(S::user(), $xuser, $email, 'Groupe : ' . Platal::globals()->asso('nom')); $valid->submit(); } elseif ($req_marketing) { $market = Marketing::get($xuser->uid, $email); if (!$market) { $market = new Marketing($xuser->uid, $email, 'group', Platal::globals()->asso('nom'), $marketing_from, S::i('uid')); $market->add(); } } if ($user->mergeIn($xuser)) { return $xuser->login(); } return $user->login(); }
private static function getDate(PlUser $user, $date) { if (is_null($date)) { $date = $user->watchLast(); $limit = time() - 7 * 86400; if ($date < $limit) { $date = $limit; } } return $date; }