Completed
Push — master ( b7fcec...fe4315 )
by Nazar
04:06
created
components/modules/Disqus/events/enabled.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 Event::instance()->on(
20 20
 	'Comments/instance',
21 21
 	function ($data) {
22
-		$data['Comments']	= Disqus::instance();
22
+		$data['Comments'] = Disqus::instance();
23 23
 		return false;
24 24
 	}
25 25
 );
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package		Disqus
4
- * @category	modules
5
- * @author		Nazar Mokrynskyi <[email protected]>
6
- * @copyright	Copyright (c) 2013-2016, Nazar Mokrynskyi
7
- * @license		MIT License, see license.txt
8
- */
3
+	 * @package		Disqus
4
+	 * @category	modules
5
+	 * @author		Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright	Copyright (c) 2013-2016, Nazar Mokrynskyi
7
+	 * @license		MIT License, see license.txt
8
+	 */
9 9
 /**
10
- * Supports next events:
11
- *  Comments/instance
12
- *  [
13
- *   'Comments'		=> <i>&$Comments</i>
14
- *  ]
15
- */
10
+	 * Supports next events:
11
+	 *  Comments/instance
12
+	 *  [
13
+	 *   'Comments'		=> <i>&$Comments</i>
14
+	 *  ]
15
+	 */
16 16
 namespace	cs\modules\Disqus;
17 17
 use
18 18
 	cs\Event;
Please login to merge, or discard this patch.
components/modules/Http_server/custom_loader.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@
 block discarded – undo
11 11
  * but do not call any class to leave that all for Http server
12 12
  */
13 13
 namespace cs\modules\Http_server;
14
-require DIR.'/core/loader_base.php';             //Inclusion of loader base
14
+require DIR.'/core/loader_base.php'; //Inclusion of loader base
15 15
 @ini_set('error_log', LOGS.'/Http_server.log');
16
-require __DIR__.'/functions.php';                //Inclusion of functions needed for http server
16
+require __DIR__.'/functions.php'; //Inclusion of functions needed for http server
17 17
 \cs\Singleton\clean_classes_cache();
18
-require __DIR__.'/Request.php';                  //Inclusion of Request class, used for http server requests processing
19
-require __DIR__.'/Singleton.php';                //Inclusion of `Singleton` trait, specific for http server
20
-require __DIR__.'/Config.php';                   //Inclusion of `cs\custom\Config` class, which is used instead original `cs\Config` for http server
21
-require __DIR__.'/User.php';                     //Inclusion of `cs\custom\User` class, which is used instead original `cs\User` for http server
18
+require __DIR__.'/Request.php'; //Inclusion of Request class, used for http server requests processing
19
+require __DIR__.'/Singleton.php'; //Inclusion of `Singleton` trait, specific for http server
20
+require __DIR__.'/Config.php'; //Inclusion of `cs\custom\Config` class, which is used instead original `cs\Config` for http server
21
+require __DIR__.'/User.php'; //Inclusion of `cs\custom\User` class, which is used instead original `cs\User` for http server
22 22
 /**
23 23
  * Including of custom files
24 24
  */
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   Http server
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   Http server
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 /**
10
- * This is custom loader that includes basic files and defines constants,
11
- * but do not call any class to leave that all for Http server
12
- */
10
+	 * This is custom loader that includes basic files and defines constants,
11
+	 * but do not call any class to leave that all for Http server
12
+	 */
13 13
 namespace cs\modules\Http_server;
14 14
 require DIR.'/core/loader_base.php';             //Inclusion of loader base
15 15
 @ini_set('error_log', LOGS.'/Http_server.log');
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 require __DIR__.'/Config.php';                   //Inclusion of `cs\custom\Config` class, which is used instead original `cs\Config` for http server
21 21
 require __DIR__.'/User.php';                     //Inclusion of `cs\custom\User` class, which is used instead original `cs\User` for http server
22 22
 /**
23
- * Including of custom files
24
- */
23
+	 * Including of custom files
24
+	 */
25 25
 foreach (glob(CUSTOM.'/*.php') ?: [] as $custom) {
26 26
 	include $custom;
27 27
 }
Please login to merge, or discard this patch.
components/modules/Http_server/functions.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return object[]
44 44
 	 */
45
-	function &objects_pool ($request_id, $update_objects_pool = null) {
45
+	function &objects_pool($request_id, $update_objects_pool = null) {
46 46
 		static $objects_pool = [];
47 47
 		if (!isset($objects_pool[$request_id])) {
48 48
 			$objects_pool[$request_id] = [];
@@ -327,10 +327,10 @@  discard block
 block discarded – undo
327 327
 			 * Try to load classes from different places. If not found in one place - try in another.
328 328
 			 */
329 329
 			if (
330
-				_require_once($file = DIR."/core/classes/$namespace/$class_name.php", false) ||    //Core classes
330
+				_require_once($file = DIR."/core/classes/$namespace/$class_name.php", false) || //Core classes
331 331
 				_require_once($file = DIR."/core/thirdparty/$namespace/$class_name.php", false) || //Third party classes
332
-				_require_once($file = DIR."/core/traits/$namespace/$class_name.php", false) ||     //Core traits
333
-				_require_once($file = ENGINES."/$namespace/$class_name.php", false) ||             //Core engines
332
+				_require_once($file = DIR."/core/traits/$namespace/$class_name.php", false) || //Core traits
333
+				_require_once($file = ENGINES."/$namespace/$class_name.php", false) || //Core engines
334 334
 				_require_once($file = MODULES."/../$namespace/$class_name.php", false)             //Classes in modules and plugins
335 335
 			) {
336 336
 				$cache[$class] = realpath($file);
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   Http server
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   Http server
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 namespace cs\modules\Http_server;
10 10
 use
11 11
 	ArrayAccess,
Please login to merge, or discard this patch.
components/modules/Http_server/run_server.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@
 block discarded – undo
11 11
 /**
12 12
  * Time of start of execution, is used as current time
13 13
  */
14
-define('MICROTIME', microtime(true));         //Time in seconds (float)
15
-define('TIME', floor(MICROTIME));             //Time in seconds (integer)
14
+define('MICROTIME', microtime(true)); //Time in seconds (float)
15
+define('TIME', floor(MICROTIME)); //Time in seconds (integer)
16 16
 define('DIR', realpath(__DIR__.'/../../..')); //Root directory
17 17
 chdir(DIR);
18 18
 $async = false;
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   Http server
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   Http server
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 use
10 10
 	cs\modules\Http_server\Request;
11 11
 /**
12
- * Time of start of execution, is used as current time
13
- */
12
+	 * Time of start of execution, is used as current time
13
+	 */
14 14
 define('MICROTIME', microtime(true));         //Time in seconds (float)
15 15
 define('TIME', floor(MICROTIME));             //Time in seconds (integer)
16 16
 define('DIR', realpath(__DIR__.'/../../..')); //Root directory
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 	}
27 27
 }
28 28
 /**
29
- * Whether server should be ready for asynchronous processing (is not - more optimizations might be applied)
30
- */
29
+	 * Whether server should be ready for asynchronous processing (is not - more optimizations might be applied)
30
+	 */
31 31
 define('ASYNC_HTTP_SERVER', $async);
32 32
 unset($async);
33 33
 require_once __DIR__.'/custom_loader.php';
34 34
 /**
35
- * Manually require composer autoloader because otherwise it will be included much later
36
- */
35
+	 * Manually require composer autoloader because otherwise it will be included much later
36
+	 */
37 37
 require_once STORAGE.'/Composer/vendor/autoload.php';
38 38
 $loop   = React\EventLoop\Factory::create();
39 39
 $socket = new React\Socket\Server($loop);
Please login to merge, or discard this patch.
components/modules/HybridAuth/events/enabled.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
 						return strtolower($provider);
30 30
 				}
31 31
 			};
32
-			$providers     = [];
32
+			$providers = [];
33 33
 			foreach ($Config->module('HybridAuth')->providers as $provider => $provider_settings) {
34 34
 				if ($provider_settings['enabled']) {
35 35
 					$providers[$provider] = [
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   HybridAuth
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2012-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   HybridAuth
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2012-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 namespace	cs;
10 10
 Event::instance()->on(
11 11
 	'admin/System/components/modules/install/after',
Please login to merge, or discard this patch.
components/modules/HybridAuth/events/uninstalled.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,6 +13,6 @@
 block discarded – undo
13 13
 		if ($data['name'] != 'HybridAuth') {
14 14
 			return;
15 15
 		}
16
-		Config::instance()->module('HybridAuth')->providers	= [];
16
+		Config::instance()->module('HybridAuth')->providers = [];
17 17
 	}
18 18
 );
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   HybridAuth
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2012-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   HybridAuth
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2012-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 namespace	cs;
10 10
 Event::instance()->on(
11 11
 	'admin/System/components/modules/install/after',
Please login to merge, or discard this patch.
components/modules/OAuth2/authorize.php 2 patches
Switch Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -233,86 +233,86 @@
 block discarded – undo
233 233
 	return;
234 234
 }
235 235
 switch ($_GET['response_type']) {
236
-	case 'code':
237
-		_header(
238
-			'Location: '.http_build_url(
239
-				urldecode($redirect_uri),
240
-				[
241
-					'code'  => $code,
242
-					'state' => isset($_GET['state']) ? $_GET['state'] : false
243
-				]
244
-			),
245
-			true,
246
-			302
247
-		);
248
-		$Page->Content = '';
249
-		return;
250
-	case 'token':
251
-		$token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], $redirect_uri);
252
-		if ($token_data) {
253
-			unset($token_data['refresh_token']);
236
+		case 'code':
254 237
 			_header(
255
-				'Location: '.uri_for_token(
256
-					http_build_url(
257
-						urldecode($redirect_uri),
258
-						array_merge(
259
-							$token_data,
260
-							[
261
-								'state' => isset($_GET['state']) ? $_GET['state'] : false
262
-							]
263
-						)
264
-					)
238
+				'Location: '.http_build_url(
239
+					urldecode($redirect_uri),
240
+					[
241
+						'code'  => $code,
242
+						'state' => isset($_GET['state']) ? $_GET['state'] : false
243
+					]
265 244
 				),
266 245
 				true,
267 246
 				302
268 247
 			);
269 248
 			$Page->Content = '';
270 249
 			return;
271
-		} else {
272
-			error_redirect('server_error', "Server can't get token data, try later");
273
-			return;
274
-		}
275
-	case 'guest_token':
276
-		_header('Cache-Control: no-store');
277
-		_header('Pragma: no-cache');
278
-		interface_off();
279
-		if ($User->user()) {
280
-			$e = new ExitException(
281
-				[
282
-					'access_denied',
283
-					'Only guests, not users allowed to access this response_type'
284
-				],
285
-				403
286
-			);
287
-			$e->setJson();
288
-			throw $e;
289
-		}
290
-		$code = $OAuth2->add_code($client['id'], 'token', urldecode($_GET['redirect_uri']));
291
-		if (!$code) {
292
-			$e = new ExitException(
293
-				[
294
-					'server_error',
295
-					"Server can't generate code, try later"
296
-				],
297
-				500
298
-			);
299
-			$e->setJson();
300
-			throw $e;
301
-		}
302
-		$token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], urldecode($_GET['redirect_uri']));
303
-		if ($token_data) {
304
-			unset($token_data['refresh_token']);
305
-			$Page->json($token_data);
306
-			return;
307
-		} else {
308
-			$e = new ExitException(
309
-				[
310
-					'server_error',
311
-					"Server can't get token data, try later"
312
-				],
313
-				500
314
-			);
315
-			$e->setJson();
316
-			throw $e;
317
-		}
250
+		case 'token':
251
+			$token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], $redirect_uri);
252
+			if ($token_data) {
253
+				unset($token_data['refresh_token']);
254
+				_header(
255
+					'Location: '.uri_for_token(
256
+						http_build_url(
257
+							urldecode($redirect_uri),
258
+							array_merge(
259
+								$token_data,
260
+								[
261
+									'state' => isset($_GET['state']) ? $_GET['state'] : false
262
+								]
263
+							)
264
+						)
265
+					),
266
+					true,
267
+					302
268
+				);
269
+				$Page->Content = '';
270
+				return;
271
+			} else {
272
+				error_redirect('server_error', "Server can't get token data, try later");
273
+				return;
274
+			}
275
+		case 'guest_token':
276
+			_header('Cache-Control: no-store');
277
+			_header('Pragma: no-cache');
278
+			interface_off();
279
+			if ($User->user()) {
280
+				$e = new ExitException(
281
+					[
282
+						'access_denied',
283
+						'Only guests, not users allowed to access this response_type'
284
+					],
285
+					403
286
+				);
287
+				$e->setJson();
288
+				throw $e;
289
+			}
290
+			$code = $OAuth2->add_code($client['id'], 'token', urldecode($_GET['redirect_uri']));
291
+			if (!$code) {
292
+				$e = new ExitException(
293
+					[
294
+						'server_error',
295
+						"Server can't generate code, try later"
296
+					],
297
+					500
298
+				);
299
+				$e->setJson();
300
+				throw $e;
301
+			}
302
+			$token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], urldecode($_GET['redirect_uri']));
303
+			if ($token_data) {
304
+				unset($token_data['refresh_token']);
305
+				$Page->json($token_data);
306
+				return;
307
+			} else {
308
+				$e = new ExitException(
309
+					[
310
+						'server_error',
311
+						"Server can't get token data, try later"
312
+					],
313
+					500
314
+				);
315
+				$e->setJson();
316
+				throw $e;
317
+			}
318 318
 }
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   OAuth2
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   OAuth2
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 /**
10
- * Provides next events:<br>
11
- *  OAuth2/custom_sign_in_page
12
- *  OAuth2/custom_allow_access_page
13
- */
10
+	 * Provides next events:<br>
11
+	 *  OAuth2/custom_sign_in_page
12
+	 *  OAuth2/custom_allow_access_page
13
+	 */
14 14
 namespace cs\modules\OAuth2;
15 15
 use
16 16
 	h,
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 $L      = new Prefix('oauth2_');
47 47
 $Page   = Page::instance();
48 48
 /**
49
- * Errors processing
50
- */
49
+	 * Errors processing
50
+	 */
51 51
 if (!isset($_GET['client_id'])) {
52 52
 	error_redirect('invalid_request', 'client_id parameter required');
53 53
 	return;
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 	}
116 116
 }
117 117
 /**
118
- * guest_token should return JSON data while all other works with redirects
119
- */
118
+	 * guest_token should return JSON data while all other works with redirects
119
+	 */
120 120
 if ($_GET['response_type'] != 'guest_token') {
121 121
 	if (!isset($_GET['redirect_uri'])) {
122 122
 		$e = new ExitException(
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 	}
190 190
 }
191 191
 /**
192
- * Authorization processing
193
- */
192
+	 * Authorization processing
193
+	 */
194 194
 if (isset($_POST['mode'])) {
195 195
 	switch ($_POST['mode']) {
196 196
 		case 'allow':
Please login to merge, or discard this patch.
components/modules/OAuth2/prepare.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,19 +31,19 @@
 block discarded – undo
31 31
  * @return string
32 32
  */
33 33
 function http_build_url ($url, $parts) {
34
-	$url	= explode('?', $url, 2);
35
-	$params	= [];
34
+	$url = explode('?', $url, 2);
35
+	$params = [];
36 36
 	if (isset($url[1])) {
37 37
 		foreach (explode('&', $url[1]) as $u) {
38
-			$params[]	= $u;
38
+			$params[] = $u;
39 39
 		}
40 40
 		unset($u, $url[1]);
41 41
 	}
42
-	$url	= $url[0];
42
+	$url = $url[0];
43 43
 	foreach ($parts as $name => $value) {
44
-		$params[]	= $name.'='.urlencode($value);
44
+		$params[] = $name.'='.urlencode($value);
45 45
 	}
46 46
 	unset($parts, $p);
47
-	$params	= array_unique($params);
47
+	$params = array_unique($params);
48 48
 	return "$url?".implode('&', $params);
49 49
 }
Please login to merge, or discard this patch.
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package		OAuth2
4
- * @category	modules
5
- * @author		Nazar Mokrynskyi <[email protected]>
6
- * @copyright	Copyright (c) 2011-2016, Nazar Mokrynskyi
7
- * @license		MIT License, see license.txt
8
- */
3
+	 * @package		OAuth2
4
+	 * @category	modules
5
+	 * @author		Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright	Copyright (c) 2011-2016, Nazar Mokrynskyi
7
+	 * @license		MIT License, see license.txt
8
+	 */
9 9
 namespace	cs\modules\OAuth2;
10 10
 /**
11
- * Just replaces first "?" symbol by "#"
12
- *
13
- * @param string	$str
14
- *
15
- * @return string
16
- */
11
+	 * Just replaces first "?" symbol by "#"
12
+	 *
13
+	 * @param string	$str
14
+	 *
15
+	 * @return string
16
+	 */
17 17
 function uri_for_token ($str) {
18 18
 	return implode(
19 19
 		'#',
@@ -25,11 +25,11 @@  discard block
 block discarded – undo
25 25
 	);
26 26
 }
27 27
 /**
28
- * @param string	$url
29
- * @param string[]	$parts
30
- *
31
- * @return string
32
- */
28
+	 * @param string	$url
29
+	 * @param string[]	$parts
30
+	 *
31
+	 * @return string
32
+	 */
33 33
 function http_build_url ($url, $parts) {
34 34
 	$url	= explode('?', $url, 2);
35 35
 	$params	= [];
Please login to merge, or discard this patch.
components/modules/OAuth2/token.php 2 patches
Switch Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -142,118 +142,118 @@
 block discarded – undo
142 142
  * Tokens operations processing
143 143
  */
144 144
 switch ($_POST['grant_type']) {
145
-	case 'authorization_code':
146
-		if (!isset($_POST['code'])) {
147
-			$e = new ExitException(
148
-				[
149
-					'invalid_request',
150
-					'code parameter required'
151
-				],
152
-				400
153
-			);
154
-			$e->setJson();
155
-			throw $e;
156
-		}
157
-		$token_data = $OAuth2->get_code($_POST['code'], $client['id'], $client['secret'], urldecode($_POST['redirect_uri']));
158
-		if (!$token_data) {
159
-			$e = new ExitException(
160
-				[
161
-					'access_denied',
162
-					"Server can't get token data, check parameters and try again"
163
-				],
164
-				403
165
-			);
166
-			$e->setJson();
167
-			throw $e;
168
-		}
169
-		if ($token_data['expires_in'] < 0) {
170
-			$e = new ExitException(
171
-				[
172
-					'access_denied',
173
-					'access_token expired'
174
-				],
175
-				403
176
-			);
177
-			$e->setJson();
178
-			throw $e;
179
-		}
180
-		$Page->json($token_data);
181
-		return;
182
-	case 'refresh_token':
183
-		if (!isset($_POST['refresh_token'])) {
184
-			$e = new ExitException(
185
-				[
186
-					'invalid_request',
187
-					'refresh_token parameter required'
188
-				],
189
-				400
190
-			);
191
-			$e->setJson();
192
-			throw $e;
193
-		}
194
-		$token_data = $OAuth2->refresh_token($_POST['refresh_token'], $client['id'], $client['secret']);
195
-		if (!$token_data) {
196
-			$e = new ExitException(
197
-				[
198
-					'access_denied',
199
-					'User session invalid'
200
-				],
201
-				403
202
-			);
203
-			$e->setJson();
204
-			throw $e;
205
-		}
206
-		$Page->json($token_data);
207
-		return;
208
-	case 'guest_token':
209
-		if (User::instance()->user()) {
210
-			$e = new ExitException(
211
-				[
212
-					'access_denied',
213
-					'Only guests, not user allowed to access this grant_type'
214
-				],
215
-				403
216
-			);
217
-			$e->setJson();
218
-			throw $e;
219
-		}
220
-		if (!$Config->module('OAuth2')->guest_tokens) {
221
-			$e = new ExitException(
222
-				[
223
-					'access_denied',
224
-					'Guest tokens disabled'
225
-				],
226
-				403
227
-			);
228
-			$e->setJson();
229
-			throw $e;
230
-		}
231
-		$code = $OAuth2->add_code($client['id'], 'code', '');
232
-		if (!$code) {
233
-			$e = new ExitException(
234
-				[
235
-					'server_error',
236
-					"Server can't generate code, try later"
237
-				],
238
-				500
239
-			);
240
-			$e->setJson();
241
-			throw $e;
242
-		}
243
-		$token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], '');
244
-		if ($token_data) {
245
-			unset($token_data['refresh_token']);
145
+		case 'authorization_code':
146
+			if (!isset($_POST['code'])) {
147
+				$e = new ExitException(
148
+					[
149
+						'invalid_request',
150
+						'code parameter required'
151
+					],
152
+					400
153
+				);
154
+				$e->setJson();
155
+				throw $e;
156
+			}
157
+			$token_data = $OAuth2->get_code($_POST['code'], $client['id'], $client['secret'], urldecode($_POST['redirect_uri']));
158
+			if (!$token_data) {
159
+				$e = new ExitException(
160
+					[
161
+						'access_denied',
162
+						"Server can't get token data, check parameters and try again"
163
+					],
164
+					403
165
+				);
166
+				$e->setJson();
167
+				throw $e;
168
+			}
169
+			if ($token_data['expires_in'] < 0) {
170
+				$e = new ExitException(
171
+					[
172
+						'access_denied',
173
+						'access_token expired'
174
+					],
175
+					403
176
+				);
177
+				$e->setJson();
178
+				throw $e;
179
+			}
246 180
 			$Page->json($token_data);
247 181
 			return;
248
-		} else {
249
-			$e = new ExitException(
250
-				[
251
-					'server_error',
252
-					"Server can't get token data, try later"
253
-				],
254
-				500
255
-			);
256
-			$e->setJson();
257
-			throw $e;
258
-		}
182
+		case 'refresh_token':
183
+			if (!isset($_POST['refresh_token'])) {
184
+				$e = new ExitException(
185
+					[
186
+						'invalid_request',
187
+						'refresh_token parameter required'
188
+					],
189
+					400
190
+				);
191
+				$e->setJson();
192
+				throw $e;
193
+			}
194
+			$token_data = $OAuth2->refresh_token($_POST['refresh_token'], $client['id'], $client['secret']);
195
+			if (!$token_data) {
196
+				$e = new ExitException(
197
+					[
198
+						'access_denied',
199
+						'User session invalid'
200
+					],
201
+					403
202
+				);
203
+				$e->setJson();
204
+				throw $e;
205
+			}
206
+			$Page->json($token_data);
207
+			return;
208
+		case 'guest_token':
209
+			if (User::instance()->user()) {
210
+				$e = new ExitException(
211
+					[
212
+						'access_denied',
213
+						'Only guests, not user allowed to access this grant_type'
214
+					],
215
+					403
216
+				);
217
+				$e->setJson();
218
+				throw $e;
219
+			}
220
+			if (!$Config->module('OAuth2')->guest_tokens) {
221
+				$e = new ExitException(
222
+					[
223
+						'access_denied',
224
+						'Guest tokens disabled'
225
+					],
226
+					403
227
+				);
228
+				$e->setJson();
229
+				throw $e;
230
+			}
231
+			$code = $OAuth2->add_code($client['id'], 'code', '');
232
+			if (!$code) {
233
+				$e = new ExitException(
234
+					[
235
+						'server_error',
236
+						"Server can't generate code, try later"
237
+					],
238
+					500
239
+				);
240
+				$e->setJson();
241
+				throw $e;
242
+			}
243
+			$token_data = $OAuth2->get_code($code, $client['id'], $client['secret'], '');
244
+			if ($token_data) {
245
+				unset($token_data['refresh_token']);
246
+				$Page->json($token_data);
247
+				return;
248
+			} else {
249
+				$e = new ExitException(
250
+					[
251
+						'server_error',
252
+						"Server can't get token data, try later"
253
+					],
254
+					500
255
+				);
256
+				$e->setJson();
257
+				throw $e;
258
+			}
259 259
 }
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @package   OAuth2
4
- * @category  modules
5
- * @author    Nazar Mokrynskyi <[email protected]>
6
- * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
7
- * @license   MIT License, see license.txt
8
- */
3
+	 * @package   OAuth2
4
+	 * @category  modules
5
+	 * @author    Nazar Mokrynskyi <[email protected]>
6
+	 * @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi
7
+	 * @license   MIT License, see license.txt
8
+	 */
9 9
 namespace cs\modules\OAuth2;
10 10
 
11 11
 use
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	throw $e;
140 140
 }
141 141
 /**
142
- * Tokens operations processing
143
- */
142
+	 * Tokens operations processing
143
+	 */
144 144
 switch ($_POST['grant_type']) {
145 145
 	case 'authorization_code':
146 146
 		if (!isset($_POST['code'])) {
Please login to merge, or discard this patch.