Created
May 19, 2012 07:56
-
-
Save mojaie/2729985 to your computer and use it in GitHub Desktop.
CakePHP:test002_2
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 | |
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