Skip to content

Instantly share code, notes, and snippets.

Created August 24, 2015 07:39
Show Gist options
  • Save anonymous/06056f2af4e8dc093557 to your computer and use it in GitHub Desktop.
Save anonymous/06056f2af4e8dc093557 to your computer and use it in GitHub Desktop.
<?php
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('initDB','logout');
}
public function index() {
echo "hello"; die;
}
public function add() {
$groupInfo=$this->User->Group->find('list',array('type'=>'select','fields'=>array('id',"name"),"order"=>array('id'=>'ASC')));
$groupInfo=$this->set("group",$groupInfo);
if($this->request->is('post')){
if($this->User->save()){
$this->Session->setFlash("Your data is successfully loaded");
}else{
$this->Session->setFlash("Your data is not successfully loaded");
}
}
}
public function edit() {
}
public function delete() {
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect('/');
}
$this->Session->setFlash(__('Your username or password was incorrect.'));
}else{
if ($this->Session->read('Auth.User')) {
$this->Session->setFlash('You are logged in!');
return $this->redirect('/');
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
public function initDB() {
$group = $this->User->Group;
$group->id = 1;
$this->Acl->allow($group, 'controllers');
$group->id = 2;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts');
$this->Acl->allow($group, 'controllers/Widgets');
$group->id = 3;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts/add');
$this->Acl->allow($group, 'controllers/Posts/edit');
$this->Acl->allow($group, 'controllers/Widgets/add');
$this->Acl->allow($group, 'controllers/Widgets/edit');
$this->Acl->allow($group, 'controllers/users/logout');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment