]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/caslogin.php
Just a label change. Since the user already went ahead with
[quix0rs-gnu-social.git] / plugins / CasAuthentication / 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($args)
25     {
26         parent::handle($args);
27         if (common_is_real_login()) {
28             $this->clientError(_m('Already logged in.'));
29         } else {
30             global $casSettings;
31             phpCAS::client(CAS_VERSION_2_0,$casSettings['server'],$casSettings['port'],$casSettings['path']);
32             phpCAS::setNoCasServerValidation();
33             phpCAS::handleLogoutRequests();
34             phpCAS::forceAuthentication();
35             global $casTempPassword;
36             $casTempPassword = common_good_rand(16);
37             $user = common_check_user(phpCAS::getUser(), $casTempPassword);
38             if (!$user) {
39                 $this->serverError(_('Incorrect username or password.'));
40                 return;
41             }
42
43             // success!
44             if (!common_set_user($user)) {
45                 $this->serverError(_('Error setting user. You are probably not authorized.'));
46                 return;
47             }
48
49             common_real_login(true);
50
51             $url = common_get_returnto();
52
53             if ($url) {
54                 // We don't have to return to it again
55                 common_set_returnto(null);
56             } else {
57                 $url = common_local_url('all',
58                                     array('nickname' =>
59                                           $user->nickname));
60             }
61
62             common_redirect($url, 303);
63
64         }
65     }
66 }