- $form = $body->appendForm('', 'POST', 'authform');
- $form->setAttribute('id', 'authform');
- $form->appendElement('p', sprintf(_('Do you authorize %s to access %s?'), $request->query['client_id'], $request->query['scope']));
- $submit = $form->appendInputSubmit(_('yes'));
- $submit->setAttribute('name', 'authorized');
- $form->appendText(' ');
- $submit = $form->appendInputSubmit(_('no'));
- $submit->setAttribute('name', 'authorized');
- // Send HTML to client.
- print($document->saveHTML());
- exit();
+ $para = $body->appendElement('p', sprintf(_('Hi %s!'), $user['email']));
+ $para->setAttribute('class', 'userwelcome');
+
+ $form = $body->appendForm('', 'POST', 'authform');
+ $form->setAttribute('id', 'authform');
+ $form->appendElement('p', sprintf(_('Do you authorize %s to access %s?'), $request->query['client_id'], $request->query['scope']));
+ $submit = $form->appendInputSubmit(_('yes'));
+ $submit->setAttribute('name', 'authorized');
+ $form->appendText(' ');
+ $submit = $form->appendInputSubmit(_('no'));
+ $submit->setAttribute('name', 'authorized');
+ }
+ else {
+ // Handle authorize request, forwarding code in GET parameters if the user has authorized your client.
+ $is_authorized = ($_POST['authorized'] === 'yes');
+ $server->handleAuthorizeRequest($request, $response, $is_authorized);
+ /* For testing only
+ if ($is_authorized) {
+ // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client
+ $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
+ exit("SUCCESS! Authorization Code: $code");
+ }
+ */
+ $response->send();
+ exit();
+ }
+ }
+ else {
+ // Display login/register form.
+ $para = $body->appendElement('p', _('You need to log in or register to continue.'));
+ $para->setAttribute('class', 'logininfo');
+ }