当用户点击导航栏上的报告卡链接时,我正在尝试为新用户创建一个注册页面。但是,当我在注册页面上单击提交后,我收到“键入的密码不匹配”错误。问题是,密码没有被散列。我不知道我做错了什么。
print_r($this->data)
按原样显示数据:
阵列(
[MerryParent] =>阵列(
[username] =>红
[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))
}
}