]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/openidlogin.php
change LACONICA to STATUSNET
[quix0rs-gnu-social.git] / actions / openidlogin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/openid.php');
23
24 class OpenidloginAction extends Action
25 {
26     function handle($args)
27     {
28         parent::handle($args);
29         if (!common_config('openid', 'enabled')) {
30             common_redirect(common_local_url('login'));
31         } else if (common_is_real_login()) {
32             $this->clientError(_('Already logged in.'));
33         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
34             $openid_url = $this->trimmed('openid_url');
35
36             # CSRF protection
37             $token = $this->trimmed('token');
38             if (!$token || $token != common_session_token()) {
39                 $this->showForm(_('There was a problem with your session token. Try again, please.'), $openid_url);
40                 return;
41             }
42
43             $rememberme = $this->boolean('rememberme');
44
45             common_ensure_session();
46
47             $_SESSION['openid_rememberme'] = $rememberme;
48
49             $result = oid_authenticate($openid_url,
50                                        'finishopenidlogin');
51
52             if (is_string($result)) { # error message
53                 unset($_SESSION['openid_rememberme']);
54                 $this->showForm($result, $openid_url);
55             }
56         } else {
57             $openid_url = oid_get_last();
58             $this->showForm(null, $openid_url);
59         }
60     }
61
62     function getInstructions()
63     {
64         if (common_logged_in() && !common_is_real_login() &&
65             common_get_returnto()) {
66             // rememberme logins have to reauthenticate before
67             // changing any profile settings (cookie-stealing protection)
68             return _('For security reasons, please re-login with your ' .
69                      '[OpenID](%%doc.openid%%) ' .
70                      'before changing your settings.');
71         } else {
72             return _('Login with an [OpenID](%%doc.openid%%) account.');
73         }
74     }
75
76     function showPageNotice()
77     {
78         if ($this->error) {
79             $this->element('div', array('class' => 'error'), $this->error);
80         } else {
81             $instr = $this->getInstructions();
82             $output = common_markup_to_html($instr);
83             $this->elementStart('div', 'instructions');
84             $this->raw($output);
85             $this->elementEnd('div');
86         }
87     }
88
89     function title()
90     {
91         return _('OpenID Login');
92     }
93
94     function showForm($error=null, $openid_url)
95     {
96         $this->error = $error;
97         $this->openid_url = $openid_url;
98         $this->showPage();
99     }
100
101     function showContent() {
102         $formaction = common_local_url('openidlogin');
103         $this->elementStart('form', array('method' => 'post',
104                                            'id' => 'form_openid_login',
105                                            'class' => 'form_settings',
106                                            'action' => $formaction));
107         $this->elementStart('fieldset');
108         $this->element('legend', null, _('OpenID login'));
109         $this->hidden('token', common_session_token());
110
111         $this->elementStart('ul', 'form_data');
112         $this->elementStart('li');
113         $this->input('openid_url', _('OpenID URL'),
114                      $this->openid_url,
115                      _('Your OpenID URL'));
116         $this->elementEnd('li');
117         $this->elementStart('li', array('id' => 'settings_rememberme'));
118         $this->checkbox('rememberme', _('Remember me'), false,
119                         _('Automatically login in the future; ' .
120                            'not for shared computers!'));
121         $this->elementEnd('li');
122         $this->elementEnd('ul');
123         $this->submit('submit', _('Login'));
124         $this->elementEnd('fieldset');
125         $this->elementEnd('form');
126     }
127
128     function showLocalNav()
129     {
130         $nav = new LoginGroupNav($this);
131         $nav->show();
132     }
133 }