11.07
php
saved
derelm
Note
simple Auth component example updated
simple Auth component example updated
- /*
- This is a very simplistic example of the Auth component.
- It assumes you have a model `User` with at least these fields:
- * `username`
- * `password` (should be a CHAR of length 40)
- * `is_admin` (BOOL/INT)
- */
- //---
- // app_controller.php
- class AppController extends Controller {
- function beforeFilter() {
- $this->Auth->authorize = "controller";
- //$this->Auth->allow(); // if uncommented, allows anonymous access to any action
- }
- function isAuthorized() {
- /* defines if the loggedin user may access the current action
- in this case only users with an `is_admin` field and a value of `true`
- are allowed to use admin routes of this controller */
- return $this->Auth->user('is_admin');
- }
- return true;
- }
- }
- //---
- // controllers/users.php
- class UsersController extends AppController {
- var $name = 'Users';
- function login() {
- }
- function logout() {
- return $this->Auth->logout();
- }
- }
- //---
- // views/users/login.ctp
- <form method="post" action=".">
- </form>
- //---
- // views/users/logout.ctp
- <p>You've been logged out successfully.</p>
Parsed in 0.060 seconds, using GeSHi 1.0.7.14