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