| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- if (!defined('CLASS_USER')) {
- define('CLASS_USER', 'User');
- }
- App::uses('ToolsAppController', 'Tools.Controller');
- class QloginController extends ToolsAppController {
- public $uses = array('Tools.Qlogin');
- public $components = array('Tools.Common');
- public function beforeFilter() {
- parent::beforeFilter();
- if (isset($this->Auth)) {
- $this->Auth->allow('go');
- }
- }
- /****************************************************************************************
- * ADMIN functions
- ****************************************************************************************/
- /**
- * main login function
- * 2011-07-11 ms
- */
- public function go($key = null) {
- if (!$key) {
- throw new NotFoundException();
- }
- $entry = $this->Qlogin->translate($key);
- $default = '/';
- if ($this->Session->read('Auth.User.id') && isset($this->Auth->loginRedirect)) {
- $default = $this->Auth->loginRedirect;
- }
- if (empty($entry)) {
- $this->Common->flashMessage(__('Invalid Key'), 'error');
- return $this->Common->autoRedirect($default);
- }
- //die(returns($entry));
- $uid = $entry['CodeKey']['user_id'];
- $url = $entry['CodeKey']['url'];
- if (!$this->Session->read('Auth.User.id')) {
- if ($this->Common->manualLogin($uid)) {
- $this->Session->write('Auth.User.Login.qlogin', true);
- if (!Configure::read('Qlogin.suppressMessage')) {
- $this->Common->flashMessage(__('You successfully logged in via qlogin'), 'success');
- }
- } else {
- $this->Common->flashMessage($this->Auth->loginError, 'error');
- $url = $default;
- trigger_error($this->Auth->loginError . ' - uid ' . $uid);
- }
- }
- return $this->redirect($url);
- }
- /**
- * these params can be passed to preset the form
- * - user_id
- * - url (base64encoded)
- *
- * 2012-03-04 ms
- */
- public function admin_index() {
- if ($this->Common->isPosted()) {
- $this->Qlogin->set($this->request->data);
- if ($this->Qlogin->validates()) {
- $id = $this->Qlogin->generate($this->Qlogin->data['Qlogin']['url'], $this->Qlogin->data['Qlogin']['user_id']);
- $this->Common->flashMessage('New Key: '.h($id), 'success');
- $url = $this->Qlogin->urlByKey($id);
- $this->set(compact('url'));
- $this->request->data = array();
- }
- } else {
- if (!empty($this->request->params['named']['user_id'])) {
- $this->request->data['Qlogin']['user_id'] = $this->request->params['named']['user_id'];
- }
- if (!empty($this->request->params['named']['url'])) {
- $this->request->data['Qlogin']['url'] = base64_decode($this->request->params['named']['url']);
- }
- }
- $this->User = ClassRegistry::init(CLASS_USER);
- $users = $this->User->find('list');
- $this->CodeKey = ClassRegistry::init('Tools.CodeKey');
- $qlogins = $this->CodeKey->find('count', array('conditions'=>array('type'=>'qlogin')));
- $this->set(compact('users', 'qlogins'));
- }
- public function admin_listing() {
- }
- public function admin_reset() {
- if (!$this->Common->isPosted()) {
- throw new MethodNotAllowedException();
- }
- $this->CodeKey = ClassRegistry::init('Tools.CodeKey');
- $this->CodeKey->deleteAll(array('type'=>'qlogin'));
- $this->Common->flashMessage(__('Success'), 'success');
- return $this->Common->autoRedirect(array('action'=>'index'));
- }
- }
|