用户控制器身份验证
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用户控制器身份验证相关的知识,希望对你有一定的参考价值。
this is all the actions needed for auth and the users login/register system
<?php class UsersController extends AppController { var $name = 'Users'; function beforeFilter() { parent::beforeFilter(); } function index() { $users = $this->User->find('all'); } else { $this->set('users', $users); } } function view($id) { $user = $this->User->findById($id); $this->set('user', $user); } else { $this->redirect('index'); } } function add() { $this->User->set($this->data); if ($this->User->validates()) { $this->data['User']['password'] = $this->data['User']['clear_password']; $this->User->save($this->Auth->hashPasswords($this->data), false); $this->redirect('index'); } else { } } } function edit($id = null) { foreach ($this->data['User'] as $field => $data) { $fields[] = $field; } } $fields[] = 'password'; $fields[] = 'clear_password'; $fields[] = 'confirm_password'; } $this->User->set($this->data); if ($this->User->validates()) { $this->data['User']['password'] = $this->data['User']['confirm_password']; } $this->User->save($this->Auth->hashPasswords($this->data), false, $fields); $this->Session->setFlash($this->data['User']['name'].' Updated', 'default', array('class'=>'good')); $this->redirect('index'); } } else { $user = $this->User->findById($id); $this->redirect('index'); } else { $this->data = $user; } } } function delete($id) { $user = $this->User->findById($id); } else { if ($user['User']['id'] == $this->Session->read('Auth.User.id')) { } else { if ($this->User->del($id)) { } else { $this->Session->setFlash('Failed to delete '.$user['User']['name'], 'default', array('class'=>'bad')); } } } $this->redirect('index'); } function login() { // Auth Magic } function logout() { $this->Session->del('Auth.User'); $this->redirect('login'); } } ?>
以上是关于用户控制器身份验证的主要内容,如果未能解决你的问题,请参考以下文章