Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2. class UsersController extends AppController {
  3.     /**
  4.      * Overload setupAuth from AppController
  5.      *
  6.      * When we login our authenticate method should not be User model
  7.      * but the default AuthComponent handler
  8.      *
  9.      */
  10.     protected function setupAuth() {
  11.         // Call parent method first
  12.         parent::setupAuth();
  13.  
  14.         // And then switch authenticate method for login action
  15.         if ($this->action === 'login') {
  16.             $this->Auth->authenticate = null;
  17.         }
  18.     }
  19.  
  20.     /**
  21.      * Login form
  22.      *
  23.      * All the magic is handled by the AuthComponent
  24.      *
  25.      * All we need to do is change layout
  26.      *
  27.      */
  28.     public function login() {
  29.         $this->layout = 'login';
  30.     }
  31.  
  32.     /**
  33.      * Admin index
  34.      *
  35.      * Lists all users
  36.      *
  37.      */
  38.     public function admin_index() {
  39.         $users = $this->User->find('all');
  40.         $this->set(compact('users'));
  41.     }
  42.  
  43.     /**
  44.      * Admin add
  45.      *
  46.      * Handles creation of new users
  47.      *
  48.      */
  49.     public function admin_add() {
  50.         if (!empty($this->data)) {
  51.             if ($this->User->save($this->data)) {
  52.                 $this->Session->setFlash('User successfully created');
  53.                 $this->redirect(array('action' => 'index'));
  54.             }
  55.             $this->Session->setFlash('User was not created', 'error');
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * Admin edit
  61.      *
  62.      * Handles editing existing users
  63.      *
  64.      */
  65.     public function admin_edit($id = null) {
  66.         if (empty($id)) {
  67.             $this->Session->setFlash('Missing user id', 'error');
  68.             $this->redirect(array('action' => 'index'));
  69.         }
  70.  
  71.         $user = $this->User->read(null, $id);
  72.         if (empty($user)) {
  73.             $this->Session->setFlash('User does not exist', 'error');
  74.             $this->redirect(array('action' => 'index'));
  75.         }
  76.  
  77.         if (!empty($this->data)) {
  78.             if ($this->User->save($this->data)) {
  79.                 $this->Session->setFlash('User successfully updated');
  80.                 $this->redirect(array('action' => 'index'));
  81.             }
  82.             $this->Session->setFlash('User was not updated', 'error');
  83.         } else {
  84.             $this->data = $user;
  85.         }
  86.  
  87.         unset($this->data['User']['password']);
  88.     }
  89.  
  90.     /**
  91.      * Admin delete
  92.      *
  93.      * Handles deleting existing users
  94.      *
  95.      */
  96.     public function admin_delete($id) {
  97.  
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement