@@ -13,13 +13,13 @@ |
||
| 13 | 13 | cs\Language\Prefix, |
| 14 | 14 | cs\Page, |
| 15 | 15 | cs\Route; |
| 16 | -$Index = Index::instance(); |
|
| 17 | -$L = new Prefix('oauth2_'); |
|
| 18 | -$client = OAuth2::instance()->get_client(Route::instance()->route[2]); |
|
| 16 | +$Index = Index::instance(); |
|
| 17 | +$L = new Prefix('oauth2_'); |
|
| 18 | +$client = OAuth2::instance()->get_client(Route::instance()->route[2]); |
|
| 19 | 19 | Page::instance()->title($L->deletion_of_client($client['name'])); |
| 20 | -$Index->buttons = false; |
|
| 21 | -$Index->cancel_button_back = true; |
|
| 22 | -$Index->action = 'admin/OAuth2/clients/list'; |
|
| 20 | +$Index->buttons = false; |
|
| 21 | +$Index->cancel_button_back = true; |
|
| 22 | +$Index->action = 'admin/OAuth2/clients/list'; |
|
| 23 | 23 | $Index->content( |
| 24 | 24 | h::{'h2.cs-text-center'}( |
| 25 | 25 | $L->sure_to_delete_client($client['name']) |
@@ -1,9 +1,9 @@ |
||
| 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 | interface_off(); |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | namespace cs\modules\OAuth2; |
| 10 | 10 | use cs\Config, |
| 11 | 11 | cs\Index; |
| 12 | -$OAuth2 = OAuth2::instance(); |
|
| 13 | -$Index = Index::instance(); |
|
| 12 | +$OAuth2 = OAuth2::instance(); |
|
| 13 | +$Index = Index::instance(); |
|
| 14 | 14 | if (isset($_POST['mode'])) { |
| 15 | 15 | switch ($_POST['mode']) { |
| 16 | 16 | case 'add': |
@@ -1,9 +1,9 @@ |
||
| 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 | interface_off(); |
@@ -233,86 +233,86 @@ |
||
| 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 | } |
@@ -1,16 +1,16 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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': |
@@ -31,19 +31,19 @@ |
||
| 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 | } |
@@ -1,19 +1,19 @@ discard block |
||
| 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 |
||
| 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 = []; |
@@ -142,118 +142,118 @@ |
||
| 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 | } |
@@ -1,11 +1,11 @@ discard block |
||
| 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 |
||
| 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'])) { |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $module_data = Config::instance()->module('Photo_gallery'); |
| 38 | 38 | if (!$module_data->directory_created) { |
| 39 | 39 | $this->storage()->mkdir('Photo_gallery'); |
| 40 | - $module_data->directory_created = 1; |
|
| 40 | + $module_data->directory_created = 1; |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | /** |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | function get ($id) { |
| 69 | 69 | if (is_array($id)) { |
| 70 | 70 | foreach ($id as &$i) { |
| 71 | - $i = $this->get($i); |
|
| 71 | + $i = $this->get($i); |
|
| 72 | 72 | } |
| 73 | 73 | return $id; |
| 74 | 74 | } |
| 75 | - $L = Language::instance(); |
|
| 76 | - $id = (int)$id; |
|
| 75 | + $L = Language::instance(); |
|
| 76 | + $id = (int)$id; |
|
| 77 | 77 | return $this->cache->get("images/$id/$L->clang", function () use ($id) { |
| 78 | 78 | $data = $this->db()->qf([ |
| 79 | 79 | "SELECT |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | $id |
| 92 | 92 | ]); |
| 93 | 93 | if ($data) { |
| 94 | - $data['title'] = $this->ml_process($data['title']); |
|
| 95 | - $data['description'] = $this->ml_process($data['description']); |
|
| 94 | + $data['title'] = $this->ml_process($data['title']); |
|
| 95 | + $data['description'] = $this->ml_process($data['description']); |
|
| 96 | 96 | } |
| 97 | 97 | return $data; |
| 98 | 98 | }); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | if (!filter_var($original, FILTER_VALIDATE_URL)) { |
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | - $gallery = (int)$gallery; |
|
| 117 | + $gallery = (int)$gallery; |
|
| 118 | 118 | if ($this->db_prime()->q( |
| 119 | 119 | "INSERT INTO `[prefix]photo_gallery_images` |
| 120 | 120 | ( |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | time(), |
| 136 | 136 | $original |
| 137 | 137 | )) { |
| 138 | - $id = $this->db_prime()->id(); |
|
| 138 | + $id = $this->db_prime()->id(); |
|
| 139 | 139 | if ($this->set($id, $title, $description)) { |
| 140 | 140 | Event::instance()->fire( |
| 141 | 141 | 'System/upload_files/add_tag', |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | 'url' => $original |
| 145 | 145 | ] |
| 146 | 146 | ); |
| 147 | - $hash = md5(random_bytes(1000)); |
|
| 148 | - $tmp_file = TEMP.'/'.User::instance()->id."_$hash"; |
|
| 147 | + $hash = md5(random_bytes(1000)); |
|
| 148 | + $tmp_file = TEMP.'/'.User::instance()->id."_$hash"; |
|
| 149 | 149 | try { |
| 150 | - $SimpleImage = new SimpleImage($original); |
|
| 150 | + $SimpleImage = new SimpleImage($original); |
|
| 151 | 151 | $SimpleImage->thumbnail(256)->save($tmp_file = "$tmp_file.".$SimpleImage->get_original_info()['format']); |
| 152 | 152 | unset($SimpleImage); |
| 153 | 153 | } catch (Exception $e) { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | trigger_error($e->getMessage(), E_USER_WARNING); |
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | - $storage = $this->storage(); |
|
| 158 | + $storage = $this->storage(); |
|
| 159 | 159 | if (!$storage->file_exists("Photo_gallery/$gallery")) { |
| 160 | 160 | $storage->mkdir("Photo_gallery/$gallery"); |
| 161 | 161 | } |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | * @return bool |
| 198 | 198 | */ |
| 199 | 199 | function set ($id, $title, $description) { |
| 200 | - $User = User::instance(); |
|
| 201 | - $id = (int)$id; |
|
| 202 | - $title = xap(trim($title)); |
|
| 203 | - $description = xap(trim($description)); |
|
| 200 | + $User = User::instance(); |
|
| 201 | + $id = (int)$id; |
|
| 202 | + $title = xap(trim($title)); |
|
| 203 | + $description = xap(trim($description)); |
|
| 204 | 204 | if ($this->db_prime()->q( |
| 205 | 205 | "UPDATE `[prefix]photo_gallery_images` |
| 206 | 206 | SET |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | * @return bool |
| 233 | 233 | */ |
| 234 | 234 | function del ($id) { |
| 235 | - $id = (int)$id; |
|
| 236 | - $data = $this->get($id); |
|
| 235 | + $id = (int)$id; |
|
| 236 | + $data = $this->get($id); |
|
| 237 | 237 | if ($this->db_prime()->q( |
| 238 | 238 | "DELETE FROM `[prefix]photo_gallery_images` |
| 239 | 239 | WHERE `id` = $id |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | ] |
| 249 | 249 | ); |
| 250 | 250 | $this->storage()->unlink($this->storage()->source_by_url($data['preview'])); |
| 251 | - $Cache = $this->cache; |
|
| 251 | + $Cache = $this->cache; |
|
| 252 | 252 | unset( |
| 253 | 253 | $Cache->{"images/$id"}, |
| 254 | 254 | $Cache->{"galleries/$data[gallery]"} |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | * @return array|false |
| 265 | 265 | */ |
| 266 | 266 | function get_galleries_list () { |
| 267 | - $L = Language::instance(); |
|
| 267 | + $L = Language::instance(); |
|
| 268 | 268 | return $this->cache->get("galleries/list/$L->clang", function () { |
| 269 | - $data = []; |
|
| 269 | + $data = []; |
|
| 270 | 270 | foreach ( |
| 271 | 271 | $this->db()->qfas( |
| 272 | 272 | "SELECT `id` |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | ORDER BY `order` ASC" |
| 276 | 276 | ) as $gallery |
| 277 | 277 | ) { |
| 278 | - $data[$this->get_gallery($gallery)['path']] = $gallery; |
|
| 278 | + $data[$this->get_gallery($gallery)['path']] = $gallery; |
|
| 279 | 279 | } |
| 280 | 280 | return $data; |
| 281 | 281 | }); |
@@ -290,12 +290,12 @@ discard block |
||
| 290 | 290 | function get_gallery ($id) { |
| 291 | 291 | if (is_array($id)) { |
| 292 | 292 | foreach ($id as &$i) { |
| 293 | - $i = $this->get_gallery($i); |
|
| 293 | + $i = $this->get_gallery($i); |
|
| 294 | 294 | } |
| 295 | 295 | return $id; |
| 296 | 296 | } |
| 297 | - $L = Language::instance(); |
|
| 298 | - $id = (int)$id; |
|
| 297 | + $L = Language::instance(); |
|
| 298 | + $id = (int)$id; |
|
| 299 | 299 | return $this->cache->get("galleries/$id/$L->clang", function () use ($id) { |
| 300 | 300 | if ($data = $this->db()->qf([ |
| 301 | 301 | "SELECT |
@@ -315,17 +315,17 @@ discard block |
||
| 315 | 315 | LIMIT 1", |
| 316 | 316 | $id |
| 317 | 317 | ])) { |
| 318 | - $data['title'] = $this->ml_process($data['title']); |
|
| 319 | - $data['path'] = $this->ml_process($data['path']); |
|
| 320 | - $data['description'] = $this->ml_process($data['description']); |
|
| 321 | - $order = $data['preview_image'] == 'first' ? 'ASC' : 'DESC'; |
|
| 322 | - $data['preview'] = $this->db()->qfs( |
|
| 318 | + $data['title'] = $this->ml_process($data['title']); |
|
| 319 | + $data['path'] = $this->ml_process($data['path']); |
|
| 320 | + $data['description'] = $this->ml_process($data['description']); |
|
| 321 | + $order = $data['preview_image'] == 'first' ? 'ASC' : 'DESC'; |
|
| 322 | + $data['preview'] = $this->db()->qfs( |
|
| 323 | 323 | "SELECT `preview` |
| 324 | 324 | FROM `[prefix]photo_gallery_images` |
| 325 | 325 | WHERE `gallery` = $data[id] |
| 326 | 326 | ORDER BY `id` $order" |
| 327 | 327 | ) ?: ''; |
| 328 | - $data['images'] = $this->db()->qfas( |
|
| 328 | + $data['images'] = $this->db()->qfas( |
|
| 329 | 329 | "SELECT `id` |
| 330 | 330 | FROM `[prefix]photo_gallery_images` |
| 331 | 331 | WHERE `gallery` = $data[id] |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | ('%s')", |
| 355 | 355 | (int)(bool)$active |
| 356 | 356 | )) { |
| 357 | - $id = $this->db_prime()->id(); |
|
| 357 | + $id = $this->db_prime()->id(); |
|
| 358 | 358 | $this->set_gallery($id, $title, $path, $description, $active, $preview_image); |
| 359 | 359 | return $id; |
| 360 | 360 | } |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | * @return bool |
| 374 | 374 | */ |
| 375 | 375 | function set_gallery ($id, $title, $path, $description, $active, $preview_image) { |
| 376 | - $path = path($path ?: $title); |
|
| 377 | - $title = xap(trim($title)); |
|
| 378 | - $description = xap(trim($description)); |
|
| 379 | - $id = (int)$id; |
|
| 376 | + $path = path($path ?: $title); |
|
| 377 | + $title = xap(trim($title)); |
|
| 378 | + $description = xap(trim($description)); |
|
| 379 | + $id = (int)$id; |
|
| 380 | 380 | if ($this->db_prime()->q( |
| 381 | 381 | "UPDATE `[prefix]photo_gallery_galleries` |
| 382 | 382 | SET |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | $preview_image, |
| 395 | 395 | $id |
| 396 | 396 | )) { |
| 397 | - $Cache = $this->cache; |
|
| 397 | + $Cache = $this->cache; |
|
| 398 | 398 | unset( |
| 399 | 399 | $Cache->{"galleries/$id"}, |
| 400 | 400 | $Cache->{'galleries/list'} |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return bool |
| 413 | 413 | */ |
| 414 | 414 | function del_gallery ($id) { |
| 415 | - $id = (int)$id; |
|
| 415 | + $id = (int)$id; |
|
| 416 | 416 | if (!$this->db_prime()->q( |
| 417 | 417 | "DELETE FROM `[prefix]photo_gallery_galleries` |
| 418 | 418 | WHERE `id` = '%s' |
@@ -424,12 +424,12 @@ discard block |
||
| 424 | 424 | $this->ml_del('Photo_gallery/galleries/title', $id); |
| 425 | 425 | $this->ml_del('Photo_gallery/galleries/path', $id); |
| 426 | 426 | $this->ml_del('Photo_gallery/galleries/description', $id); |
| 427 | - $Cache = $this->cache; |
|
| 427 | + $Cache = $this->cache; |
|
| 428 | 428 | unset( |
| 429 | 429 | $Cache->{"galleries/$id"}, |
| 430 | 430 | $Cache->{'galleries/list'} |
| 431 | 431 | ); |
| 432 | - $images = $this->db()->qfas([ |
|
| 432 | + $images = $this->db()->qfas([ |
|
| 433 | 433 | "SELECT `id` |
| 434 | 434 | FROM `[prefix]photo_gallery_images` |
| 435 | 435 | WHERE `gallery` = '%s'", |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @package Photo gallery |
|
| 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 Photo gallery |
|
| 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 | namespace cs\modules\Photo_gallery; |
| 10 | 10 | use |
| 11 | 11 | cs\Cache\Prefix, |
@@ -33,8 +33,7 @@ |
||
| 33 | 33 | 'value' => $gallery['title'] |
| 34 | 34 | ] |
| 35 | 35 | ). |
| 36 | - ($Config->core['simple_admin_mode'] ? '' : |
|
| 37 | - h::label(h::info('photo_gallery_gallery_path')). |
|
| 36 | + ($Config->core['simple_admin_mode'] ? '' : h::label(h::info('photo_gallery_gallery_path')). |
|
| 38 | 37 | h::{'input[is=cs-input-text][name=edit[path]]'}( |
| 39 | 38 | [ |
| 40 | 39 | 'value' => $gallery['path'] |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @package Photo gallery |
|
| 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 Photo gallery |
|
| 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 | namespace cs\modules\Photo_gallery; |
| 10 | 10 | use |
| 11 | 11 | cs\ExitException, |
@@ -9,13 +9,13 @@ |
||
| 9 | 9 | namespace cs\modules\Photo_gallery; |
| 10 | 10 | use |
| 11 | 11 | cs\Index; |
| 12 | -$Index = Index::instance(); |
|
| 13 | -$Photo_gallery = Photo_gallery::instance(); |
|
| 12 | +$Index = Index::instance(); |
|
| 13 | +$Photo_gallery = Photo_gallery::instance(); |
|
| 14 | 14 | if (isset($_POST['add'])) { |
| 15 | - $add = $_POST['add']; |
|
| 15 | + $add = $_POST['add']; |
|
| 16 | 16 | $Index->save($Photo_gallery->add_gallery($add['title'], isset($add['path']) ? $add['path'] : null, $add['description'], $add['active'], $add['preview_image'])); |
| 17 | 17 | } elseif (isset($_POST['edit'])) { |
| 18 | - $edit = $_POST['edit']; |
|
| 18 | + $edit = $_POST['edit']; |
|
| 19 | 19 | $Index->save($Photo_gallery->set_gallery($edit['id'], $edit['title'], isset($edit['path']) ? $edit['path'] : null, $edit['description'], $edit['active'], $edit['preview_image'])); |
| 20 | 20 | } elseif (isset($_POST['delete'])) { |
| 21 | 21 | $Index->save($Photo_gallery->del_gallery($_POST['delete'])); |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @package Photo gallery |
|
| 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 Photo gallery |
|
| 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 | namespace cs\modules\Photo_gallery; |
| 10 | 10 | use |
| 11 | 11 | cs\Cache\Prefix, |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | if ($data['name'] != 'Photo_gallery') { |
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | - $module_data = Config::instance()->module('Photo_gallery'); |
|
| 21 | - $storage = Storage::instance()->{$module_data->storage('files')}; |
|
| 22 | - $Photo_gallery = Photo_gallery::instance(); |
|
| 20 | + $module_data = Config::instance()->module('Photo_gallery'); |
|
| 21 | + $storage = Storage::instance()->{$module_data->storage('files')}; |
|
| 22 | + $Photo_gallery = Photo_gallery::instance(); |
|
| 23 | 23 | foreach ($Photo_gallery->get_galleries_list() as $gallery) { |
| 24 | 24 | $Photo_gallery->del_gallery($gallery); |
| 25 | 25 | } |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @package Photo gallery |
|
| 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 Photo gallery |
|
| 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 | namespace cs\modules\Photo_gallery; |
| 10 | 10 | use |
| 11 | 11 | cs\Cache\Prefix, |