01.04
php
saved
bazil749
Note
Auth Component with Cookie
Works great thanX to TommyO!
Auth Component with Cookie
Works great thanX to TommyO!
- // app_controller:
- class AppController extends Controller {
- function beforeFilter(){
- $this->Auth->authorize = 'controller';
- $this->Auth->loginAction = '/login/';
- $this->Auth->autoRedirect = false;
- }
- function isAuthorized() {
- return true;
- }
- }
- // users_controller:
- function login()
- {
- $cookie = $this->Cookie->read('Auth.User');
- if ($this->Auth->login($cookie)) {
- // Clear auth message, just in case we use it.
- $this->Session->del('Message.auth');
- $this->redirect($this->Auth->redirect());
- }
- }
- }
- if ($this->Auth->user()) {
- $cookie['username'] = $this->data['User']['username'];
- $cookie['password'] = $this->data['User']['password'];
- $this->Cookie->write('Auth.User', $cookie, true, '+1 day');
- }
- $this->redirect($this->Auth->redirect());
- }
- }
- function logout(){
- $this->Session->setFlash('Good-Bye');
- $this->Cookie->del('Auth.User');
- $this->redirect($this->Auth->logout());
- }
- function beforeFilter() {
- parent::beforeFilter();
- $this->Auth->allow('add');
- }
Parsed in 0.079 seconds, using GeSHi 1.0.7.14