{
Platal::assert(!is_null($user), 'User cannot be null.');
- return !$user->checkPerms(User::PERM_MAIL) && $new_email != $user->forlifeEmail();
+ $is_new = !$user->checkPerms(User::PERM_MAIL) && $new_email != strtolower($user->email);
+ if ($new_email && $is_new) {
+ $already = XDB::fetchOneCell('SELECT hruid
+ FROM accounts
+ WHERE email = {?} AND uid != {?}',
+ $new_email, $user->id());
+ if ($already) {
+ Platal::page()->trigError("L'email ne peut pas être utilisé pour ce compte car il correspond déjà au compte : "
+ . $already . ". Si l'utilisateur courant et cette personne ne sont en fait qu'une "
+ . "seul et même personne, ou en cas de problème, contacter : contact@polytechnique.org");
+ return false;
+ }
+ }
+ return $is_new;
}
function format_email_alias($email)
// function isvalid_email_redirection() {{{1
/** Checks if an email is a suitable redirection.
* @param $email the email to check
+ * @param $user the user asking for the redirection
* @return BOOL
*/
-function isvalid_email_redirection($email)
+function isvalid_email_redirection($email, User $user)
{
- return isvalid_email($email) && !preg_match("/@polytechnique\.edu$/", $email) && User::isForeignEmailAddress($email);
+ $valid = isvalid_email($email) && User::isForeignEmailAddress($email);
+ if (!$user->hasProfile() || ($user->profile()->grad_year > date('Y') - 3)) {
+ return $valid && !preg_match("/@polytechnique\.edu$/", $email);
+ } else {
+ return $valid;
+ }
}
// function ids_from_mails() {{{1
if (!isvalid_email($email_stripped)) {
return ERROR_INVALID_EMAIL;
}
- if (!isvalid_email_redirection($email_stripped)) {
+ if (!isvalid_email_redirection($email_stripped, $this->user)) {
return ERROR_LOOP_EMAIL;
}
// We first need to retrieve the value for the antispam filter: it is
XDB::execute('REPLACE INTO email_redirect_account (uid, redirect, flags, action)
VALUES ({?}, {?}, \'active\', {?})',
$this->user->id(), $email, $filter);
+ // Replace this email by forlife email, if present in aliases and MLs.
+ $listClient = new MMList(S::user());
+ $listClient->change_user_email($email, $this->user->forlifeEmail());
+ update_alias_user($email, $this->user->forlifeEmail());
if ($logger = S::v('log', null)) { // may be absent --> step4.php
S::logger()->log('email_add', $email . ($this->user->id() != S::v('uid') ? " (admin on {$this->user->login()})" : ""));
}