@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | public function __construct($params) |
11 | 11 | { |
12 | 12 | parent::__construct($params); |
13 | - if(!isset($params['client_secrets_path'])) |
|
13 | + if (!isset($params['client_secrets_path'])) |
|
14 | 14 | { |
15 | 15 | throw new \Exception('Missing required parameter client_secrets_path!'); |
16 | 16 | } |
17 | - if(!isset($params['redirect_url'])) |
|
17 | + if (!isset($params['redirect_url'])) |
|
18 | 18 | { |
19 | 19 | $params['redirect_url'] = 'https://'.$_SERVER['HTTP_HOST'].'/oauth2callback.php?src=google'; |
20 | 20 | } |
@@ -34,21 +34,21 @@ discard block |
||
34 | 34 | public function authenticate($code, &$currentUser = false) |
35 | 35 | { |
36 | 36 | $googleUser = false; |
37 | - try{ |
|
37 | + try { |
|
38 | 38 | $this->client->authenticate($code); |
39 | 39 | $this->token = $this->client->getAccessToken(); |
40 | 40 | \FlipSession::setVar('GoogleToken', $this->token); |
41 | 41 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
42 | 42 | $googleUser = $oauth2Service->userinfo->get(); |
43 | - } catch(\Exception $ex) { |
|
43 | + } catch (\Exception $ex) { |
|
44 | 44 | return self::LOGIN_FAILED; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $auth = \AuthProvider::getInstance(); |
48 | 48 | $localUsers = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$googleUser->email)); |
49 | - if($localUsers !== false && isset($localUsers[0])) |
|
49 | + if ($localUsers !== false && isset($localUsers[0])) |
|
50 | 50 | { |
51 | - if($localUsers[0]->canLoginWith('google.com')) |
|
51 | + if ($localUsers[0]->canLoginWith('google.com')) |
|
52 | 52 | { |
53 | 53 | $auth->impersonateUser($localUsers[0]); |
54 | 54 | return self::SUCCESS; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $user->setLastName($googleUser->familyName); |
65 | 65 | $user->addLoginProvider('google.com'); |
66 | 66 | $ret = $auth->activatePendingUser($user); |
67 | - if($ret === false) |
|
67 | + if ($ret === false) |
|
68 | 68 | { |
69 | 69 | throw new \Exception('Unable to create user! '.$res); |
70 | 70 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | public function getUser($data = false) |
76 | 76 | { |
77 | - if($data === false) |
|
77 | + if ($data === false) |
|
78 | 78 | { |
79 | 79 | $data = $this->token; |
80 | 80 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $profileUser['displayName'] = $googleUser->name; |
90 | 90 | $profileUser['jpegPhoto'] = base64_encode(file_get_contents($googleUser->picture)); |
91 | 91 | return $profileUser; |
92 | - } catch(\Exception $e) |
|
92 | + } catch (\Exception $e) |
|
93 | 93 | { |
94 | 94 | return false; |
95 | 95 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | namespace Auth\OAuth2; |
15 | 15 | |
16 | 16 | /** Only load the HTTPFul bootstrap if it isn't already loaded*/ |
17 | -if(!class_exists('Httpful\Request')) |
|
17 | +if (!class_exists('Httpful\Request')) |
|
18 | 18 | { |
19 | 19 | require('/var/www/common/libs/httpful/bootstrap.php'); |
20 | 20 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function __construct($params) |
38 | 38 | { |
39 | 39 | parent::__construct($params); |
40 | - if(!isset($params['redirect_url'])) |
|
40 | + if (!isset($params['redirect_url'])) |
|
41 | 41 | { |
42 | 42 | $this->redirect_uri = 'https://'.$_SERVER['HTTP_HOST'].'/oauth/callbacks/'.$this->getHostName(); |
43 | 43 | } |
@@ -115,21 +115,21 @@ discard block |
||
115 | 115 | public function authenticate($params, &$current_user) |
116 | 116 | { |
117 | 117 | $resp = $this->doAuthPost($params); |
118 | - if($resp->hasErrors()) |
|
118 | + if ($resp->hasErrors()) |
|
119 | 119 | { |
120 | 120 | return self::LOGIN_FAILED; |
121 | 121 | } |
122 | 122 | \FlipSession::setVar('OAuthToken', $resp->body); |
123 | 123 | $user = $this->getUserFromToken($resp->body); |
124 | - if($user === false) |
|
124 | + if ($user === false) |
|
125 | 125 | { |
126 | 126 | return self::LOGIN_FAILED; |
127 | 127 | } |
128 | 128 | $auth = \AuthProvider::getInstance(); |
129 | 129 | $local_users = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$user->getEmail())); |
130 | - if($local_users !== false && isset($local_users[0])) |
|
130 | + if ($local_users !== false && isset($local_users[0])) |
|
131 | 131 | { |
132 | - if($local_users[0]->canLoginWith($this->getHostName())) |
|
132 | + if ($local_users[0]->canLoginWith($this->getHostName())) |
|
133 | 133 | { |
134 | 134 | $auth->impersonateUser($local_users[0]); |
135 | 135 | return self::SUCCESS; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | return self::ALREADY_PRESENT; |
139 | 139 | } |
140 | 140 | $ret = $auth->activatePendingUser($user); |
141 | - if($ret === false) |
|
141 | + if ($ret === false) |
|
142 | 142 | { |
143 | 143 | throw new \Exception('Unable to create user! '.$res); |
144 | 144 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function getUserFromToken($token) |
32 | 32 | { |
33 | - if($token === false) |
|
33 | + if ($token === false) |
|
34 | 34 | { |
35 | 35 | $token = \FlipSession::getVar('OAuthToken'); |
36 | 36 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | |
26 | 26 | public function getUserFromToken($token) |
27 | 27 | { |
28 | - if($token === false) |
|
28 | + if ($token === false) |
|
29 | 29 | { |
30 | 30 | $token = \FlipSession::getVar('OAuthToken'); |
31 | 31 | } |
32 | 32 | $resp = \Httpful\Request::get('https://api.github.com/user')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
33 | 33 | $github_user = $resp->body; |
34 | 34 | $user = new \Auth\PendingUser(); |
35 | - if(isset($github_user->name)) |
|
35 | + if (isset($github_user->name)) |
|
36 | 36 | { |
37 | 37 | $name = explode(' ', $github_user->name); |
38 | 38 | $user->setGivenName($name[0]); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function login($username, $password) |
48 | 48 | { |
49 | 49 | $resp = \Httpful\Request::post('https://profiles.test.burningflipside.com/api/v1/login?username='.urlencode($username).'&password='.urlencode($password))->send(); |
50 | - if($resp->hasErrors()) |
|
50 | + if ($resp->hasErrors()) |
|
51 | 51 | { |
52 | 52 | return false; |
53 | 53 | } |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | public function isLoggedIn($data) |
60 | 60 | { |
61 | - if(isset($this->user)) |
|
61 | + if (isset($this->user)) |
|
62 | 62 | { |
63 | 63 | return true; |
64 | 64 | } |
65 | - if(isset($data['res'])) |
|
65 | + if (isset($data['res'])) |
|
66 | 66 | { |
67 | 67 | return $data['res']; |
68 | 68 | } |
@@ -30,14 +30,14 @@ |
||
30 | 30 | |
31 | 31 | public function getUserFromToken($token) |
32 | 32 | { |
33 | - if($token === false) |
|
33 | + if ($token === false) |
|
34 | 34 | { |
35 | 35 | $token = \FlipSession::getVar('OAuthToken'); |
36 | 36 | } |
37 | 37 | $resp = \Httpful\Request::get('https://api.github.com/user')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
38 | 38 | $github_user = $resp->body; |
39 | 39 | $user = new \Auth\PendingUser(); |
40 | - if(isset($github_user->name)) |
|
40 | + if (isset($github_user->name)) |
|
41 | 41 | { |
42 | 42 | $name = explode(' ', $github_user->name); |
43 | 43 | $user->setGivenName($name[0]); |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | public function isLoggedIn($data) |
12 | 12 | { |
13 | - if(isset($data['res'])) |
|
13 | + if (isset($data['res'])) |
|
14 | 14 | { |
15 | 15 | return $data['res']; |
16 | 16 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @SuppressWarnings("UnusedFormalParameter") |
104 | 104 | */ |
105 | - public function getGroupsByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false) |
|
105 | + public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
|
106 | 106 | { |
107 | 107 | return false; |
108 | 108 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @SuppressWarnings("UnusedFormalParameter") |
122 | 122 | */ |
123 | - public function getUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false) |
|
123 | + public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
|
124 | 124 | { |
125 | 125 | return false; |
126 | 126 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @SuppressWarnings("UnusedFormalParameter") |
140 | 140 | */ |
141 | - public function getPendingUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false) |
|
141 | + public function getPendingUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
|
142 | 142 | { |
143 | 143 | return false; |
144 | 144 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function getActiveUserCount() |
152 | 152 | { |
153 | 153 | $users = $this->getUsersByFilter(false); |
154 | - if($users === false) |
|
154 | + if ($users === false) |
|
155 | 155 | { |
156 | 156 | return 0; |
157 | 157 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | public function getPendingUserCount() |
167 | 167 | { |
168 | 168 | $users = $this->getPendingUsersByFilter(false); |
169 | - if($users === false) |
|
169 | + if ($users === false) |
|
170 | 170 | { |
171 | 171 | return 0; |
172 | 172 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | public function getGroupCount() |
182 | 182 | { |
183 | 183 | $groups = $this->getGroupsByFilter(false); |
184 | - if($groups === false) |
|
184 | + if ($groups === false) |
|
185 | 185 | { |
186 | 186 | return 0; |
187 | 187 | } |
@@ -25,7 +25,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 = ''; |
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 |
||
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 | } |
@@ -293,12 +293,12 @@ discard block |
||
293 | 293 | return $this->post($uri, $handler); |
294 | 294 | } |
295 | 295 | |
296 | - function get_json_body($array=false) |
|
296 | + function get_json_body($array = false) |
|
297 | 297 | { |
298 | 298 | return $this->getJsonBody($array); |
299 | 299 | } |
300 | 300 | |
301 | - function getJsonBody($array=false) |
|
301 | + function getJsonBody($array = false) |
|
302 | 302 | { |
303 | 303 | $body = $this->request->getBody(); |
304 | 304 | return json_decode($body, $array); |
@@ -26,16 +26,16 @@ |
||
26 | 26 | { |
27 | 27 | $namespace = substr($classname, 0, $lastNsPos); |
28 | 28 | $classname = substr($classname, $lastNsPos + 1); |
29 | - $filename = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; |
|
29 | + $filename = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR; |
|
30 | 30 | } |
31 | 31 | $filename = __DIR__.DIRECTORY_SEPARATOR.$filename.'class.'.$classname.'.php'; |
32 | - if(is_readable($filename)) |
|
32 | + if (is_readable($filename)) |
|
33 | 33 | { |
34 | 34 | require $filename; |
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | -if(version_compare(PHP_VERSION, '5.3.0', '>=')) |
|
38 | +if (version_compare(PHP_VERSION, '5.3.0', '>=')) |
|
39 | 39 | { |
40 | 40 | spl_autoload_register('FlipsideAutoload', true, true); |
41 | 41 | } |