From: Stéphane Jacob Date: Tue, 20 Sep 2011 17:56:10 +0000 (+0200) Subject: Checks email redirections before creating an xnet account. X-Git-Tag: xorg/1.1.4~147 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=12f38333e3ebcbe0d5b5f62c6addce2338e95665;p=platal.git Checks email redirections before creating an xnet account. Signed-off-by: Stéphane Jacob --- diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 7ad6236..07ad8f1 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -888,40 +888,45 @@ class XnetGrpModule extends PLModule } } } else { - // 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). - $user = User::getSilent($hruid); - - // If the user has no account yet, creates new account: build names from email address. - if (empty($user)) { - $parts = explode('.', $mbox); - if (count($parts) == 1) { - $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox); - $firstname = ''; - } else { - $firstname = ucfirst($parts[0]); - $lastname = ucwords(implode(' ', array_slice($parts, 1))); - $display_name = $firstname; - $full_name = "$firstname $lastname"; - $directory_name = strtoupper($lastname) . " " . $firstname; - } - XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', - $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email); + // Check if the email is a redirection. + $user = User::getSilent($email); + + if (is_null($user) || $user->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). $user = User::getSilent($hruid); - } - $suggest_account_activation = $this->suggest($user); + // If the user has no account yet, creates new account: build names from email address. + if (empty($user)) { + $parts = explode('.', $mbox); + if (count($parts) == 1) { + $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox); + $firstname = ''; + } else { + $firstname = ucfirst($parts[0]); + $lastname = ucwords(implode(' ', array_slice($parts, 1))); + $display_name = $firstname; + $full_name = "$firstname $lastname"; + $directory_name = strtoupper($lastname) . " " . $firstname; + } + XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', + $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email); + $user = User::getSilent($hruid); + } + + $suggest_account_activation = $this->suggest($user); + } } if ($user) {