我有一個CakePHP應用程序,其中包含用戶註冊。在用戶頁面上,我希望他們能夠更新他們的電子郵件和密碼。這是我的User
型號:使用CakePHP更新用戶電子郵件和密碼
<?php
class User extends AppModel {
public $name = 'User';
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
),
'range' => array(
'rule' => array('between', 4, 20),
'message' => 'Between 4 and 20 characters'
),
'characters' => array(
'rule' => array('alphaNumeric'),
'message' => 'Alphanumeric characters only'
),
'unique' => array(
'rule' => array('isUnique'),
'message' => 'This username is taken'
)
),
'email' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'An email is required'
),
'validEmail' => array(
'rule' => array('email'),
'message' => 'Please provide a valid email'
),
'range' => array(
'rule' => array('between', 5, 64),
'message' => 'Between 5 and 64 characters'
),
'unique' => array(
'rule' => array('isUnique'),
'message' => 'This email has already been used'
)
),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A password is required'
),
'range' => array(
'rule' => array('between', 5, 64),
'message' => 'Between 5 and 64 characters'
),
)
);
public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
}
而且我使用的形式幫助創建表單:
<p>Modify your account settings</p>
<?php echo $this->Session->flash(); ?>
<?php
echo $this->Form->create('User');
echo $this->Form->input('currentPassword', array('type' => 'password'));
echo $this->Form->input('username', array('disabled' => 'disabled', 'value' => $username));
echo $this->Form->input('email');
echo $this->Form->input('newPassword', array('type' => 'password'));
echo $this->Form->end('Update');
?>
我怎麼會去檢查當前密碼是否有效,檢查是否新電子郵件和密碼傳遞驗證規則,然後從我的控制器中更新我的用戶表中的用戶記錄?
這是如何檢查用戶輸入的密碼與存儲在數據庫中的密碼相同的?從我所看到的情況來看,它假定它是相同的並繼續進行下去。 – 2012-07-24 21:34:45
噢...對不起,我會編輯它。 :)給我幾分鐘。 :) – 2012-07-24 21:36:05