Php 敏捷工具包:密码更改表单和保存
我一直在关注敏捷工具包“书”,我已经达到: 我尝试使用提供的代码:Php 敏捷工具包:密码更改表单和保存,php,frameworks,atk4,Php,Frameworks,Atk4,我一直在关注敏捷工具包“书”,我已经达到: 我尝试使用提供的代码: class page_account extends Page { function init(){ parent::init(); $this->api->auth->check(); $model = $this->add('Model_Customer'); $model->getField('email')->
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'));
}
}
但这给了我一个model not set错误,因此知道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');
问题是显示哈希密码(显然是heh)和adding->system(true)只会使它不可见。这是Model_客户:
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();
}
}
}
这会为密码创建一个空字段,只有在您输入密码时才会更新。我认为这是正确的方法,尽管很难确定。它确实有效,我看不出有任何安全问题
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的问题现在已经说得更清楚了。