]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/userauthorization.php
617830e9a6d5011f04e953354716342dd92e6c6c
[quix0rs-gnu-social.git] / actions / userauthorization.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class UserauthorizationAction extends Action {
23         function handle($args) {
24                 parent::handle($args);
25                 
26                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
27                         $this->send_authorization();
28                 } else {
29                         try {
30                                 $req = $this->get_request();
31                                 if (!$req) {
32                                         common_server_error(_t('Cannot find request'));
33                                 }
34                                 common_debug('userauthorization.php - $req = "'.print_r($req,TRUE).'"');
35                                 $server = common_oauth_server();
36                                 $server->get_version($req);
37                                 $consumer = $server->get_consumer($req);
38                                 common_debug('userauthorization.php - $consumer = "'.print_r($consumer,TRUE).'"');
39                                 $token = $server->get_token($req, $consumer, "request");
40                                 common_debug('userauthorization.php - $token = "'.print_r($token,TRUE).'"');
41                                 $server->check_signature($req, $consumer, $token);
42                         } catch (OAuthException $e) {
43                                 $this->clear_request();
44                                 common_server_error($e->getMessage());
45                                 return;
46                         }
47                         
48                         if (common_logged_in()) {
49                                 $this->show_form($req);
50                         } else {
51                                 # Go log in, and then come back
52                                 common_set_returnto(common_local_url('userauthorization'));
53                                 common_redirect(common_local_url('login'));
54                         }
55                 }
56         }
57         
58         function store_request($req) {
59                 common_ensure_session();
60                 $_SESSION['userauthorizationrequest'] = $req;
61         }
62         
63         function get_request() {
64                 common_ensure_session();                
65                 $req = $_SESSION['userauthorizationrequest'];
66                 if (!$req) {
67                         # XXX: may have an uncaught exception
68                         $req = OAuthRequest::from_request();
69                         if ($req) {
70                                 $this->store_request($req);
71                         }
72                 }
73                 return $req;
74         }
75         
76         function show_form($req) {
77                 common_show_header(_t('Authorize subscription'));
78
79                 common_show_footer();
80         }
81         
82         function send_authorization() {
83                 $req = $this->get_request();
84                 
85                 if (!$req) {
86                         common_user_error(_t('No authorization request!'));
87                         return;
88                 }
89                 
90                 if ($this->boolean('authorize')) {
91                         
92                 }
93         }
94 }