IndexController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_OpenId
  17. * @subpackage Demos
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Controller_Action
  23. */
  24. require_once 'Zend/Controller/Action.php';
  25. /**
  26. * @see Zend_Auth
  27. */
  28. require_once 'Zend/Auth.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_OpenId
  32. * @subpackage Demos
  33. * @uses Zend_Controller_Action
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class IndexController extends Zend_Controller_Action
  38. {
  39. /**
  40. * indexAction
  41. *
  42. * @return void
  43. */
  44. public function indexAction()
  45. {
  46. $auth = Zend_Auth::getInstance();
  47. if (!$auth->hasIdentity()) {
  48. $this->_redirect('/index/login');
  49. } else {
  50. $this->_redirect('/index/welcome');
  51. }
  52. }
  53. /**
  54. * welcomeAction
  55. *
  56. * @return void
  57. */
  58. public function welcomeAction()
  59. {
  60. $auth = Zend_Auth::getInstance();
  61. if (!$auth->hasIdentity()) {
  62. $this->_redirect('index/login');
  63. }
  64. $this->view->user = $auth->getIdentity();
  65. }
  66. /**
  67. * loginAction
  68. *
  69. * @return void
  70. */
  71. public function loginAction()
  72. {
  73. $this->view->status = "";
  74. if (($this->_request->isPost() &&
  75. $this->_request->getPost('openid_action') == 'login' &&
  76. $this->_request->getPost('openid_identifier', '') !== '') ||
  77. ($this->_request->isPost() &&
  78. $this->_request->getPost('openid_mode') !== null) ||
  79. (!$this->_request->isPost() &&
  80. $this->_request->getQuery('openid_mode') != null)) {
  81. Zend_Loader::loadClass('Zend_Auth_Adapter_OpenId');
  82. $auth = Zend_Auth::getInstance();
  83. $result = $auth->authenticate(
  84. new Zend_Auth_Adapter_OpenId($this->_request->getPost('openid_identifier')));
  85. if ($result->isValid()) {
  86. $this->_redirect('/index/welcome');
  87. } else {
  88. $auth->clearIdentity();
  89. foreach ($result->getMessages() as $message) {
  90. $this->view->status .= "$message<br>\n";
  91. }
  92. }
  93. }
  94. $this->render();
  95. }
  96. /**
  97. * logoutAction
  98. *
  99. * @return void
  100. */
  101. public function logoutAction()
  102. {
  103. Zend_Auth::getInstance()->clearIdentity();
  104. $this->_redirect('/index/index');
  105. }
  106. }