Browse Source

Fix user adding

Phyks (Lucas Verney) 4 years ago
parent
commit
09bbb789c6
3 changed files with 23 additions and 9 deletions
  1. 19
    5
      inc/User.class.php
  2. 2
    2
      index.php
  3. 2
    2
      tpl/default/index.html

+ 19
- 5
inc/User.class.php View File

@@ -67,7 +67,11 @@ class User extends Storage {
67 67
     }
68 68
 
69 69
     public function setEmail($email) {
70
-        if(filter_var($email, FILTER_VALIDATE_EMAIL) !== false) {
70
+        if (empty($email)) {
71
+            $this->email = null;
72
+            return true;
73
+        }
74
+        elseif(filter_var($email, FILTER_VALIDATE_EMAIL) !== false) {
71 75
             $this->email = $email;
72 76
             return true;
73 77
         }
@@ -77,7 +81,7 @@ class User extends Storage {
77 81
     }
78 82
 
79 83
     public function setDisplayName($display_name) {
80
-        $this->display_name = $display_name;
84
+        $this->display_name = (!empty($display_name) ? $display_name : NULL);
81 85
     }
82 86
 
83 87
     public function setPassword($password) {
@@ -113,7 +117,7 @@ class User extends Storage {
113 117
     }
114 118
 
115 119
     public function setStaySignedInToken($token) {
116
-        $this->stay_signed_in_token = $token;
120
+        $this->stay_signed_in_token = (!empty($token) ? $token : NULL);
117 121
     }
118 122
 
119 123
     // Password functions
@@ -177,8 +181,18 @@ class User extends Storage {
177 181
     // (a user = a unique login and display_name)
178 182
     // =========================================
179 183
     public function isUnique() {
180
-        if($this->load(array('login'=>$this->login)) === false && $this->load(array('display_name'=>$this->display_name)) === false) {
181
-            return true;
184
+        if($this->load(array('login'=>$this->login)) === false) {
185
+            if (!empty($this->display_name)) {
186
+                if ($this->load(array('display_name'=>$this->display_name)) === false) {
187
+                    return true;
188
+                }
189
+                else {
190
+                    return false;
191
+                }
192
+            }
193
+            else {
194
+                return true;
195
+            }
182 196
         }
183 197
         else {
184 198
             return false;

+ 2
- 2
index.php View File

@@ -227,7 +227,7 @@
227 227
                         $user->setPassword($user->encrypt($_POST['password']));
228 228
                     }
229 229
                     $user->setAdmin($_POST['admin']);
230
-                    $user->setStaySignedInToken("");
230
+                    $user->setStaySignedInToken(NULL);
231 231
 
232 232
                     if($user->setEmail($_POST['email']) !== false) {
233 233
                         if(!empty($_POST['user_id']) || $user->isUnique()) {
@@ -1088,7 +1088,7 @@
1088 1088
 
1089 1089
                 // Only keep the invoices which concern the user (as buyer or user in) (only if user != admin)
1090 1090
                 // TODO : Optimize ?
1091
-                if(!$current_user->getAdmin()) {
1091
+                if(!$current_user->getAdmin() && $invoices_list !== false) {
1092 1092
                     foreach($invoices_list as $key=>$invoice) {
1093 1093
                         if($invoice->getBuyer() != $current_user->getId() && !$invoice->getUsersIn()->inUsersIn($current_user->getId())) {
1094 1094
                             unset($invoices_list[$key]);

+ 2
- 2
tpl/default/index.html View File

@@ -35,7 +35,7 @@
35 35
             <tr>
36 36
                 <th>{$i18n['users']}</th>
37 37
                 <th>{$i18n['you_owe_him']}</th>
38
-                <th>{$i18n['he_owes_you']}/th>
38
+                <th>{$i18n['he_owes_you']}</th>
39 39
             </tr>
40 40
             {loop="$users"}
41 41
                 {if condition="$balances[$value->getId()][$current_user->getId()] !== 'X' && $balances[$value->getId()][$current_user->getId()] !== '-'"}
@@ -141,7 +141,7 @@
141 141
             {/loop}
142 142
         </table>
143 143
     {else}
144
-    <p class="center">{$i18n['no_bills']}.</p>
144
+    <p class="center">{$i18n['no_bills']}</p>
145 145
     {/if}
146 146
 </div>
147 147
 {include="footer"}