cakephp: почему мой пароль авторизации не хешируется? - PullRequest
0 голосов
/ 19 сентября 2011

Я пытаюсь создать страницу регистрации для новых пользователей, когда пользователь нажимает ссылку на табель успеваемости на панели навигации. Однако после нажатия кнопки «Отправить» на странице регистрации я получаю сообщение об ошибке «введенные пароли не совпадают». Проблема в том, что пароль не хэшируется. Понятия не имею, что я делаю не так.

print_r($this->data) отображает данные в таком виде: Array ( [MerryParent] => Array ( [имя пользователя] => Хонг [email] => hong7@yahoo.com [пароль] => hong7 [password2] => hong7 ) )

Ниже приведены мой вид, модель и контроллер.

signup.ctp

echo $this->Form->create('MerryParent',array('action'=>'signup'));
echo $this->Form->input('username',array('label'=>'Name'));
echo $this->Form->input('email');
echo $this->Form->input('password',array('value'=>''));
echo $this->Form->input('password2',array('label'=>'Confirm Password', 'type'=>'password','value'=>''));
echo $this->Form->end('Submit');

merry_parent.php

class MerryParent extends AppModel{
    var $name='MerryParent';

    var $validate=array(
        'initial'=>array(
            'rule'=>'notEmpty',
            'message'=>'Please select your initial'
        ),
        'username'=>array(
            'rule'=>array('minLength',3),
            'required'=>true,
            'allowEmpty'=>false,
            'message'=>'Name is required!'
        ),
        'email'=>array(
            'rule'=>'email',
            'required'=>true, 
            'allowEmpty'=>false,
            'message'=>'Valid email address required!'
        ),
        'password'=>array(
            'rule'=>'notEmpty',
            'required'=>true,
            'allowEmpty'=>false,
            'message'=>'password required!'
        ),
        'password2'=>array(
            'rule'=>'notEmpty',
            'required'=>true,
            'allowEmpty'=>false,
            'message'=>'confirm password required!'
        )
    );
}

merry_parents_controller.php

class MerryParentsController extends AppController{

    var $name='MerryParents';
    var $components=array('Auth','Session');

    function beforeFilter(){
        //parent::beforeFilter();
        $this->Auth->userModel='MerryParent';
        $this->Auth->authorize='actions';
        $this->Auth->allow('signup','login','logout');
        $this->Auth->loginAction=array('controller'=>'merry_parents','action'=>'register');
        //$this->Auth->loginRedirect=array('controller'=>'merry_parents','action'=>'report_card');
    }

    function register(){
    }

    function login(){
    }

    function logout(){
        $this->redirect($this->Auth->logout());
    }

    function signup(){
        print_r($this->data);

        if (!empty($this->data)){
            //$this->Auth->password($this->data['MerryParent']['password2'] used to get what the hashed password2 would look like.
            if ($this->data['MerryParent']['password']==$this->Auth->password($this->data['MerryParent']['password2'])){

                $merryparent_id=$this->MerryParent->field('id',
                    array('MerryParent.name'=>$this->data['MerryParent']['name'],
                    'MerryParent.email'=>$this->data['MerryParent']['email'])
                );
                echo $merryparent_id;

                if ($this->MerryParent->save($this->data))//record with $merryparent_id is updated
                {
                    $this->Session->setFlash('You will be receiving an email shortly confirming your login and password.');
                    $this->Auth->login($this->data); //automatically logs a user in after registration
                    $this->redirect(array('controller'=>'pages','action'=>'home'));
                }
                else
                    echo $this->Session->setFlash(__('Your admission could not be saved, please try again!',true));
            }//end if ($this->data['MerryParent']['password']....
            else
                echo $this->Session->setFlash('Typed passwords did not match');
        }//end if (!empty($this->data))
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...