$this->make_hook('register', AUTH_PUBLIC),
'register/end' => $this->make_hook('end', AUTH_PUBLIC),
'register/end.php' => $this->make_hook('end_old', AUTH_PUBLIC),
'register/success' => $this->make_hook('success', AUTH_MDP),
);
}
function handler_register(&$page, $hash = null)
{
$sub_state = S::v('sub_state', Array());
if (!isset($sub_state['step'])) {
$sub_state['step'] = 0;
}
if (Get::has('back') && Get::i('back') < $sub_state['step']) {
$sub_state['step'] = max(0,Get::i('back'));
}
// Compatibility with old sources, keep it atm
if (!$hash && Env::has('hash')) {
$hash = Env::v('hash');
}
if ($hash) {
$res = XDB::query(
"SELECT m.uid, u.promo, u.nom, u.prenom, u.matricule
FROM register_marketing AS m
INNER JOIN auth_user_md5 AS u ON u.user_id = m.uid
WHERE m.hash={?}", $hash);
if (list($uid, $promo, $nom, $prenom, $ourmat) = $res->fetchOneRow()) {
$sub_state['uid'] = $uid;
$sub_state['hash'] = $hash;
$sub_state['promo'] = $promo;
$sub_state['nom'] = $nom;
$sub_state['prenom'] = $prenom;
$sub_state['ourmat'] = $ourmat;
XDB::execute(
"REPLACE INTO register_mstats (uid,sender,success)
SELECT m.uid, m.sender, 0
FROM register_marketing AS m
WHERE m.hash", $sub_state['hash']);
}
}
switch ($sub_state['step']) {
case 0:
require_once('wiki.inc.php');
wiki_require_page('Reference.Charte');
if (Post::has('step1')) {
$sub_state['step'] = 1;
if (isset($sub_state['hash'])) {
$sub_state['step'] = 3;
require_once('register.inc.php');
create_aliases($sub_state);
}
}
break;
case 1:
if (Post::has('promo')) {
$promo = Post::i('promo');
$res = XDB::query("SELECT COUNT(*)
FROM auth_user_md5
WHERE perms='pending' AND deces = '0000-00-00'
AND promo = {?}",
$promo);
if (!$res->fetchOneCell()) {
$err = "La promotion saisie est incorrecte ou tous les camardes de cette promo sont inscrits !";
} else {
$sub_state['step'] = 2;
$sub_state['promo'] = $promo;
if ($promo >= 1996 && $promo<2000) {
$sub_state['mat'] = ($promo % 100)*10 . '???';
} elseif($promo >= 2000) {
$sub_state['mat'] = 100 + ($promo % 100) . '???';
}
}
}
break;
case 2:
if (count($_POST)) {
require_once('register.inc.php');
$sub_state['prenom'] = Post::v('prenom');
$sub_state['nom'] = Post::v('nom');
$sub_state['mat'] = Post::v('mat');
$err = check_new_user($sub_state);
if ($err !== true) { break; }
$err = create_aliases($sub_state);
if ($err === true) {
unset($err);
$sub_state['step'] = 3;
}
}
break;
case 3:
$alert = null;
if (count($_POST)) {
require_once('register.inc.php');
if (!isvalid_email(Post::v('email'))) {
$err[] = "Le champ 'E-mail' n'est pas valide.";
} elseif (!isvalid_email_redirection(Post::v('email'))) {
$err[] = $sub_state['forlife']." doit renvoyer vers un email existant ".
"valide, en particulier, il ne peut pas être renvoyé vers lui-même.";
}
$birth = Env::v('naissance');
if (!preg_match('/^[0-3][0-9][01][0-9][12][90][0-9][0-9]$/', $birth)) {
$err[] = "La 'Date de naissance' n'est pas correcte.";
} else {
$year = (int)substr($birth, 4, 4);
$promo = (int)$sub_state['promo'];
if ($year > $promo - 15 || $year < $promo - 30) {
$err[] = "La 'Date de naissance' n'est pas correcte.";
$alert = "Date de naissance proposée $birth\n\n";
}
}
// Check if the given email is known as dangerous
$res = Xdb::iterRow("SELECT w.state, w.description, a.alias
FROM emails AS e
INNER JOIN emails_watch AS w ON (e.email = w.email AND w.state != 'safe')
INNER JOIN aliases AS a ON (e.uid = a.id AND a.type = 'a_vie')
WHERE e.email = {?}
ORDER BY a.alias", Post::v('email'));
$aliases = array();
while(list($gstate, $gdescription, $alias) = $res->next()) {
$state = $gstate;
$description = $gdescription;
$aliases[] = $alias;
}
if (count($aliases) != 0) {
$alert .= "Email proposé : " . Post::v('email') . "\n"
. "Ce mails est connu avec l'état $state :\n"
. $description . "\n"
. "Pour les alias :\n* " . join("\n* ", $aliases) . "\n\n";
}
if (isset($err)) {
$err = join('
', $err);
} else {
$sub_state['naissance'] = sprintf("%s-%s-%s",
substr($birth,4,4),
substr($birth,2,2),
substr($birth,0,2));
$sub_state['email'] = Post::v('email');
$sub_state['step'] = 4;
finish_ins($sub_state);
}
if (!is_null($alert)) {
send_alert_mail($sub_state, $alert);
}
}
break;
}
$_SESSION['sub_state'] = $sub_state;
$page->changeTpl('register/step'.intval($sub_state['step']).'.tpl');
if (isset($err)) {
$page->trig($err);
}
}
function handler_end_old(&$page)
{
return $this->handler_end($page, Env::v('hash'));
}
function handler_end(&$page, $hash = null)
{
global $globals;
$page->changeTpl('register/end.tpl');
$_SESSION['sub_state'] = array('step' => 5);
require_once('user.func.inc.php');
if ($hash) {
$res = XDB::query(
"SELECT r.uid, r.forlife, r.bestalias, r.mailorg2,
r.password, r.email, r.naissance, u.nom, u.prenom,
u.promo, u.flags
FROM register_pending AS r
INNER JOIN auth_user_md5 AS u ON r.uid = u.user_id
WHERE hash={?} AND hash!='INSCRIT'", $hash);
}
if (!$hash || !list($uid, $forlife, $bestalias, $mailorg2, $password, $email,
$naissance, $nom, $prenom, $promo, $femme) = $res->fetchOneRow())
{
$page->kill("
Cette adresse n'existe pas, ou plus, sur le serveur.
Causes probables :