我一直在關注敏捷工具包「書」,我已經達到:http://agiletoolkit.org/learn/app/auth敏捷工具包:密碼更改FormAndSave
我嘗試使用提供的代碼:
class page_account extends Page {
function init(){
parent::init();
$this->api->auth->check();
$model = $this->add('Model_Customer');
$model->getField('email')->system(true);
$this->add('FormAndSave')->setModel($model)->loadData($this->api->auth->get('id'));
}
}
但是,這只是給了我一個模型未設置錯誤,以便知道在哪裏FormAndSave從我得到的代碼更改爲:
class page_account extends Page {
function init(){
parent::init();
$this->api->auth->check();
$model = $this->add('Model_Customer');
$saveForm=$this->add('Form');
$saveForm->setModel($model)->loadData($this->api->auth->get('id'));
$saveForm->addSubmit();
$saveForm->onSubmit(function($saveForm) {
try {
$saveForm->update()->js()->univ()->successMessage('Saved changes.')->execute();
} catch(Exception $e) {
$saveForm->js()->univ()->alert('Failed to save.')->execute();
}
});
}
}
這至少讓我保存數據,但我不能讓密碼字段露面。我可以在以後通過正確添加到模型:
$model = $this->add('Model_Customer');
$model->addField('password', 'password');
的問題是,顯示了哈希密碼(顯然嘿嘿),並添加 - >系統(真)只是使它不可見。這是Model_Customer:
class Model_Customer extends Model_Table {
public $table='customer';
function init() {
parent::init();
$this->addField('name');
$this->addField('email');
}
}
幫助將超級讚賞 - 一些解釋將是巨大的,我正在學習這個框架,我越能學到更好。
當前表單不顯示用戶編輯他/她的密碼的密碼字段 - 我該如何去實現該功能?就像我說過的,如果我再次將它添加到模型中,我可以讓字段顯示,但它顯示的散列密碼實際上並不是您想要的。我如何正確地做到這一點?
謝謝!
更新:我有工作,但不知道這是否是正確的或安全的方式:
class page_account extends Page {
function init(){
parent::init();
$this->api->auth->check();
$auth=$this->api->auth;
$model = $this->add('Model_Customer');
$model->addField('password')->type('password');
$saveForm=$this->add('MVCForm');
$saveForm->setModel($model)->loadData($this->api->auth->get('id'));
$saveForm->set('password', '');
$saveForm->addSubmit();
if($saveForm->isSubmitted()){
// Short-cuts
$auth=$this->api->auth;
$l=$saveForm->get('email');
$p=$saveForm->get('password');
if ($p) {
// Manually encrypt password
$enc_p = $auth->encryptPassword($p,$l);
$saveForm->set('password', $enc_p);
} else {
$saveForm->set('password', $model->get('password'));
}
$saveForm->update()->js()->univ()->successMessage('Saved user information. ')->execute();
}
}
}
這產生了只有更新,如果你把東西在它的密碼爲空場。
我看到類似隱含問題的東西,但需要明確詢問。提到你期望的代碼將會有所幫助。 –
而且對不起@BenBarden問題現在已經說得更清楚了。 –