Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class UsersController extends AppController {
- /**
- * Overload setupAuth from AppController
- *
- * When we login our authenticate method should not be User model
- * but the default AuthComponent handler
- *
- */
- protected function setupAuth() {
- // Call parent method first
- parent::setupAuth();
- // And then switch authenticate method for login action
- if ($this->action === 'login') {
- $this->Auth->authenticate = null;
- }
- }
- /**
- * Login form
- *
- * All the magic is handled by the AuthComponent
- *
- * All we need to do is change layout
- *
- */
- public function login() {
- $this->layout = 'login';
- }
- /**
- * Admin index
- *
- * Lists all users
- *
- */
- public function admin_index() {
- $users = $this->User->find('all');
- $this->set(compact('users'));
- }
- /**
- * Admin add
- *
- * Handles creation of new users
- *
- */
- public function admin_add() {
- if (!empty($this->data)) {
- if ($this->User->save($this->data)) {
- $this->Session->setFlash('User successfully created');
- $this->redirect(array('action' => 'index'));
- }
- $this->Session->setFlash('User was not created', 'error');
- }
- }
- /**
- * Admin edit
- *
- * Handles editing existing users
- *
- */
- public function admin_edit($id = null) {
- if (empty($id)) {
- $this->Session->setFlash('Missing user id', 'error');
- $this->redirect(array('action' => 'index'));
- }
- $user = $this->User->read(null, $id);
- if (empty($user)) {
- $this->Session->setFlash('User does not exist', 'error');
- $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->data)) {
- if ($this->User->save($this->data)) {
- $this->Session->setFlash('User successfully updated');
- $this->redirect(array('action' => 'index'));
- }
- $this->Session->setFlash('User was not updated', 'error');
- } else {
- $this->data = $user;
- }
- unset($this->data['User']['password']);
- }
- /**
- * Admin delete
- *
- * Handles deleting existing users
- *
- */
- public function admin_delete($id) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement