caslogin.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
  20. class CasloginAction extends Action
  21. {
  22. function handle($args)
  23. {
  24. parent::handle($args);
  25. if (common_is_real_login()) {
  26. // TRANS: Client error displayed when trying to log in while already logged on.
  27. $this->clientError(_m('Already logged in.'));
  28. } else {
  29. global $casSettings;
  30. phpCAS::client(CAS_VERSION_2_0,$casSettings['server'],$casSettings['port'],$casSettings['path'],false);
  31. phpCAS::setNoCasServerValidation();
  32. phpCAS::handleLogoutRequests();
  33. phpCAS::forceAuthentication();
  34. global $casTempPassword;
  35. $casTempPassword = common_random_hexstr(16);
  36. $user = common_check_user(phpCAS::getUser(), $casTempPassword);
  37. if (!$user) {
  38. // TRANS: Server error displayed when trying to log in with incorrect username or password.
  39. $this->serverError(_m('Incorrect username or password.'));
  40. }
  41. // success!
  42. if (!common_set_user($user)) {
  43. // TRANS: Server error displayed when login fails in CAS authentication plugin.
  44. $this->serverError(_m('Error setting user. You are probably not authorized.'));
  45. }
  46. common_real_login(true);
  47. $url = common_get_returnto();
  48. if ($url) {
  49. // We don't have to return to it again
  50. common_set_returnto(null);
  51. } else {
  52. if(common_config('site', 'private') && $casSettings['takeOverLogin']) {
  53. //SSO users expect to just go to the URL they entered
  54. //if we don't have a returnto set, the user entered the
  55. //main StatusNet url, so send them there.
  56. $url = common_local_url('public');
  57. } else {
  58. //With normal logins (regular form-based username/password),
  59. //the user would expect to go to their home after logging in.
  60. $url = common_local_url('public',
  61. array('nickname' =>
  62. $user->nickname));
  63. }
  64. }
  65. common_redirect($url, 303);
  66. }
  67. }
  68. }