]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/actions/caslogin.php
Test if $casSettings['user_whitelist'] is an array - and then perform in_array(....
[quix0rs-gnu-social.git] / plugins / CasAuthentication / actions / caslogin.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 class CasloginAction extends Action
23 {
24     function handle()
25     {
26         parent::handle();
27         if (common_is_real_login()) {
28             // TRANS: Client error displayed when trying to log in while already logged on.
29             $this->clientError(_m('Already logged in.'));
30         } else {
31             global $casSettings;
32             phpCAS::client(CAS_VERSION_2_0,$casSettings['server'],$casSettings['port'],$casSettings['path'],false);
33             phpCAS::setNoCasServerValidation();
34             phpCAS::handleLogoutRequests();
35             phpCAS::forceAuthentication();
36             global $casTempPassword;
37             $casTempPassword = common_random_hexstr(16);
38             $user = common_check_user(phpCAS::getUser(), $casTempPassword);
39             if (!$user) {
40                 // TRANS: Server error displayed when trying to log in with incorrect username or password.
41                 $this->serverError(_m('Incorrect username or password.'));
42             }
43
44             if (is_array($casSettings['user_whitelist']) && !in_array($user->nickname, $casSettings['user_whitelist'])) {
45                 // TRANS: Server error displayed when trying to log in with non-whitelisted user name (when whitelists are enabled.)
46                 $this->serverError(_m('Incorrect username or password.'));
47             }
48
49             // success!
50             if (!common_set_user($user)) {
51                 // TRANS: Server error displayed when login fails in CAS authentication plugin.
52                 $this->serverError(_m('Error setting user. You are probably not authorized.'));
53             }
54
55             common_real_login(true);
56
57             $url = common_get_returnto();
58
59             if ($url) {
60                 // We don't have to return to it again
61                 common_set_returnto(null);
62             } else {
63                 if(common_config('site', 'private') && $casSettings['takeOverLogin']) {
64                     //SSO users expect to just go to the URL they entered
65                     //if we don't have a returnto set, the user entered the
66                     //main StatusNet url, so send them there.
67                     $url = common_local_url('public');
68                 } else {
69                     //With normal logins (regular form-based username/password),
70                     //the user would expect to go to their home after logging in.
71                     $url = common_local_url('public',
72                                         array('nickname' =>
73                                               $user->nickname));
74                 }
75             }
76
77             common_redirect($url, 303);
78         }
79     }
80 }