QloginController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. if (!defined('CLASS_USER')) {
  3. define('CLASS_USER', 'User');
  4. }
  5. App::uses('ToolsAppController', 'Tools.Controller');
  6. class QloginController extends ToolsAppController {
  7. public $uses = array('Tools.Qlogin');
  8. public $components = array('Tools.Common');
  9. public function beforeFilter() {
  10. parent::beforeFilter();
  11. if (isset($this->Auth)) {
  12. $this->Auth->allow('go');
  13. }
  14. }
  15. /****************************************************************************************
  16. * ADMIN functions
  17. ****************************************************************************************/
  18. /**
  19. * main login function
  20. * 2011-07-11 ms
  21. */
  22. public function go($key) {
  23. $entry = $this->Qlogin->translate($key);
  24. $default = '/';
  25. if ($this->Session->read('Auth.User.id') && isset($this->Auth->loginRedirect)) {
  26. $default = $this->Auth->loginRedirect;
  27. }
  28. if (empty($entry)) {
  29. $this->Common->flashMessage(__('Invalid Key'), 'error');
  30. $this->Common->autoRedirect($default);
  31. }
  32. //die(returns($entry));
  33. $uid = $entry['CodeKey']['user_id'];
  34. $url = $entry['CodeKey']['url'];
  35. if (!$this->Session->read('Auth.User.id')) {
  36. $this->User = ClassRegistry::init(CLASS_USER);
  37. # needs to be logged in
  38. $user = $this->User->get($uid);
  39. if (!$user) {
  40. $this->Common->flashMessage(__('Invalid Account'), 'error');
  41. $this->Common->autoRedirect($default);
  42. }
  43. if ($this->Auth->login($user['User'])) {
  44. $this->Session->write('Auth.User.Login.qlogin', true);
  45. if (!Configure::read('Qlogin.suppressMessage')) {
  46. $this->Common->flashMessage(__('You successfully logged in via qlogin'), 'success');
  47. }
  48. }
  49. }
  50. $this->redirect($url);
  51. }
  52. public function admin_index() {
  53. //TODO
  54. if ($this->Common->isPost()) {
  55. $this->Qlogin->set($this->request->data);
  56. if ($this->Qlogin->validates()) {
  57. $id = $this->Qlogin->generate($this->Qlogin->data['Qlogin']['url'], $this->Qlogin->data['Qlogin']['user_id']);
  58. $this->Common->flashMessage('New Key: '.h($id), 'success');
  59. $url = $this->Qlogin->urlByKey($id);
  60. $this->set(compact('url'));
  61. $this->request->data = array();
  62. }
  63. }
  64. $this->User = ClassRegistry::init(CLASS_USER);
  65. $users = $this->User->find('list');
  66. $this->CodeKey = ClassRegistry::init('Tools.CodeKey');
  67. $qlogins = $this->CodeKey->find('count', array('conditions'=>array('type'=>'qlogin')));
  68. $this->set(compact('users', 'qlogins'));
  69. }
  70. public function admin_listing() {
  71. }
  72. public function admin_reset() {
  73. if (!$this->Common->isPost()) {
  74. throw new MethodNotAllowedException();
  75. }
  76. $this->CodeKey = ClassRegistry::init('Tools.CodeKey');
  77. $this->CodeKey->deleteAll(array('type'=>'qlogin'));
  78. $this->Common->flashMessage(__('Success'), 'success');
  79. $this->Common->autoRedirect(array('action'=>'index'));
  80. }
  81. }