3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 class UserauthorizationAction extends Action {
23 function handle($args) {
24 parent::handle($args);
26 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
27 $this->send_authorization();
30 common_debug('userauthorization.php - fetching request');
31 $req = $this->get_request();
33 common_server_error(_t('Cannot find request'));
35 common_debug('userauthorization.php - $req = "'.print_r($req,TRUE).'"');
36 $server = common_oauth_server();
37 common_debug('userauthorization.php - checking request version');
38 $server->get_version($req);
39 common_debug('userauthorization.php - getting the consumer');
40 $consumer = $server->get_consumer($req);
41 common_debug('userauthorization.php - $consumer = "'.print_r($consumer,TRUE).'"');
42 $token = $server->get_token($req, $consumer, "request");
43 common_debug('userauthorization.php - $token = "'.print_r($token,TRUE).'"');
44 $server->check_signature($req, $consumer, $token);
45 } catch (OAuthException $e) {
46 $this->clear_request();
47 common_server_error($e->getMessage());
51 if (common_logged_in()) {
52 $this->show_form($req);
54 # Go log in, and then come back
55 common_set_returnto(common_local_url('userauthorization'));
56 common_redirect(common_local_url('login'));
61 function store_request($req) {
62 common_ensure_session();
63 $_SESSION['userauthorizationrequest'] = $req;
66 function get_request() {
67 common_ensure_session();
68 $req = $_SESSION['userauthorizationrequest'];
70 # XXX: may have an uncaught exception
71 $req = OAuthRequest::from_request();
73 $this->store_request($req);
79 function show_form($req) {
80 common_show_header(_t('Authorize subscription'));
85 function send_authorization() {
86 $req = $this->get_request();
89 common_user_error(_t('No authorization request!'));
93 if ($this->boolean('authorize')) {