我一直在跟踪敏捷工具包"Book“,我已经到达:http://agiletoolkit.org/learn/app/auth
我尝试使用提供的代码:
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');问题是,显示散列密码(显然是heh)和添加->system(true)只会使其不可见。这是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();
}
}
}这将为密码创建一个空字段,只有当您在密码中添加某些内容时才会进行更新。
发布于 2012-08-24 20:38:17
我认为这是正确的方法,虽然很难确定。它确实起作用了,我看不出有什么安全问题。
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();
}
}
}https://stackoverflow.com/questions/12110855
复制相似问题