]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OpenID/openidlogin.php
Merge branch 'testing' into 0.9.x
[quix0rs-gnu-social.git] / plugins / OpenID / 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') && !defined('LACONICA')) { exit(1); }
21
22 require_once INSTALLDIR.'/plugins/OpenID/openid.php';
23
24 class OpenidloginAction extends Action
25 {
26     function handle($args)
27     {
28         parent::handle($args);
29         if (common_is_real_login()) {
30             // TRANS: Client error message trying to log on with OpenID while already logged on.
31             $this->clientError(_m('Already logged in.'));
32         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
33             $provider = common_config('openid', 'trusted_provider');
34             if ($provider) {
35                 $openid_url = $provider;
36             } else {
37                 $openid_url = $this->trimmed('openid_url');
38             }
39
40             oid_assert_allowed($openid_url);
41
42             # CSRF protection
43             $token = $this->trimmed('token');
44             if (!$token || $token != common_session_token()) {
45                 // TRANS: Message given when there is a problem with the user's session token.
46                 $this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url);
47                 return;
48             }
49
50             $rememberme = $this->boolean('rememberme');
51
52             common_ensure_session();
53
54             $_SESSION['openid_rememberme'] = $rememberme;
55
56             $result = oid_authenticate($openid_url,
57                                        'finishopenidlogin');
58
59             if (is_string($result)) { # error message
60                 unset($_SESSION['openid_rememberme']);
61                 $this->showForm($result, $openid_url);
62             }
63         } else {
64             $openid_url = oid_get_last();
65             $this->showForm(null, $openid_url);
66         }
67     }
68
69     function getInstructions()
70     {
71         if (common_logged_in() && !common_is_real_login() &&
72             common_get_returnto()) {
73             // rememberme logins have to reauthenticate before
74             // changing any profile settings (cookie-stealing protection)
75             // TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
76             // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
77             return _m('For security reasons, please re-login with your ' .
78                      '[OpenID](%%doc.openid%%) ' .
79                      'before changing your settings.');
80         } else {
81             // TRANS: OpenID plugin message.
82             // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
83             return _m('Login with an [OpenID](%%doc.openid%%) account.');
84         }
85     }
86
87     function showPageNotice()
88     {
89         if ($this->error) {
90             $this->element('div', array('class' => 'error'), $this->error);
91         } else {
92             $instr = $this->getInstructions();
93             $output = common_markup_to_html($instr);
94             $this->elementStart('div', 'instructions');
95             $this->raw($output);
96             $this->elementEnd('div');
97         }
98     }
99
100     function showScripts()
101     {
102         parent::showScripts();
103         $this->autofocus('openid_url');
104     }
105
106     function title()
107     {
108         // TRANS: OpenID plugin message. Title.
109         return _m('OpenID Login');
110     }
111
112     function showForm($error=null, $openid_url)
113     {
114         $this->error = $error;
115         $this->openid_url = $openid_url;
116         $this->showPage();
117     }
118
119     function showContent() {
120         $formaction = common_local_url('openidlogin');
121         $this->elementStart('form', array('method' => 'post',
122                                            'id' => 'form_openid_login',
123                                            'class' => 'form_settings',
124                                            'action' => $formaction));
125         $this->elementStart('fieldset');
126         // TRANS: OpenID plugin logon form legend.
127         $this->element('legend', null, _m('OpenID login'));
128         $this->hidden('token', common_session_token());
129
130         $this->elementStart('ul', 'form_data');
131         $this->elementStart('li');
132         $provider = common_config('openid', 'trusted_provider');
133         if ($provider) {
134             $this->element('label', array(), _m('OpenID provider'));
135             $this->element('span', array(), $provider);
136             $this->element('p', 'form_guide',
137                            _m('You will be sent to the provider\'s site for authentication.'));
138             $this->hidden('openid_url', $provider);
139         } else {
140             // TRANS: OpenID plugin logon form field label.
141             $this->input('openid_url', _m('OpenID URL'),
142                          $this->openid_url,
143                         // TRANS: OpenID plugin logon form field instructions.
144                          _m('Your OpenID URL'));
145         }
146         $this->elementEnd('li');
147         $this->elementStart('li', array('id' => 'settings_rememberme'));
148         // TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
149         $this->checkbox('rememberme', _m('Remember me'), false,
150                         // TRANS: OpenID plugin logon form field instructions.
151                         _m('Automatically login in the future; ' .
152                            'not for shared computers!'));
153         $this->elementEnd('li');
154         $this->elementEnd('ul');
155         // TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
156         $this->submit('submit', _m('BUTTON', 'Login'));
157         $this->elementEnd('fieldset');
158         $this->elementEnd('form');
159     }
160
161     function showLocalNav()
162     {
163         $nav = new LoginGroupNav($this);
164         $nav->show();
165     }
166 }