Merge branch 'xorg/maint' into xorg/master
[platal.git] / include / validations / account.inc.php
index 2ce9e09..68b10a5 100644 (file)
@@ -28,6 +28,7 @@ class AccountReq extends Validate
     public $hruid;
     public $email;
     public $group;
+    public $groups;
 
     public $rules = "Accepter si l'adresse email parait correcte, et pas absurde
         (ou si le demandeur est de confiance). Si le demandeur marque sa propre
@@ -46,6 +47,12 @@ class AccountReq extends Validate
                                           FROM  accounts
                                          WHERE  hruid = {?}',
                                        $hruid);
+        $this->groups = implode(',', XDB::fetchColumn('SELECT  g.nom
+                                                         FROM  groups AS g
+                                                   INNER JOIN  group_members AS m ON (g.id = m.asso_id)
+                                                        WHERE  m.uid = {?}
+                                                     ORDER BY  g.nom',
+                                                      $this->uid));
     }
 
     // }}}
@@ -82,17 +89,9 @@ class AccountReq extends Validate
     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();
+        XDB::execute('INSERT INTO  register_pending_xnet (uid, hruid, email, date, hash, sender_name, group_name)
+                           VALUES  ({?}, {?}, {?}, NOW(), {?}, {?}, {?})',
+                     $this->uid, $this->hruid, $this->email, $hash, $this->user->fullName(), $this->group);
 
         return true;
     }
@@ -107,12 +106,13 @@ class AccountReq extends Validate
                               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));
+            if ($request->uid == $uid) {
+                return true;
+            }
         }
-        return $is_pending;
+        return false;
     }
 
     // }}}