Conditions | 4 |
Paths | 4 |
Total Lines | 33 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
14 | public function authAction() |
||
|
|||
15 | { |
||
16 | $server = $this->oauth2Server; |
||
17 | |||
18 | $request = Request::createFromGlobals(); |
||
19 | $response = new Response(); |
||
20 | |||
21 | if (!$server->validateAuthorizeRequest($request, $response)) { |
||
22 | $response->send(); |
||
23 | exit; |
||
24 | } |
||
25 | |||
26 | $form = $this->getForm(); |
||
27 | |||
28 | if (empty($_POST)) { |
||
29 | $html = $form->render(); |
||
30 | echo $html; |
||
31 | exit; |
||
32 | } else { |
||
33 | $post = $this->getRequest()->getParsedBody(); |
||
34 | $form->populate($post); |
||
35 | if ($form->isValid()) { |
||
36 | $data = $form->getValues(); |
||
37 | $isAuthorized = ($data['auth'] === 'yes'); |
||
38 | $server->handleAuthorizeRequest($request, $response, $isAuthorized); |
||
39 | $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); |
||
40 | exit("SUCCESS! Authorization Code: $code"); |
||
41 | } |
||
42 | } |
||
43 | $response->setStatusCode(400); |
||
44 | $response->send(); |
||
45 | exit; |
||
46 | } |
||
47 | |||
69 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: