Completed
Push — master ( f3d443...f2ef51 )
by Patrick
03:59 queued 01:03
created
Auth/class.LDAPGroup.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace Auth;
3
-if(isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
3
+if (isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
4 4
 {
5 5
     require_once($GLOBALS['FLIPSIDE_SETTINGS_LOC'].'/class.FlipsideSettings.php');
6 6
 }
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     {
21 21
         $this->ldapObj = $data;
22 22
         $this->server = \LDAP\LDAPServer::getInstance();
23
-        if(!is_object($data))
23
+        if (!is_object($data))
24 24
         {
25 25
             throw new \Exception('Unable to setup LDAPGroup!');
26 26
         }
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
     {
46 46
         $rawMembers = $this->getField('member');
47 47
         $fieldName  = 'member';
48
-        if($rawMembers === false)
48
+        if ($rawMembers === false)
49 49
         {
50 50
             $rawMembers = $this->getField('uniqueMember');
51 51
             $fieldName  = 'uniqueMember';
52 52
         }
53
-        if($rawMembers === false)
53
+        if ($rawMembers === false)
54 54
         {
55 55
             $rawMembers = $this->getField('memberUid');
56 56
             $fieldName  = 'memberUid';
57 57
         }
58
-        if(!isset($rawMembers['count']))
58
+        if (!isset($rawMembers['count']))
59 59
         {
60 60
             $rawMembers['count'] = count($rawMembers);
61 61
         }
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
     private function getIDFromDN($dn)
66 66
     {
67 67
         $split = explode(',', $dn);
68
-        if(strncmp('cn=', $split[0], 3) === 0)
68
+        if (strncmp('cn=', $split[0], 3) === 0)
69 69
         {
70 70
             return substr($split[0], 3);
71 71
         }
72 72
         return substr($split[0], 4);
73 73
     }
74 74
 
75
-    public function getMemberUids($recursive=true)
75
+    public function getMemberUids($recursive = true)
76 76
     {
77 77
         $members = array();
78 78
         $rawMembers = $this->getMembersField();
79
-        for($i = 0; $i < $rawMembers['count']; $i++)
79
+        for ($i = 0; $i < $rawMembers['count']; $i++)
80 80
         {
81
-            if($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0)
81
+            if ($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0)
82 82
             {
83 83
                 $child = self::from_dn($rawMembers[$i], $this->server);
84
-                if($child !== false)
84
+                if ($child !== false)
85 85
                 {
86 86
                     $members = array_merge($members, $child->members());
87 87
                 }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             }
93 93
         }
94 94
         $count = count($members);
95
-        for($i = 0; $i < $count; $i++)
95
+        for ($i = 0; $i < $count; $i++)
96 96
         {
97 97
             $members[$i] = $this->getIDFromDN($members[$i]);
98 98
         }
@@ -102,36 +102,36 @@  discard block
 block discarded – undo
102 102
     private function getObjectFromDN($dn)
103 103
     {
104 104
         $split = explode(',', $dn);
105
-        if(strncmp('cn=', $dn, 3) === 0)
105
+        if (strncmp('cn=', $dn, 3) === 0)
106 106
         {
107
-            if(count($split) === 1)
107
+            if (count($split) === 1)
108 108
             {
109 109
                 return LDAPGroup::from_name($dn, $this->server);
110 110
             }
111 111
             return LDAPGroup::from_name(substr($split[0], 3), $this->server);
112 112
         }
113
-        if(count($split) === 1)
113
+        if (count($split) === 1)
114 114
         {
115 115
             return LDAPUser::from_name($dn, $this->server);
116 116
         }
117 117
         return LDAPUser::from_name(substr($split[0], 4), $this->server);
118 118
     }
119 119
 
120
-    public function members($details=false, $recursive=true, $includeGroups=true)
120
+    public function members($details = false, $recursive = true, $includeGroups = true)
121 121
     {
122 122
         $members = array();
123 123
         $rawMembers = $this->getMembersField();
124
-        for($i = 0; $i < $rawMembers['count']; $i++)
124
+        for ($i = 0; $i < $rawMembers['count']; $i++)
125 125
         {
126
-            if($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0)
126
+            if ($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0)
127 127
             {
128 128
                 $child = self::from_dn($rawMembers[$i], $this->server);
129
-                if($child !== false)
129
+                if ($child !== false)
130 130
                 {
131 131
                     $members = array_merge($members, $child->members());
132 132
                 }
133 133
             }
134
-            else if($includeGroups === false && strncmp($rawMembers[$i], 'cn=', 3) === 0)
134
+            else if ($includeGroups === false && strncmp($rawMembers[$i], 'cn=', 3) === 0)
135 135
             {
136 136
                 //Drop this member
137 137
             }
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
                 array_push($members, $rawMembers[$i]);
141 141
             }
142 142
         }
143
-        if($details === true)
143
+        if ($details === true)
144 144
         {
145 145
             $details = array();
146 146
             $count = count($members);
147
-            for($i = 0; $i < $count; $i++)
147
+            for ($i = 0; $i < $count; $i++)
148 148
             {
149 149
                 $details[$i] = $this->getObjectFromDN($members[$i]);
150 150
             }
@@ -154,37 +154,37 @@  discard block
 block discarded – undo
154 154
         return $members;
155 155
     }
156 156
 
157
-    public function getNonMemebers($select=false)
157
+    public function getNonMemebers($select = false)
158 158
     {
159 159
         $data = array();
160 160
         $groupFilter = '(&(cn=*)(!(cn='.$this->getGroupName().'))';
161 161
         $userFilter = '(&(cn=*)';
162 162
         $members = $this->members();
163 163
         $count = count($members);
164
-        for($i = 0; $i < $count; $i++)
164
+        for ($i = 0; $i < $count; $i++)
165 165
         {
166
-            $dnComps = explode(',',$members[$i]);
167
-            if(strncmp($members[$i], "uid=", 4) == 0)
166
+            $dnComps = explode(',', $members[$i]);
167
+            if (strncmp($members[$i], "uid=", 4) == 0)
168 168
             {
169
-                $userFilter.='(!('.$dnComps[0].'))';
169
+                $userFilter .= '(!('.$dnComps[0].'))';
170 170
             }
171 171
             else
172 172
             {
173
-                $groupFilter.='(!('.$dnComps[0].'))';
173
+                $groupFilter .= '(!('.$dnComps[0].'))';
174 174
             }
175 175
         }
176
-        $userFilter.=')';
177
-        $groupFilter.=')';
176
+        $userFilter .= ')';
177
+        $groupFilter .= ')';
178 178
         $groups = $this->server->read($this->server->group_base, $groupFilter);
179 179
         $count = count($groups);
180
-        for($i = 0; $i < $count; $i++)
180
+        for ($i = 0; $i < $count; $i++)
181 181
         {
182
-            if($groups[$i] === false || $groups[$i] === null) continue;
182
+            if ($groups[$i] === false || $groups[$i] === null) continue;
183 183
             array_push($data, new LDAPGroup($groups[$i]));
184 184
         }
185 185
         $users = $this->server->read($this->server->user_base, $userFilter, false, $select);
186 186
         $count = count($users);
187
-        for($i = 0; $i < $count; $i++)
187
+        for ($i = 0; $i < $count; $i++)
188 188
         {
189 189
             array_push($data, new LDAPUser($users[$i]));
190 190
         } 
@@ -193,24 +193,24 @@  discard block
 block discarded – undo
193 193
 
194 194
     public function clearMembers()
195 195
     {
196
-        if(isset($this->ldapObj['member']))
196
+        if (isset($this->ldapObj['member']))
197 197
         {
198 198
             $this->ldapObj['member'] = array();
199 199
         }
200
-        else if(isset($this->ldapObj['uniquemember']))
200
+        else if (isset($this->ldapObj['uniquemember']))
201 201
         {
202 202
             $this->ldapObj['uniquemember'] = array();
203 203
         }
204
-        else if(isset($this->ldapObj['memberuid']))
204
+        else if (isset($this->ldapObj['memberuid']))
205 205
         {
206 206
             $this->ldapObj['memberuid'] = array();
207 207
         }
208 208
     }
209 209
 
210
-    public function addMember($name, $isGroup=false, $flush=true)
210
+    public function addMember($name, $isGroup = false, $flush = true)
211 211
     {
212 212
         $dn = false;
213
-        if($isGroup)
213
+        if ($isGroup)
214 214
         {
215 215
             $dn = 'cn='.$name.','.$this->server->group_base;
216 216
         }
@@ -220,17 +220,17 @@  discard block
 block discarded – undo
220 220
         }
221 221
         $propName   = false;
222 222
         $rawMembers = $this->getMembersField($propName);
223
-        if(isset($rawMembers['count']))
223
+        if (isset($rawMembers['count']))
224 224
         {
225 225
             unset($rawMembers['count']);
226 226
         }
227
-        if(in_array($dn, $rawMembers) || in_array($name, $rawMembers))
227
+        if (in_array($dn, $rawMembers) || in_array($name, $rawMembers))
228 228
         {
229 229
             return true;
230 230
         }
231
-        if($propName === 'memberUid')
231
+        if ($propName === 'memberUid')
232 232
         {
233
-            if($isGroup)
233
+            if ($isGroup)
234 234
             {
235 235
                 throw new \Exception('Unable to add a group as a child of this group type');
236 236
             }
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         }
243 243
         $tmp = strtolower($propName);
244 244
         $this->ldapObj->$tmp = $rawMembers;
245
-        if($flush === true)
245
+        if ($flush === true)
246 246
         {
247 247
             $obj = array('dn'=>$this->ldapObj->dn);
248 248
             $obj[$propName] = $rawMembers;
@@ -254,29 +254,29 @@  discard block
 block discarded – undo
254 254
         }
255 255
     }
256 256
 
257
-    static function from_dn($dn, $data=false)
257
+    static function from_dn($dn, $data = false)
258 258
     {
259
-        if($data === false)
259
+        if ($data === false)
260 260
         {
261 261
             throw new \Exception('data must be set for LDAPGroup');
262 262
         }
263 263
         $group = $data->read($dn, false, true);
264
-        if($group === false || !isset($group[0]))
264
+        if ($group === false || !isset($group[0]))
265 265
         {
266 266
             return false;
267 267
         }
268 268
         return new static($group[0]);
269 269
     }
270 270
 
271
-    static function from_name($name, $data=false)
271
+    static function from_name($name, $data = false)
272 272
     {
273
-        if($data === false)
273
+        if ($data === false)
274 274
         {
275 275
             throw new \Exception('data must be set for LDAPGroup');
276 276
         }
277 277
         $filter = new \Data\Filter("cn eq $name");
278 278
 	$group = $data->read($data->group_base, $filter);
279
-        if($group === false || !isset($group[0]))
279
+        if ($group === false || !isset($group[0]))
280 280
         {
281 281
             return false;
282 282
         }
Please login to merge, or discard this patch.
class.FlipREST.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
     private function getUserFromSession()
27 27
     {
28
-        if(FlipSession::isLoggedIn())
28
+        if (FlipSession::isLoggedIn())
29 29
         {
30 30
             return FlipSession::getUser();
31 31
         }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         $auth = \AuthProvider::getInstance();
42 42
         $auth->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
43 43
         $user = FlipSession::getUser();
44
-        if($user === false)
44
+        if ($user === false)
45 45
         {
46 46
             $data = substr($header['Authorization'], 6);
47 47
             $userpass = explode(':', base64_decode($data));
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
     private function getUserFromHeader($header)
64 64
     {
65
-        if(strncmp($header, 'Basic', 5) == 0)
65
+        if (strncmp($header, 'Basic', 5) == 0)
66 66
         {
67 67
             return $this->getUserFromBasicAuth($header);
68 68
         }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     public function call()
73 73
     {
74 74
         // no auth header
75
-        if(!isset($this->headers['Authorization']))
75
+        if (!isset($this->headers['Authorization']))
76 76
         {
77 77
             $this->app->user = $this->getUserFromSession();
78 78
         } 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             $this->app->user = $this->getUserFromHeader($header);
83 83
         }
84 84
 
85
-        if($this->app->user === false)
85
+        if ($this->app->user === false)
86 86
         {
87 87
             $this->app->getLog()->error("No user found for call");
88 88
         }
@@ -96,19 +96,19 @@  discard block
 block discarded – undo
96 96
 {
97 97
     private function fix_encoded_element($key, $value, &$array, $prefix = '')
98 98
     {
99
-        if(is_array($value))
99
+        if (is_array($value))
100 100
         {
101 101
             $array[$key] = implode(';', $value);
102 102
         }
103
-        else if($key === '_id' && is_object($value))
103
+        else if ($key === '_id' && is_object($value))
104 104
         {
105 105
             $array[$key] = $value->{'$id'};
106 106
         }
107
-        else if(is_object($value))
107
+        else if (is_object($value))
108 108
         {
109 109
             $array[$key] = $this->app->request->getUrl().$this->app->request->getPath().$prefix.'/'.$key;
110 110
         }
111
-        else if(strncmp($value, 'data:', 5) === 0)
111
+        else if (strncmp($value, 'data:', 5) === 0)
112 112
         {
113 113
             $array[$key] = $this->app->request->getUrl().$this->app->request->getPath().$prefix.'/'.$key;
114 114
         }
@@ -122,40 +122,40 @@  discard block
 block discarded – undo
122 122
         }
123 123
         ob_start();
124 124
         $df = fopen("php://output", 'w');
125
-        if(is_array($array))
125
+        if (is_array($array))
126 126
         {
127 127
             $first = reset($array);
128 128
             $keys = FALSE;
129
-            if(is_array($first))
129
+            if (is_array($first))
130 130
             {
131 131
                 $keys = array_keys($first);
132 132
             }
133
-            else if(is_object($first))
133
+            else if (is_object($first))
134 134
             {
135 135
                 $keys = array_keys(get_object_vars($first));
136 136
             }
137 137
             fputcsv($df, $keys);
138 138
             foreach ($array as $row)
139 139
             {
140
-                if(is_array($row))
140
+                if (is_array($row))
141 141
                 {
142 142
                     $id = $row[$keys[0]];
143
-                    foreach($row as $key=>$value)
143
+                    foreach ($row as $key=>$value)
144 144
                     {
145 145
                         $this->fix_encoded_element($key, $value, $row, '/'.$id);
146 146
                     }
147 147
                     fputcsv($df, $row);
148 148
                 }
149
-                else if(is_object($row))
149
+                else if (is_object($row))
150 150
                 {
151 151
                     $keyName = $keys[0];
152 152
                     $id = $row->$keyName;
153
-                    if(is_object($id))
153
+                    if (is_object($id))
154 154
                     {
155 155
                         $id = $id->{'$id'};
156 156
                     }
157 157
                     $values = get_object_vars($row);
158
-                    foreach($values as $key=>$value)
158
+                    foreach ($values as $key=>$value)
159 159
                     {
160 160
                         $this->fix_encoded_element($key, $value, $values, '/'.$id);
161 161
                     }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         {
168 168
             $array = get_object_vars($array);
169 169
             fputcsv($df, array_keys($array));
170
-            foreach($array as $key=>$value)
170
+            foreach ($array as $key=>$value)
171 171
             {
172 172
                 $this->fix_encoded_element($key, $value, $array);
173 173
             }
@@ -185,34 +185,34 @@  discard block
 block discarded – undo
185 185
 
186 186
     public function call()
187 187
     {
188
-        if($this->app->request->isOptions())
188
+        if ($this->app->request->isOptions())
189 189
         {
190 190
             return;
191 191
         }
192 192
         $params = $this->app->request->params();
193 193
         $fmt = null;
194
-        if(isset($params['fmt']))
194
+        if (isset($params['fmt']))
195 195
         {
196 196
             $fmt = $params['fmt'];
197 197
         }
198
-        if($fmt === null && isset($params['$format']))
198
+        if ($fmt === null && isset($params['$format']))
199 199
         {
200 200
             $fmt = $params['$format'];
201
-            if(strstr($fmt, 'odata.streaming=true'))
201
+            if (strstr($fmt, 'odata.streaming=true'))
202 202
             {
203 203
                 $this->app->response->setStatus(406);
204 204
                 return;
205 205
             }
206 206
         }
207
-        if($fmt === null)
207
+        if ($fmt === null)
208 208
         {
209 209
             $mimeType = $this->app->request->headers->get('Accept');
210
-            if(strstr($mimeType, 'odata.streaming=true'))
210
+            if (strstr($mimeType, 'odata.streaming=true'))
211 211
             {
212 212
                 $this->app->response->setStatus(406);
213 213
                 return;
214 214
             }
215
-            switch($mimeType)
215
+            switch ($mimeType)
216 216
             {
217 217
                 case 'text/csv':
218 218
                     $fmt = 'csv';
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
 
233 233
         $this->next->call();
234 234
 
235
-        if($this->app->response->getStatus() == 200 && $this->app->fmt !== 'json')
235
+        if ($this->app->response->getStatus() == 200 && $this->app->fmt !== 'json')
236 236
         {
237 237
             $data = json_decode($this->app->response->getBody());
238 238
             $text = false;
239
-            switch($this->app->fmt)
239
+            switch ($this->app->fmt)
240 240
             {
241 241
                 case 'data-table':
242 242
                     $this->app->response->headers->set('Content-Type', 'application/json');
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
             }
264 264
             $this->app->response->setBody($text);
265 265
         }
266
-        else if($this->app->response->getStatus() == 200)
266
+        else if ($this->app->response->getStatus() == 200)
267 267
         {
268 268
             $this->app->response->headers->set('Content-Type', 'application/json;odata.metadata=none');
269 269
         }
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
         parent::__construct();
278 278
         $this->config('debug', false);
279 279
         $headers = array();
280
-        if(php_sapi_name() !== "cli")
280
+        if (php_sapi_name() !== "cli")
281 281
         {
282 282
             $headers = apache_request_headers();
283 283
         }
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
         return $this->post($uri, $handler);
298 298
     }
299 299
 
300
-    function get_json_body($array=false)
300
+    function get_json_body($array = false)
301 301
     {
302 302
         return $this->getJsonBody($array);
303 303
     }
304 304
 
305
-    function getJsonBody($array=false)
305
+    function getJsonBody($array = false)
306 306
     {
307 307
         $body = $this->request->getBody();
308 308
         return json_decode($body, $array);
Please login to merge, or discard this patch.
Auth/class.SQLGroup.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
     public function getGroupName()
14 14
     {
15
-        if(isset($data['gid']))
15
+        if (isset($data['gid']))
16 16
         {
17 17
             return $data['gid'];
18 18
         }
@@ -21,19 +21,19 @@  discard block
 block discarded – undo
21 21
 
22 22
     public function getDescription()
23 23
     {
24
-        if(isset($data['description']))
24
+        if (isset($data['description']))
25 25
         {
26 26
             return $data['description'];
27 27
         }
28 28
         return false;
29 29
     }
30 30
 
31
-    public function getMemberUids($recursive=true)
31
+    public function getMemberUids($recursive = true)
32 32
     {
33 33
         return $this->members(false, $recursive, true);
34 34
     }
35 35
 
36
-    public function members($details=false, $recursive=true, $includeGroups=true)
36
+    public function members($details = false, $recursive = true, $includeGroups = true)
37 37
     {
38 38
         //TODO
39 39
         return array();
Please login to merge, or discard this patch.
Auth/class.LDAPAuthenticator.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 namespace Auth;
15 15
 
16 16
 /** We need the FlipsideSettings class to determine how to connect to the LDAP server */
17
-if(isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
17
+if (isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
18 18
 {
19 19
     require_once($GLOBALS['FLIPSIDE_SETTINGS_LOC'].'/class.FlipsideSettings.php');
20 20
 }
@@ -33,18 +33,18 @@  discard block
 block discarded – undo
33 33
 {
34 34
     $count = count($array);
35 35
     $keys  = array_keys($orderby);
36
-    for($i = 0; $i < $count; $i++)
36
+    for ($i = 0; $i < $count; $i++)
37 37
     {
38
-        for($j = $i; $j < $count; $j++)
38
+        for ($j = $i; $j < $count; $j++)
39 39
         {
40 40
             $d = strcasecmp($array[$i][$keys[0]][0], $array[$j][$keys[0]][0]);
41
-            switch($orderby[$keys[0]])
41
+            switch ($orderby[$keys[0]])
42 42
             {
43 43
                 case 1:
44
-                    if($d > 0) swap($array, $i, $j);
44
+                    if ($d > 0) swap($array, $i, $j);
45 45
                     break;
46 46
                 case 0:
47
-                    if($d < 0) swap($array, $i, $j);
47
+                    if ($d < 0) swap($array, $i, $j);
48 48
                     break;
49 49
             }
50 50
         }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         $this->host       = $this->getHostParam($params);
93 93
         $this->user_base  = $this->getParam($params, 'user_base');
94 94
         $this->group_base = $this->getParam($params, 'group_base');
95
-        $this->bind_dn    = $this->getParam($params, 'bind_dn',   '$ldap_auth', 'read_write_pass');
95
+        $this->bind_dn    = $this->getParam($params, 'bind_dn', '$ldap_auth', 'read_write_pass');
96 96
         $this->bind_pass  = $this->getParam($params, 'bind_pass', '$ldap_auth', 'read_write_user');
97 97
     }
98 98
 
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
      */
108 108
     private function getHostParam($params)
109 109
     {
110
-        if(isset($params['host']))
110
+        if (isset($params['host']))
111 111
         {
112 112
             return $params['host'];
113 113
         }
114
-        if(isset(\FlipsideSettings::$ldap['proto']))
114
+        if (isset(\FlipsideSettings::$ldap['proto']))
115 115
         {
116 116
             return \FlipsideSettings::$ldap['proto'].'://'.\FlipsideSettings::$ldap['host'];
117 117
         }
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
      *
131 131
      * @SuppressWarnings("StaticAccess")
132 132
      */
133
-    private function getParam($params, $paramName, $settingsLocation='$ldap', $settingsName=false)
133
+    private function getParam($params, $paramName, $settingsLocation = '$ldap', $settingsName = false)
134 134
     {
135
-        if($settingsName === false)
135
+        if ($settingsName === false)
136 136
         {
137 137
             $settingsName = $paramName;
138 138
         }
139
-        if(isset($params[$paramName]))
139
+        if (isset($params[$paramName]))
140 140
         {
141 141
             return $params[$paramName];
142 142
         }
143
-        if($settingsLocation === '$ldap')
143
+        if ($settingsLocation === '$ldap')
144 144
         {
145 145
             return \FlipsideSettings::$ldap[$settingsName];
146 146
         }
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
      *
157 157
      * @SuppressWarnings("StaticAccess")
158 158
      */
159
-    public function get_and_bind_server($bind_write=false)
159
+    public function get_and_bind_server($bind_write = false)
160 160
     {
161 161
         $server = \LDAP\LDAPServer::getInstance();
162 162
         $server->user_base = $this->user_base;
163 163
         $server->group_base = $this->group_base;
164 164
         $server->connect($this->host);
165
-        if($bind_write === false)
165
+        if ($bind_write === false)
166 166
         {
167 167
             $ret = $server->bind();
168 168
         }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         {
171 171
             $ret = $server->bind($this->bind_dn, $this->bind_pass);
172 172
         }
173
-        if($ret === false)
173
+        if ($ret === false)
174 174
         {
175 175
             return false;
176 176
         }
@@ -188,20 +188,20 @@  discard block
 block discarded – undo
188 188
     public function login($username, $password)
189 189
     {
190 190
         $server = $this->get_and_bind_server();
191
-        if($server === false)
191
+        if ($server === false)
192 192
         {
193 193
             return false;
194 194
         }
195 195
         $filter = new \Data\Filter("uid eq $username or mail eq $username");
196 196
         $user = $server->read($this->user_base, $filter);
197
-        if($user === false || count($user) === 0)
197
+        if ($user === false || count($user) === 0)
198 198
         {
199 199
             return false;
200 200
         }
201 201
         $user = $user[0];
202 202
         $server->unbind();
203 203
         $ret = $server->bind($user->dn, $password);
204
-        if($ret !== false)
204
+        if ($ret !== false)
205 205
         {
206 206
             return array('res'=>true, 'extended'=>$user); 
207 207
         }
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function isLoggedIn($data)
219 219
     {
220
-        if(isset($data['res']))
220
+        if (isset($data['res']))
221 221
         {
222 222
             return $data['res'];
223 223
         }
@@ -239,35 +239,35 @@  discard block
 block discarded – undo
239 239
     public function getGroupByName($name)
240 240
     {
241 241
         $server = $this->get_and_bind_server();
242
-        if($server === false)
242
+        if ($server === false)
243 243
         {
244 244
             return false;
245 245
         }
246 246
         return LDAPGroup::from_name($name, $server);
247 247
     }
248 248
 
249
-    public function getGroupsByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false)
249
+    public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false)
250 250
     {
251 251
         $server = $this->get_and_bind_server();
252
-        if($server === false)
252
+        if ($server === false)
253 253
         {
254 254
             return false;
255 255
         }
256
-        if($filter === false)
256
+        if ($filter === false)
257 257
         {
258 258
             $filter = new \Data\Filter('cn eq *');
259 259
         }
260 260
         $groups = $server->read($this->group_base, $filter);
261
-        if($groups === false)
261
+        if ($groups === false)
262 262
         {
263 263
             return false;
264 264
         }
265 265
         $this->processFilteringParams($groups, $select, $top, $skip, $orderby);
266 266
         $count = count($groups);
267
-        for($i = 0; $i < $count; $i++)
267
+        for ($i = 0; $i < $count; $i++)
268 268
         {
269 269
             $groups[$i] = new LDAPGroup($groups[$i]);
270
-            if($select !== false)
270
+            if ($select !== false)
271 271
             {
272 272
                 $groups[$i] = json_decode(json_encode($groups[$i]), true);
273 273
                 $groups[$i] = array_intersect_key($groups[$i], array_flip($select));
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
     public function getActiveUserCount()
280 280
     {
281 281
         $server = $this->get_and_bind_server();
282
-        if($server === false)
282
+        if ($server === false)
283 283
         {
284 284
             return false;
285 285
         }
@@ -288,50 +288,50 @@  discard block
 block discarded – undo
288 288
 
289 289
     private function processFilteringParams(&$data, &$select, $top, $skip, $orderby)
290 290
     {
291
-        if($orderby !== false)
291
+        if ($orderby !== false)
292 292
         {
293 293
             sort_array($data, $orderby);
294 294
         }
295
-        if($select !== false)
295
+        if ($select !== false)
296 296
         {
297 297
             $select = array_flip($select);
298 298
         }
299
-        if($skip !== false && $top !== false)
299
+        if ($skip !== false && $top !== false)
300 300
         {
301 301
             $data = array_slice($data, $skip, $top);
302 302
         }
303
-        else if($top !== false)
303
+        else if ($top !== false)
304 304
         {
305 305
             $data = array_slice($data, 0, $top);
306 306
         }
307
-        else if($skip !== false)
307
+        else if ($skip !== false)
308 308
         {
309 309
             $data = array_slice($data, $skip);
310 310
         }
311 311
     }
312 312
 
313
-    public function getUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false)
313
+    public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false)
314 314
     {
315 315
         $server = $this->get_and_bind_server();
316
-        if($server === false)
316
+        if ($server === false)
317 317
         {
318 318
             return false;
319 319
         }
320
-        if($filter === false)
320
+        if ($filter === false)
321 321
         {
322 322
             $filter = new \Data\Filter('cn eq *');
323 323
         }
324 324
         $users = $server->read($this->user_base, $filter, false, $select);
325
-        if($users === false)
325
+        if ($users === false)
326 326
         {
327 327
             return false;
328 328
         }
329 329
         $this->processFilteringParams($users, $select, $top, $skip, $orderby);
330 330
         $count = count($users);
331
-        for($i = 0; $i < $count; $i++)
331
+        for ($i = 0; $i < $count; $i++)
332 332
         {
333 333
             $tmp = new LDAPUser($users[$i]);
334
-            if($select !== false)
334
+            if ($select !== false)
335 335
             {
336 336
                 $tmp = $tmp->jsonSerialize();
337 337
                 $tmp = array_intersect_key($tmp, $select);
@@ -349,36 +349,36 @@  discard block
 block discarded – undo
349 349
         $email = $user->getEmail();
350 350
         $new_user->setEmail($email);
351 351
         $pass = $user->getPassword();
352
-        if($pass !== false)
352
+        if ($pass !== false)
353 353
         {
354 354
             $new_user->setPass($pass);
355 355
         }
356 356
         $sn = $user->getLastName();
357
-        if($sn !== false)
357
+        if ($sn !== false)
358 358
         {
359 359
             $new_user->setLastName($sn);
360 360
         }
361 361
         $givenName = $user->getGivenName();
362
-        if($givenName !== false)
362
+        if ($givenName !== false)
363 363
         {
364 364
             $new_user->setGivenName($givenName);
365 365
         }
366 366
         $hosts = $user->getLoginProviders();
367
-        if($hosts !== false)
367
+        if ($hosts !== false)
368 368
         {
369 369
             $count = count($hosts);
370
-            for($i = 0; $i < $count; $i++)
370
+            for ($i = 0; $i < $count; $i++)
371 371
             {
372 372
                 $new_user->addLoginProvider($hosts[$i]);
373 373
             }
374 374
         }
375 375
         $ret = $new_user->flushUser();
376
-        if($ret)
376
+        if ($ret)
377 377
         {
378 378
             $user->delete();
379 379
         }
380 380
         $users = $this->getUsersByFilter(new \Data\Filter('mail eq '.$email));
381
-        if($users === false || !isset($users[0]))
381
+        if ($users === false || !isset($users[0]))
382 382
         {
383 383
             throw new \Exception('Error creating user!');
384 384
         }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
     public function getUserByResetHash($hash)
389 389
     {
390 390
         $users = $this->getUsersByFilter(new \Data\Filter("uniqueIdentifier eq $hash"));
391
-        if($users === false || !isset($users[0]))
391
+        if ($users === false || !isset($users[0]))
392 392
         {
393 393
             return false;
394 394
         }
Please login to merge, or discard this patch.
Auth/class.SQLAuthenticator.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace Auth;
3 3
 
4
-if(!function_exists('password_hash') || !function_exists('password_verify')) 
4
+if (!function_exists('password_hash') || !function_exists('password_verify')) 
5 5
 {
6 6
     define('PASSWORD_BCRYPT', 1);
7 7
     define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
@@ -9,22 +9,22 @@  discard block
 block discarded – undo
9 9
 
10 10
     function password_hash($password, $algo = PASSWORD_DEFAULT)
11 11
     {
12
-        if(is_null($password) || is_int($password))
12
+        if (is_null($password) || is_int($password))
13 13
         {
14 14
             $password = (string)$password;
15 15
         }
16
-        if(!is_string($password))
16
+        if (!is_string($password))
17 17
         {
18 18
             trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
19 19
             return false;
20 20
         }
21
-        if(!is_int($algo))
21
+        if (!is_int($algo))
22 22
         {
23
-            trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
23
+            trigger_error("password_hash() expects parameter 2 to be long, ".gettype($algo)." given", E_USER_WARNING);
24 24
             return false;
25 25
         }
26 26
         $resultLength = 0;
27
-        switch($algo)
27
+        switch ($algo)
28 28
         {
29 29
             case PASSWORD_BCRYPT:
30 30
                 $cost = PASSWORD_BCRYPT_DEFAULT_COST;
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
         $base64String = base64_encode($salt);
44 44
         $salt = strtr(rtrim($base64String, '='), $base64Digits, $bcrypt64Digits);
45 45
         $salt = substr($salt, 0, $requiredSaltLen);
46
-        $hash = $hashFormat . $salt;
46
+        $hash = $hashFormat.$salt;
47 47
         $ret = crypt($password, $hash);
48
-        if(!is_string($ret) || strlen($ret) != $resultLength)
48
+        if (!is_string($ret) || strlen($ret) != $resultLength)
49 49
         {
50 50
             return false;
51 51
         }
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
     function password_verify($password, $hash)
56 56
     {
57 57
         $ret = crypt($password, $hash);
58
-        if(!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13)
58
+        if (!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13)
59 59
         {
60 60
             return false;
61 61
         }
62 62
         $status = 0;
63 63
         $count  = strlen($ret);
64
-        for($i = 0; $i < $count; $i++)
64
+        for ($i = 0; $i < $count; $i++)
65 65
         {
66 66
             $status |= (ord($ret[$i]) ^ ord($hash[$i]));
67 67
         }
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
     {
81 81
         parent::__construct($params);
82 82
         $this->params = $params;
83
-        if($this->current)
83
+        if ($this->current)
84 84
         {
85 85
             $this->dataSet = $this->getCurrentDataSet();
86 86
         }
87
-        if($this->pending)
87
+        if ($this->pending)
88 88
         {
89 89
             $this->pendingDataSet = $this->getPendingDataSet();
90 90
         }
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     private function getCurrentDataSet()
97 97
     {
98
-        if(isset($this->params['current_data_set']))
98
+        if (isset($this->params['current_data_set']))
99 99
         {
100 100
             return \DataSetFactory::getDataSetByName($this->params['current_data_set']);
101 101
         }
@@ -107,30 +107,30 @@  discard block
 block discarded – undo
107 107
      */
108 108
     private function getPendingDataSet()
109 109
     {
110
-        if(isset($this->params['pending_data_set']))
110
+        if (isset($this->params['pending_data_set']))
111 111
         {
112 112
             return \DataSetFactory::getDataSetByName($this->params['pending_data_set']);
113 113
         }
114 114
         return \DataSetFactory::getDataSetByName('pending_authentication');
115 115
     }
116 116
 
117
-    private function getDataTable($name, $pending=false)
117
+    private function getDataTable($name, $pending = false)
118 118
     {
119
-         if(isset($this->dataTables[$name]) && isset($this->dataTables[$name][$pending]))
119
+         if (isset($this->dataTables[$name]) && isset($this->dataTables[$name][$pending]))
120 120
          {
121 121
              return $this->dataTables[$name][$pending];
122 122
          }
123 123
          $dataSet = $this->dataSet;
124
-         if($pending)
124
+         if ($pending)
125 125
          {
126 126
              $dataSet = $this->pendingDataSet;
127 127
          }
128
-         if($dataSet === null)
128
+         if ($dataSet === null)
129 129
          {
130 130
              throw new \Exception('Unable to obtain dataset for SQL Authentication!');
131 131
          }
132 132
          $dataTable = $dataSet[$name];
133
-         if(!isset($this->dataTables[$name]))
133
+         if (!isset($this->dataTables[$name]))
134 134
          {
135 135
              $this->dataTables[$name] = array();
136 136
          }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
     private function getPendingUserDataTable()
142 142
     {
143
-        if(isset($this->params['pending_user_table']))
143
+        if (isset($this->params['pending_user_table']))
144 144
         {
145 145
             return $this->getDataTable($this->params['pending_user_table'], true);
146 146
         }
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
 
150 150
     public function login($username, $password)
151 151
     {
152
-        if($this->current === false) return false;
152
+        if ($this->current === false) return false;
153 153
         $userDataTable = $this->getDataTable('user');
154 154
         $filter = new \Data\Filter("uid eq '$username'");
155 155
         $users = $userDataTable->read($filter);
156
-        if($users === false || !isset($users[0]))
156
+        if ($users === false || !isset($users[0]))
157 157
         {
158 158
             return false;
159 159
         }
160
-        if(password_verify($password, $users[0]['pass']))
160
+        if (password_verify($password, $users[0]['pass']))
161 161
         {
162 162
             return array('res'=>true, 'extended'=>$users[0]);
163 163
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
     public function isLoggedIn($data)
168 168
     {
169
-        if(isset($data['res']))
169
+        if (isset($data['res']))
170 170
         {
171 171
             return $data['res'];
172 172
         }
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 
176 176
     public function getUser($data)
177 177
     {
178
-        if(isset($this->params['current_data_set']))
178
+        if (isset($this->params['current_data_set']))
179 179
         {
180 180
             $data['current_data_set'] = $this->params['current_data_set'];
181 181
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $groupDataTable = $this->getDataTable('group');
188 188
         $filter = new \Data\Filter("gid eq '$name'");
189 189
         $groups = $groupDataTable->read($filter);
190
-        if($groups === false || !isset($groups[0]))
190
+        if ($groups === false || !isset($groups[0]))
191 191
         {
192 192
             return false;
193 193
         }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $userDataTable = $this->getDataTable('user');
200 200
         $filter = new \Data\Filter("uid eq '$name'");
201 201
         $users = $userDataTable->read($filter);
202
-        if($users === false || !isset($users[0]))
202
+        if ($users === false || !isset($users[0]))
203 203
         {
204 204
             return false;
205 205
         }
@@ -215,33 +215,33 @@  discard block
 block discarded – undo
215 215
     private function convertDataToClass($dataTableName, $className, $filter, $select, $top, $skip, $orderby)
216 216
     {
217 217
         $data = $this->getDataByFilter($dataTableName, $filter, $select, $top, $skip, $orderby);
218
-        if($data === false)
218
+        if ($data === false)
219 219
         {
220 220
             return false;
221 221
         }
222 222
         $count = count($data);
223
-        for($i = 0; $i < $count; $i++)
223
+        for ($i = 0; $i < $count; $i++)
224 224
         {
225 225
             $data[$i] = new $className($groups[$i]);
226 226
         }
227 227
         return $data;
228 228
     }
229 229
 
230
-    public function getGroupsByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false)
230
+    public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false)
231 231
     {
232 232
         return $this->convertDataToClass('group', 'SQLGroup', $filter, $select, $top, $skip, $orderby);
233 233
     }
234 234
 
235
-    public function getUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false)
235
+    public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false)
236 236
     {
237 237
         return $this->convertDataToClass('group', 'SQLUser', $filter, $select, $top, $skip, $orderby);
238 238
     }
239 239
 
240 240
     public function getPendingUserCount()
241 241
     {
242
-        if($this->pending === false) return 0;
242
+        if ($this->pending === false) return 0;
243 243
         $dataTable = $this->getPendingUserDataTable();
244
-        if($dataTable === null) return 0;
244
+        if ($dataTable === null) return 0;
245 245
         return $dataTable->count();
246 246
     }
247 247
 
@@ -249,26 +249,26 @@  discard block
 block discarded – undo
249 249
     {
250 250
         $userDataTable = $this->getPendingUserDataTable();
251 251
         $fieldData = $filter->to_mongo_filter();
252
-        $firstFilter = new \Data\Filter('substringof(data,"'.implode($fieldData,' ').'")');
252
+        $firstFilter = new \Data\Filter('substringof(data,"'.implode($fieldData, ' ').'")');
253 253
         $users = $userDataTable->read($firstFilter, $select, $top, $skip, $orderby);
254
-        if($users === false)
254
+        if ($users === false)
255 255
         {
256 256
             return false;
257 257
         }
258 258
         $ret = array();
259 259
         $count = count($users);
260
-        for($i = 0; $i < $count; $i++)
260
+        for ($i = 0; $i < $count; $i++)
261 261
         {
262 262
             $user = new SQLPendingUser($users[$i], $userDataTable);
263 263
             $err = false;
264
-            foreach($fieldData as $field=>$data)
264
+            foreach ($fieldData as $field=>$data)
265 265
             {
266
-                if(strcasecmp($user[$field], $data) !== 0)
266
+                if (strcasecmp($user[$field], $data) !== 0)
267 267
                 {
268 268
                     $err = true; break;
269 269
                 }
270 270
             }
271
-            if(!$err)
271
+            if (!$err)
272 272
             {
273 273
                 array_push($ret, $user);
274 274
             }
@@ -276,22 +276,22 @@  discard block
 block discarded – undo
276 276
         return $ret;
277 277
     }
278 278
 
279
-    public function getPendingUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false)
279
+    public function getPendingUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false)
280 280
 
281 281
     {
282
-        if($this->pending === false) return false;
283
-        if($filter !== false && !$filter->contains('hash'))
282
+        if ($this->pending === false) return false;
283
+        if ($filter !== false && !$filter->contains('hash'))
284 284
         {
285 285
             return $this->searchPendingUsers($filter, $select, $top, $skip, $orderby);
286 286
         }
287 287
         $userDataTable = $this->getPendingUserDataTable();
288 288
         $users = $userDataTable->read($filter, $select, $top, $skip, $orderby);
289
-        if($users === false)
289
+        if ($users === false)
290 290
         {
291 291
             return false;
292 292
         }
293 293
         $count = count($users);
294
-        for($i = 0; $i < $count; $i++)
294
+        for ($i = 0; $i < $count; $i++)
295 295
         {
296 296
             $users[$i] = new SQLPendingUser($users[$i], $userDataTable);
297 297
         }
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
 
301 301
     public function createPendingUser($user)
302 302
     {
303
-        if($this->pending === false) return false;
303
+        if ($this->pending === false) return false;
304 304
         $userDataTable = $this->getPendingUserDataTable();
305
-        if(isset($user->password2))
305
+        if (isset($user->password2))
306 306
         {
307 307
             unset($user->password2);
308 308
         }
@@ -310,10 +310,10 @@  discard block
 block discarded – undo
310 310
         $hash = hash('sha512', $json);
311 311
         $array = array('hash'=>$hash, 'data'=>$json);
312 312
         $ret = $userDataTable->create($array);
313
-        if($ret !== false)
313
+        if ($ret !== false)
314 314
         {
315 315
             $users = $this->getPendingUsersByFilter(new \Data\Filter("hash eq '$hash'"));
316
-            if($users === false || !isset($users[0]))
316
+            if ($users === false || !isset($users[0]))
317 317
             {
318 318
                 throw new \Exception('Error retreiving user object after successful create!');
319 319
             }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
     public function getTempUserByHash($hash)
326 326
     {
327 327
         $users = $this->getPendingUsersByFilter(new \Data\Filter("hash eq '$hash'"));
328
-        if($users === false || !isset($users[0]))
328
+        if ($users === false || !isset($users[0]))
329 329
         {
330 330
             return false;
331 331
         }
Please login to merge, or discard this patch.
Auth/class.SQLUser.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
     private $data;
7 7
     private $auth;
8 8
 
9
-    function __construct($data=false, $auth=false)
9
+    function __construct($data = false, $auth = false)
10 10
     {
11 11
         $this->data = array();
12 12
         $this->auth = $auth;
13
-        if($data !== false)
13
+        if ($data !== false)
14 14
         {
15 15
             $this->data = $data;
16
-            if(isset($data['extended']))
16
+            if (isset($data['extended']))
17 17
             {
18 18
                 $this->data = $data['extended'];
19 19
             }
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         $uid = $this->getUid();
28 28
         $filter = new \Data\Filter("uid eq '$uid' and gid eq '$name'");
29 29
         $groups = $group_data_table->read($filter);
30
-        if($groups === false || !isset($groups[0]))
30
+        if ($groups === false || !isset($groups[0]))
31 31
         {
32 32
             return false;
33 33
         }
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     function getEmail()
39 39
     {
40
-        if(isset($this->data['mail']))
40
+        if (isset($this->data['mail']))
41 41
         {
42 42
              return $this->data['mail'];
43 43
         }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
     function getUid()
48 48
     {
49
-        if(isset($this->data['uid']))
49
+        if (isset($this->data['uid']))
50 50
         {
51 51
             return $this->data['uid'];
52 52
         }
Please login to merge, or discard this patch.