From bc6e8005beb0f4154ac96660f69dcd688c0c7893 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Wed, 16 Mar 2011 16:51:29 +0100 Subject: [PATCH] Submits xnet account creation to validation process. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- configs/mails.conf | 5 ++ include/validations/account.inc.php | 122 +++++++++++++++++++++++++++++++ modules/xnetgrp.php | 53 +++++++++++++- templates/include/form.valid.account.tpl | 32 ++++++++ templates/xnet/account.mail.tpl | 48 ++++++++++++ templates/xnetgrp/membres-suggest.tpl | 42 +++++++++++ upgrade/1.1.0/16_register_ext.sql | 16 ++++ 7 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 include/validations/account.inc.php create mode 100644 templates/include/form.valid.account.tpl create mode 100644 templates/xnet/account.mail.tpl create mode 100644 templates/xnetgrp/membres-suggest.tpl create mode 100644 upgrade/1.1.0/16_register_ext.sql diff --git a/configs/mails.conf b/configs/mails.conf index 5d0cc89..6e04953 100644 --- a/configs/mails.conf +++ b/configs/mails.conf @@ -81,3 +81,8 @@ from="Polytechnique.org" [newsletter_schedule_mailing] from="Gestion des NLs" to=br@staff.polytechnique.org + +[xnet_registration] +from=register@polytechnique.org +cc=register@polytechnique.org +subject="Inscription à Polytechnique.net" diff --git a/include/validations/account.inc.php b/include/validations/account.inc.php new file mode 100644 index 0000000..2ce9e09 --- /dev/null +++ b/include/validations/account.inc.php @@ -0,0 +1,122 @@ +hruid = $hruid; + $this->email = $email; + $this->group = $group; + $this->uid = XDB::fetchOneCell('SELECT uid + FROM accounts + WHERE hruid = {?}', + $hruid); + } + + // }}} + // {{{ function formu() + + public function formu() + { + return 'include/form.valid.account.tpl'; + } + + // }}} + // {{{ function _mail_subj + + protected function _mail_subj() + { + return "[Polytechnique.org] Création d'un compte Polytechnique.net"; + } + + // }}} + // {{{ function _mail_body + + protected function _mail_body($isok) + { + if ($isok) { + return " Un email vient d'être envoyé à {$this->email} pour qu'il puisse activer son compte sur Polytechnique.net."; + } else { + return " Nous n'avons pas jugé bon d'envoyer d'email à {$this->email} pour qu'il puisse activer son compte sur Polytechnique.net."; + } + } + + // }}} + // {{{ function commit() + + public function commit() + { + $hash = rand_url_id(12); + XDB::execute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash) + VALUES ({?}, {?}, {?}, NOW(), {?})', + $this->uid, $this->hruid, $this->email, $hash); + + $mailer = new PlMailer('xnet/account.mail.tpl'); + $mailer->addTo($this->email); + $mailer->assign('hash', $hash); + $mailer->assign('hruid', $this->hruid); + $mailer->assign('group', $this->group); + $mailer->assign('user', $this->user); + $mailer->send(); + + return true; + } + + // }}} + // {{{ function isPending() + + static public function isPending($uid) + { + $res = XDB::iterRow('SELECT data + FROM requests + WHERE type = \'account\' + ORDER BY stamp'); + + $is_pending = false; + while (list($data) = $res->next()) { + $request = Validate::unserialize($data); + $is_pending = ($is_pending || ($request->uid == $uid)); + } + return $is_pending; + } + + // }}} +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 9206635..91ec6af 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -47,6 +47,7 @@ class XnetGrpModule extends PLModule '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'), '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH), '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'), + '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_MDP, 'groupadmin'), '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC), '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), @@ -656,6 +657,7 @@ class XnetGrpModule extends PLModule } S::assert_xsrf_token(); + $suggest_account_activation = false; // Finds or creates account: first cases are for users with an account. if (!User::isForeignEmailAddress($email)) { @@ -694,7 +696,15 @@ class XnetGrpModule extends PLModule } } } else { - // User is of type xnet. + // User is of type xnet. There are 3 possible cases: + // * the email is not known yet: we create a new account and + // propose to send an email to the user so he can activate + // his account, + // * the email is known but the user was not contacted in order to + // activate yet: we propose to send an email to the user so he + // can activate his account, + // * the email is known and the user was already contacted or has + // an active account: nothing to be done. list($mbox, $domain) = explode('@', strtolower($email)); $hruid = User::makeHrid($mbox, $domain, 'ext'); // User might already have an account (in another group for example). @@ -718,6 +728,21 @@ class XnetGrpModule extends PLModule $hruid, $display_name, $full_name, $directory_name, $email); $user = User::get($hruid); } + + // Check if the user is has a pending or active account. + $active = XDB::fetchOneCell('SELECT state = \'active\' + FROM accounts + WHERE uid = {?}', + $user->id()); + $pending = XDB::fetchOneCell('SELECT uid + FROM register_pending_xnet + WHERE uid = {?}', + $user->id()); + $requested = AccountReq::isPending($user->id()); + + if (!($active || $pending || $requested)) { + $suggest_account_activation = true; + } } if ($user) { @@ -725,8 +750,32 @@ class XnetGrpModule extends PLModule VALUES ({?}, {?})', $user->id(), $globals->asso('id')); $this->removeSubscriptionRequest($user->id()); - pl_redirect('member/' . $user->login()); + if ($suggest_account_activation) { + pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom')); + } else { + pl_redirect('member/' . $user->login()); + } + } + } + + function handler_admin_member_suggest($page, $hruid, $email) + { + $page->changeTpl('xnetgrp/membres-suggest.tpl'); + + if (Post::has('suggest')) { + if (Post::t('suggest') == 'yes') { + $user = S::user(); + $group = Platal::globals()->asso('nom'); + $request = new AccountReq($user, $hruid, $email, $group); + $request->submit(); + $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.', + $group . '/member/' . $hruid); + } else { + pl_redirect('member/' . $hruid); + } } + $page->assign('email', $email); + $page->assign('hruid', $hruid); } function handler_admin_member_new_ajax($page) diff --git a/templates/include/form.valid.account.tpl b/templates/include/form.valid.account.tpl new file mode 100644 index 0000000..0439369 --- /dev/null +++ b/templates/include/form.valid.account.tpl @@ -0,0 +1,32 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + + + Groupe : + {$valid->group} + + + Adresse email : + {$valid->email} + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/xnet/account.mail.tpl b/templates/xnet/account.mail.tpl new file mode 100644 index 0000000..5dc56d3 --- /dev/null +++ b/templates/xnet/account.mail.tpl @@ -0,0 +1,48 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +{config_load file="mails.conf" section="xnet_registration"} +{if $mail_part eq 'head'} +{subject text=#subject#} +{from full=#from#} +{cc full=#cc#} +{to addr="$to"} +{elseif $mail_part eq 'text'} +Bonjour, + +{$user->fullName()} nous a demandé de vous créer un compte pour que vous puissiez disposer pleinement de toutes les fonctionnalités liées au groupe {$group}. + +Après activation, vos paramètres de connexion seront : + +identifiant : {$hruid} +mot de passe : celui que vous choisirez + +Vous pouvez, dès à présent et pendant une période d'un mois, activer votre compte en cliquant sur le lien suivant : + +http://www.polytechnique.net/register/{$hash} + +Si le lien ne fonctionne pas, copiez intégralement ce lien dans la barre d'adresse de votre navigateur. + +Nous espérons que vous profiterez pleinement des services en ligne de Polytechnique.net. +{include file="include/signature.mail.tpl"} +{/if} +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/xnetgrp/membres-suggest.tpl b/templates/xnetgrp/membres-suggest.tpl new file mode 100644 index 0000000..7bc711a --- /dev/null +++ b/templates/xnetgrp/membres-suggest.tpl @@ -0,0 +1,42 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

{$asso->nom} : Ajout d'un membre (suite)

+ +

+ L'adresse email {$email} ne correspond actuellement à aucun + compte. Souhaites-tu qu'un compte « Extérieur » soit créé pour lui et que nous + lui envoyions un email afin qu'il ait accès aux nombreuses fonctionnalités de + Polytechnique.net (inscription aux évènements, télépaiement, modération des + listes de diffusion…) ? +

+
+ {xsrf_token_field} +

+ +  -  + +

+

+
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/upgrade/1.1.0/16_register_ext.sql b/upgrade/1.1.0/16_register_ext.sql new file mode 100644 index 0000000..fc72230 --- /dev/null +++ b/upgrade/1.1.0/16_register_ext.sql @@ -0,0 +1,16 @@ +DROP TABLE IF EXISTS register_pending_xnet; + +CREATE TABLE register_pending_xnet ( + uid INT(11) UNSIGNED NOT NULL DEFAULT 0, + hruid VARCHAR(255) NOT NULL DEFAULT '', + email VARCHAR(255) NOT NULL DEFAULT '', + date DATE NOT NULL DEFAULT '0000-00-00', + hash VARCHAR(12) NOT NULL DEFAULT '', + PRIMARY KEY (uid), + UNIQUE KEY hruid (hruid), + KEY hash (hash), + FOREIGN KEY (uid) REFERENCES accounts (uid) ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (hruid) REFERENCES accounts (hruid) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB, CHARSET=utf8; + +-- vim:set syntax=mysql: -- 2.1.4