Close #646: Update destination address of validation mail when losing the bestalias
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 2 Mar 2007 16:44:42 +0000 (16:44 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Fri, 2 Mar 2007 16:44:42 +0000 (16:44 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1537 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
include/user.func.inc.php
include/validations/nomusage.inc.php
include/xorg.misc.inc.php
modules/admin.php
modules/register/register.inc.php

index 6e9f58e..9c18bc5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,7 @@ Bug/Wish:
 
     * Profile:
         - Better checks on image type for photos                           -FRU
+        - #646: Don't send a mail to an invalid address                    -FRU
 
     * Lists:
         - #407: RSS feed                                                   -FRU
index f0cccc7..6def026 100644 (file)
@@ -718,7 +718,8 @@ function user_reindex($uid) {
 // }}}
 // {{{ function set_new_usage()
 
-function set_new_usage($uid, $usage, $alias=false) { 
+function set_new_usage($uid, $usage, $alias=false)
+{ 
     XDB::execute("UPDATE auth_user_md5 set nom_usage={?} WHERE user_id={?}",$usage ,$uid);
     XDB::execute("DELETE FROM aliases WHERE FIND_IN_SET('usage',flags) AND id={?}", $uid);
     if ($alias && $usage) {
@@ -727,11 +728,12 @@ function set_new_usage($uid, $usage, $alias=false) {
             $alias, $uid);
     }
     $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid);
-    if ($r->fetchOneCell() == "") {
+    if ($r->numRows() == "") {
         XDB::execute("UPDATE aliases SET flags = 1 | flags WHERE id = {?} LIMIT 1", $uid);
+        $r = XDB::query("SELECT alias FROM aliases WHERE FIND_IN_SET('bestalias', flags) AND id = {?}", $uid);
     }
-    require_once 'user.func.inc.php';
     user_reindex($uid);
+    return $r->fetchOneCell();
 }
 
 // }}}
index a551a03..b2e6782 100644 (file)
@@ -49,6 +49,7 @@ class UsageReq extends Validate
         $this->Validate($_uid, true, 'usage');
         $this->nom_usage  = $_usage;
         $this->reason = $_reason;
+        require_once 'xorg.misc.inc.php';
         $this->alias   = make_username($this->prenom, $this->nom_usage);
         if (!$this->nom_usage) $this->alias = "";
 
@@ -101,7 +102,7 @@ class UsageReq extends Validate
     function commit()
     {
         require_once('user.func.inc.php');
-        set_new_usage($this->uid, $this->nom_usage, $this->alias);
+        $this->bestalias = set_new_usage($this->uid, $this->nom_usage, $this->alias);
         return true;
     }
 
index d4154d8..1476994 100644 (file)
@@ -104,6 +104,29 @@ function replace_accent($string)
     return strtr($string, $uc_convert);
 }
 
+/** creates a username from a first and last name
+*
+* @param $prenom the firstname
+* @param $nom the last name
+*
+* return STRING the corresponding username
+*/
+function make_username($prenom,$nom) {
+    /* on traite le prenom */
+    $prenomUS=replace_accent(trim($prenom));
+    $prenomUS=stripslashes($prenomUS);
+
+    /* on traite le nom */
+    $nomUS=replace_accent(trim($nom));
+    $nomUS=stripslashes($nomUS);
+
+    // calcul du login
+    $username = strtolower($prenomUS.".".$nomUS);
+    $username = str_replace(" ","-",$username);
+    $username = str_replace("'","",$username);
+    return $username;
+}
+
 /* Un soundex en français posté par Frédéric Bouchery
    Voici une adaptation en PHP de la fonction soundex2 francisée de Frédéric BROUARD (http://sqlpro.developpez.com/Soundex/).
    C'est une bonne démonstration de la force des expressions régulières compatible Perl.
index dab5924..1b3dc43 100644 (file)
@@ -515,6 +515,7 @@ class AdminModule extends PLModule
                             $page->trig("updaté correctement.");
                         }
                         if (Env::v('nomusageN') != $mr['nom_usage']) {
+                            require_once "xorg.misc.inc.php";
                             set_new_usage($mr['user_id'], Env::v('nomusageN'), make_username(Env::v('prenomN'), Env::v('nomusageN')));
                         }
                         if (Env::v('decesN') != $mr['deces']) {
index b9ab92f..3b475f4 100644 (file)
@@ -149,6 +149,7 @@ function create_aliases (&$sub)
 {
     extract ($sub);
 
+    require_once "xorg.misc.inc.php";
     $mailorg  = make_username($prenom, $nom);
     $mailorg2 = $mailorg.sprintf(".%02u", ($promo%100));
     $forlife  = make_forlife($prenom, $nom, $promo);