- $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();
+ $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');
+ }
+ elseif (empty($_POST) && (@$request->query['scope'] == 'email')) {
+ // Display an interstitial page for a login when we have email scope (verified email for logging in).
+ $para = $body->appendElement('p', sprintf(_('Sign in to %s using…'), $request->query['client_id'])); // XXX: put domain name from redirect URI on there instead
+ $para->setAttribute('class', 'signinwelcome');
+ $form = $body->appendForm('', 'POST', 'loginauthform');
+ $form->setAttribute('id', 'loginauthform');
+ $form->setAttribute('class', 'loginarea');
+ $form->appendInputRadio('user_email', 'uemail_'.md5($user['email']), $user['email'], $user['email'] == $user['email']);
+ $form->appendLabel('uemail_'.md5($user['email']), $user['email']);
+ $para = $form->appendElement('p');
+ $para->setAttribute('class', 'small otheremaillinks');
+ $link = $para->appendLink('#', _('Add another email address'));
+ $link->setAttribute('id', 'addanotheremail'); // Makes the JS put the right functionality onto the link.
+ $para->appendText(' ');
+ $link = $para->appendLink('#', _('This is not me'));
+ $link->setAttribute('id', 'isnotme'); // Makes the JS put the right functionality onto the link.
+ $authinput = $form->appendInputHidden('authorized', 'yes');
+ $authinput->setAttribute('id', 'isauthorized');
+ $submit = $form->appendInputSubmit(_('Sign in'));
+ $para = $form->appendElement('p');
+ $para->setAttribute('class', 'small');
+ $link = $para->appendLink('#', _('Cancel'));
+ $link->setAttribute('id', 'cancelauth'); // Makes the JS put the right functionality onto the link.
+ }
+ 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, $user['id']);
+ /* 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');
+ $utils->appendLoginForm($body, $session, $user);
+ // Save the request in the session so we can get back to fulfilling it.
+ $result = $db->prepare('UPDATE `auth_sessions` SET `saved_redirect` = :redir WHERE `id` = :sessid;');
+ $saved_request = str_replace('&logout=1', '', $_SERVER['REQUEST_URI']); // Make sure to strip a logout to not get into a loop.
+ if (!$result->execute(array(':redir' => $saved_request, ':sessid' => $session['id']))) {
+ $utils->log('redir_save_failure', 'session: '.$session['id'].', redirect: '.$saved_request);
+ }
+ }