]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/oauthconnectionssettings.php
Workflow for registering new OAuth apps pretty much done.
[quix0rs-gnu-social.git] / actions / oauthconnectionssettings.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List a user's OAuth connected applications
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/connectsettingsaction.php';
35 require_once INSTALLDIR . '/lib/applicationlist.php';
36
37 /**
38  * Show connected OAuth applications
39  *
40  * @category Settings
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  *
46  * @see      SettingsAction
47  */
48
49 class OauthconnectionssettingsAction extends ConnectSettingsAction
50 {
51     /**
52      * Title of the page
53      *
54      * @return string Title of the page
55      */
56
57     function title()
58     {
59         return _('Connected Applications');
60     }
61
62     /**
63      * Instructions for use
64      *
65      * @return instructions for use
66      */
67
68     function getInstructions()
69     {
70         return _('You have allowed the following applications to access you account.');
71     }
72
73     /**
74      * Content area of the page
75      *
76      * @return void
77      */
78
79     function showContent()
80     {
81         $user    = common_current_user();
82         $profile = $user->getProfile();
83
84         $offset = ($this->page - 1) * APPS_PER_PAGE;
85         $limit  =  APPS_PER_PAGE + 1;
86
87         $application = $profile->getApplications($offset, $limit);
88
89         if ($application) {
90             $al = new ApplicationList($application, $this->user, $this);
91             $cnt = $al->show();
92             if (0 == $cnt) {
93                 $this->showEmptyListMessage();
94             }
95         }
96
97         $this->pagination($this->page > 1, $cnt > APPS_PER_PAGE,
98                           $this->page, 'connectionssettings',
99                           array('nickname' => $this->user->nickname));
100     }
101
102     /**
103      * Handle posts to this form
104      *
105      * Based on the button that was pressed, muxes out to other functions
106      * to do the actual task requested.
107      *
108      * All sub-functions reload the form with a message -- success or failure.
109      *
110      * @return void
111      */
112
113     function handlePost()
114     {
115         // CSRF protection
116
117         $token = $this->trimmed('token');
118         if (!$token || $token != common_session_token()) {
119             $this->showForm(_('There was a problem with your session token. '.
120                               'Try again, please.'));
121             return;
122         }
123
124     }
125
126     function showEmptyListMessage()
127     {
128         $message = sprintf(_('You have not authorized any applications to use your account.'));
129
130         $this->elementStart('div', 'guide');
131         $this->raw(common_markup_to_html($message));
132         $this->elementEnd('div');
133     }
134
135     function showSections()
136     {
137        $cur = common_current_user();
138
139        $this->element('h2', null, 'Developers');
140        $this->elementStart('p');
141        $this->raw(_('Developers can edit the registration settings for their applications '));
142        $this->element('a',
143            array('href' => common_local_url('apps', array('nickname' => $cur->nickname))),
144                'here.');
145        $this->elementEnd('p');
146     }
147
148 }