]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/openidsettings.php
removed message was slurping in success flag
[quix0rs-gnu-social.git] / actions / openidsettings.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 require_once(INSTALLDIR.'/lib/settingsaction.php');
23 require_once(INSTALLDIR.'/lib/openid.php');
24
25 class OpenidsettingsAction extends SettingsAction {
26
27         function show_top($arr) {
28                 $msg = $arr[0];
29                 $success = $arr[1];
30                 
31                 if ($msg) {
32                         $this->message($msg, $success);
33                 } else {
34                         common_element('div', 'instructions',
35                                                    _t('Manage your associated OpenIDs from here.'));
36                 }
37         }
38         
39         function show_form($msg=NULL, $success=false) {
40                 
41                 $user = common_current_user();
42                 
43                 common_show_header(_t('OpenID settings'), NULL, array($msg, $success),
44                                                    array($this, 'show_top'));
45
46                 common_element_start('form', array('method' => 'POST',
47                                                                                    'id' => 'openidadd',
48                                                                                    'action' =>
49                                                                                    common_local_url('openidsettings')));
50                 common_element('h2', NULL, _t('Add OpenID'));
51                 common_element('p', NULL,
52                                            _t('If you want to add an OpenID to your account, ' .
53                                                   'enter it in the box below and click "Add".'));
54                 common_element_start('p');
55                 common_element('label', array('for' => 'openid_url'),
56                                            _t('OpenID URL'));
57                 common_element('input', array('name' => 'openid_url',
58                                                                           'type' => 'text',
59                                                                           'id' => 'openid_url'));
60                 common_element('input', array('type' => 'submit',
61                                                                           'id' => 'add',
62                                                                           'name' => 'add',
63                                                                           'class' => 'submit',
64                                                                           'value' => _t('Add')));
65                 common_element_end('p');
66                 common_element_end('form');
67
68                 $oid = new User_openid();
69                 $oid->user_id = $user->id;
70                 
71                 if ($oid->find()) {
72                         
73                         common_element('h2', NULL, _t('OpenID'));
74                         common_element('p', NULL,
75                                                    _t('You can remove an OpenID from your account '.
76                                                           'by clicking the button marked "Delete" next to it.'));
77                         $idx = 0;
78                         
79                         while ($oid->fetch()) {
80                                 common_element_start('form', array('method' => 'POST',
81                                                                                                    'id' => 'openiddelete' . $idx,
82                                                                                                    'action' =>
83                                                                                                    common_local_url('openidsettings')));
84                                 common_element_start('p');
85                                 common_element('a', array('href' => $oid->canonical),
86                                                            $oid->display);
87                                 common_element('input', array('type' => 'hidden',
88                                                                                           'id' => 'openid_url'.$idx,
89                                                                                           'name' => 'openid_url',
90                                                                                           'value' => $oid->canonical));
91                                 common_element('input', array('type' => 'submit',
92                                                                                           'id' => 'remove'.$idx,
93                                                                                           'name' => 'remove',
94                                                                                           'class' => 'submit',
95                                                                                           'value' => _t('Remove')));
96                                 common_element_end('p');
97                                 common_element_end('form');
98                                 $idx++;
99                         }
100                 }
101                 
102                 common_show_footer();
103         }
104
105         function handle_post() {
106                 if ($this->arg('add')) {
107                         $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
108                         if (is_string($result)) { # error message
109                                 $this->show_form($result);
110                         }
111                 } else if ($this->arg('remove')) {
112                         $this->remove_openid();
113                 } else {
114                         $this->show_form(_t('Something weird happened.'));
115                 }
116         }
117
118         function remove_openid() {
119                 
120                 $openid_url = $this->trimmed('openid_url');
121                 $oid = User_openid::staticGet('canonical', $openid_url);
122                 if (!$oid) {
123                         $this->show_form(_t('No such OpenID.'));
124                         return;
125                 }
126                 $cur = common_current_user();
127                 if (!$cur || $oid->user_id != $cur->id) {
128                         $this->show_form(_t('That OpenID does not belong to you.'));
129                         return;
130                 }
131                 $oid->delete();
132                 $this->show_form(_t('OpenID removed.'), true);
133                 return;
134         }
135 }