04.04
php
saved
dw
Note
Auth component is hashing passwords in admin_add, but not admin_pw.
Auth component is hashing passwords in admin_add, but not admin_pw.
- class AppController extends Controller{
- function beforeFilter(){
- Security::setHash("md5");
- $this->Auth->model = 'User';
- $this->Auth->sessionKey = 'User';
- $this->Auth->logoutRedirect = null;
- $this->Auth->loginError = 'Invalid username / password combination. Please try again';
- $this->Auth->authorize = 'controller';
- }
- function checkAdmin(){
- if($this->Session->read('User.admin')=="1"){
- return true;
- }
- }
- function flash($msg,$to){
- $this->Session->setFlash($msg);
- $this->redirect($to);
- exit;
- }
- }
- class UsersController extends AppController {
- var $name = 'Users';
- function beforeFilter(){
- parent::beforeFilter();
- $this->Auth->allow('pw', 'changepw');
- }
- function admin_pw($id=null){
- if(!$this->checkAdmin()){
- $this->flash('You are not authorized for this.',array('contoller'=>'profiles','action'=>'report_index'));
- }else{
- if(!$id){
- }
- $user = $this->User->read(null, $id);
- $this->set('user', $user);
- }else{
- //the following is needed to hash pw
- //$this->data['User']['password'] = $this->Auth->password($this->data['User']['password']);
- if($this->User->save($this->data)){
- }else{
- }
- }
- }
- }
- function admin_add(){
- if(!$this->checkAdmin()){
- $this->flash('You are not authorized for this.',array('contoller'=>'profiles','action'=>'report_index'));
- }else{
- $this->render();
- }else{
- //save
- if($this->User->save($this->data)){
- }else{
- }
- }
- }
- }
- }
- class User extends AppModel {
- var $name = 'User';
- var $useTable = 'newhire_users';
- }
- // views/admin_add.ctp
- <div id="users">
- <h2>Add User</h2>
- <?php
- ?>
- <table >
- <?php
- "User Name",
- ));
- "Password",
- ));
- "Admin",
- $form->checkbox('User.admin')
- ));
- ?>
- </table>
- <div class="submit toppad">
- <?php
- ?>
- </div>
- </div>
- // views/admin_pw.ctp
- <div id="users">
- <h2>Edit User</h2>
- <table>
- <?php
- 'User.id',
- );
- "New Password for ".$user['User']['username'],
- ));
- ?>
- </table>
- <?php
- ?>
- </div>
Parsed in 0.341 seconds, using GeSHi 1.0.7.14