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