Last active
December 4, 2017 23:06
-
-
Save Sarverott/ce5cb4dbd8c623b00633f4267f8042e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>YOU ARE ON DASHBOARD PAGE</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" action="/admin/user_process/login"> | |
<input name="data[login]"><br> | |
<input type="password" name="data[password]"><br> | |
<input type="submit"> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('AppController', 'Controller'); | |
class AdminController extends AppController { | |
public $uses = array( | |
'users' | |
); | |
public function beforeFilter(){ | |
parent::beforeFilter(); | |
session_start(); | |
if(!($this->request->params['action']=='index'||$this->request->params['action']=='user_process')&&!isset($_SESSION['access']['user'])){ | |
$this->redirect(array('action'=>'index')); | |
die(); | |
} | |
} | |
public function user_process($action){ | |
$this->autoRender=false; | |
switch($action){ | |
case 'login': | |
if($this->request->is('post')){ | |
$data=$this->data; | |
$login=$data['login']; | |
$password=$data['password']; | |
$access=$this->users->find( | |
'first', | |
array( | |
'conditions'=>array( | |
'users.banned'=>0, | |
'users.password'=>sha1($password), | |
'users.name'=>$login | |
), | |
'fields'=>array( | |
'users.name', | |
'users.id' | |
) | |
) | |
); | |
if($access){ | |
$_SESSION['access']=array( | |
'user'=>$access['users']['name'], | |
'id'=>$access['users']['id'] | |
); | |
$this->redirect(array('action'=>'dashboard')); | |
} | |
}else{ | |
$this->redirect(array('action'=>'index')); | |
} | |
break; | |
//-------// | |
case 'logout': | |
unset($_SESSION['access']); | |
$this->redirect(array('action'=>'index')); | |
break; | |
} | |
} | |
public function index() { | |
$element=$tmp_element=array(); | |
$this->set('element', $element); | |
} | |
public function dashboard() { | |
$element=$tmp_element=array(); | |
$this->set('element', $element); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment