Skip to content

Instantly share code, notes, and snippets.

@mojaie
Created May 19, 2012 07:56
Show Gist options
  • Save mojaie/2729985 to your computer and use it in GitHub Desktop.
Save mojaie/2729985 to your computer and use it in GitHub Desktop.
CakePHP:test002_2
<?php
class UsersController extends AppController {
public function beforeFilter() {
$this->Auth->allowedActions = array('login');
parent::beforeFilter();
}
public function isAuthorized() {
if ($this->Auth->user('group') == 'admin') {
return true;
} else if ($this->Auth->user('group') == 'user') {
if (in_array($this->action, array('logout')) {
return true;
}
}
return false;
}
//ログイン
function login() {
if ($this->Auth->loggedIn()) {
$this->redirect('/tests/openaccess');
}
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('メールアドレスかパスワードが間違っています');
}
}
}
//ログアウト
function logout() {
$this->redirect($this->Auth->logout());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment