$tc = $tab->add('CRUD',array('allow_add'=>$allow_add)); $tc->setModel($this->api->auth->model,$fields['edit'],$fields['grid']);
//if ($this->api->auth->model['is_super']) { $tc->grid->addColumn('Button','reset_password');
if ($tc->grid){ $tab->api->stickyGet('id');
if($_GET['reset_password']){ $tab->js()->univ() ->frameURL('Reset Password',$this->api->url('admin/resetpassword',array('id'=>$_GET['reset_password']))) ->execute(); } } //}class page_admin_resetpassword extends Page { function init(){ parent::init();
$this->api->addLocation('atk4-addons',array( 'php'=>'misc/lib' ));
$id = $_GET['id'];
$m = $this->add($this->api->auth->model); $m->loadData($_GET['id']);
$this->add('P')->setHTML('<strong>Resetting password for ' . $m['full_name'] . '</strong>');
$f = $this->add('Form');
//add fields to form - don't load via model as password field will display hashed value
$f->addField('password','new_Password')->add('StrengthChecker',null,'after_field'); $f->addField('password','password_confirm', 'Confirm password'); $f->addSubmit('Change Password');
$f->addClass('stacked');
if($f->isSubmitted()){ if($f->get('new_password') != $f->get('password_confirm')){ $f->displayError('password','Passwords do not match!'); } else {
//we have a value so set the model and update
$m->set('password', $f->get('new_password')); $m->save(); }
$f->js()->univ()->successMessage('Password Changed')->execute(); } }} else {
//we have a value so set the model and update$m->set('password', $f->get('new_password'));$m->save();}$f->js()->univ()->successMessage('Password Changed')->execute();}}
Th error is shown via a JS alert can bee seen in this screen grabThanksBP
--
Error in AJAX response: SyntaxError: Unexpected token <
BaseException
sha256 requires salt (2nd argument to encryptPassword and is normaly an email)
:
Stack trace:
/Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/BaseException.php :38 BaseException BaseException->collectBasicData(Null, Null, Null) /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/AbstractObject.php :300 BaseException BaseException->__construct("sha256 requires salt (2nd argument to encryptPassword and is normaly an email)", Null, Null, Null) /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/Auth/Basic.php :182 enjouanissonoffice_auth Auth->exception("sha256 requires salt (2nd argument to encryptPassword and is normaly an email)") /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/Auth/Basic.php :129 enjouanissonoffice_auth Auth->encryptPassword("a", Null) / : Logger{closure}(Object(Model_User)) /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/AbstractObject.php :435 Loggercall_user_func_array(Object(Closure), Array(1)) /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/Model/Table.php :555 enjouanissonoffice_auth_model_user Model_User->hook("beforeSave") /Volumes/Data/Work/Black Pig/Enjouanisson/Office/page/admin/resetpassword.php :31 enjouanissonoffice_auth_model_user Model_User->save() /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/AbstractObject.php :197 enjouanissonoffice_admin_resetpassword page_admin_resetpassword->init() /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/ApiFrontend.php :122 enjouanissonoffice Frontend->add("page_admin_resetpassword", "admin_resetpassword", "Content") /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/ApiWeb.php :399 enjouanissonoffice Frontend->layout_Content() /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/ApiFrontend.php :37 enjouanissonoffice Frontend->addLayout("Content") /Volumes/Data/Work/Black Pig/Enjouanisson/Office/atk4/lib/ApiWeb.php :271 enjouanissonoffice Frontend->initLayout() /Volumes/Data/Work/Black Pig/Enjouanisson/Office/index.php :15 enjouanissonoffice Frontend->main()
--
$m->set('password', $f->get('new_password'));
$$m->set('email', $email);
$m->update();
$m->set('password', $f->get('new_password'));$$m->set('email', $email."dirty");$m->update();class page_admin_resetpassword extends Page { function init(){ parent::init();
$this->api->addLocation('atk4-addons',array( 'php'=>'misc/lib' ));
$id = $_GET['id'];
$m =$this->api->auth->model; $m->loadData($id);
$email = $m['email'];
$this->add('P')->setHTML('<strong>Resetting password for ' . $m['email'] . '</strong>'); //shoes email in form, data is retrieved
$f = $this->add('Form'); $f->addField('password','new_password')->add('StrengthChecker',null,'after_field'); $f->addField('password','password_confirm', 'Confirm password');
$f->addSubmit('Change Password');
$f->addClass('stacked');
if($f->isSubmitted()){ if($f->get('new_password') != $f->get('password_confirm')){ $f->displayError('new_password','Passwords do not match!'); } else { $m->set('password', $f->get('new_password')); $m->set('email', $email); //shouldn't be required - testing for sticky update $m->update(); } } }}
class page_admin_resetpassword extends Page { function init(){ parent::init();
$this->api->addLocation('atk4-addons',array( 'php'=>'misc/lib' ));
$id = $_GET['id'];
$m =$this->api->auth->model; $m->loadData($id);
$this->add('P')->setHTML('<strong>Resetting password for ' . $m['full_name'] . '</strong>');
$f = $this->add('Form'); $f->setModel($this->api->auth->model,array('password')); $f->getElement('password')->set(null)->add('StrengthChecker',null,'after_field'); $f->addField('password','password_confirm', 'Confirm password');
$f->addSubmit('Change Password');
$f->addClass('stacked');
if($f->isSubmitted()){
if($f->get('password') != $f->get('password_confirm')){ $f->displayError('password','Passwords do not match!'); } else { $f->update(); } } }}$$m->set('email', $email);
function init(){ parent::init();
$tabs = $this->add('Tabs');
// Users tab $tab = $tabs->addTab("Users"); $fields['grid'] = array('full_name','email', 'is_admin'); $fields['edit'] = array('first_name','last_name','email');
if ($this->api->auth->model['is_super']) { $fields['edit'][] = "is_admin"; $fields['edit'][] = "is_super"; $allow_add = true; } else { $allow_add = false; }
$tc = $tab->add('CRUD',array('allow_add'=>$allow_add)); $tc->setModel($this->api->auth->model,$fields['edit'],$fields['grid']);
if ($tc->grid){ $tc->grid->addColumn('Button','reset_password'); $tc->grid->addOrder() ->move('reset_password','before','edit') ->now(); }
if ($this->api->auth->model['is_super']) {
if ($tc->grid){ $this->api->stickyGet('id');
if($_GET['reset_password']){ $tab->js()->univ() ->frameURL('Reset Password',$this->api->url('admin/resetpassword',array('id'=>$_GET['reset_password']))) ->execute(); } }
}
parent::init();
$this->api->addLocation('atk4-addons',array( 'php'=>'misc/lib' ));
$id = $_GET['id'];
$m = $this->setModel("User"); //have also tried $this->api->auth->model - makes no diffrence
$m->loadData($id);
$this->add('P')->setHTML('<strong>Resetting password for ' . $m['full_name'] . '</strong>');
$f = $this->add('Form'); $f->setModel("User",array('password')); //have also tried adding id to the load array $f->loadData($id); //I don't actually think I need this line anyway $f->getElement('password')->set(null)->add('StrengthChecker',null,'after_field'); $f->addField('password','password_confirm', 'Confirm password'); $f->addField('hidden','id')->set($id); //trying anything now to get it to update the record and not create new one!
$f->addSubmit('Change Password');
$f->addClass('stacked');
if($f->isSubmitted()){
if($f->get('password') != $f->get('password_confirm')){ $f->displayError('password','Passwords do not match!'); } else { $f->update(); $f->js()->univ(null,$this->js()->_selector('.autoreload')->trigger('autoreload')) ->closeDialog()->execute(); } } }}class Model_User extends Model_Table{ public $table="users";
function init(){ parent::init(); //$this->debug(); $err = "This is a required field"; $this->addField('first_name')->mandatory($err); $this->addField('last_name')->mandatory($err); $this->addField('email')->mandatory($err); $this->addField('password')->type('password')->mandatory($err); $this->addField('is_admin')->listData(array(1=>"Yes",0=>"No"))->defaultValue(0); $this->addField('is_super')->listData(array(1=>"Yes",0=>"No"))->defaultValue(0);
$this->addExpression('full_name','CONCAT (`first_name`, " " , `last_name`)');
$this->setOrder('last_name')->setOrder('first_name');
}}class Model_User extends Model_Table{ public $table="users";
function init(){ parent::init(); //$this->debug(); $err = "This is a required field"; $this->addField('first_name')->mandatory($err); $this->addField('last_name')->mandatory($err); $this->addField('email')->mandatory($err); $this->addField('password')->type('password')->mandatory($err); $this->addField('is_admin')->listData(array(1=>"Yes",0=>"No"))->defaultValue(0); $this->addField('is_super')->listData(array(1=>"Yes",0=>"No"))->defaultValue(0);
$this->addExpression('full_name','CONCAT (`first_name`, " " , `last_name`)');
$this->setOrder('last_name')->setOrder('first_name');
}}select `id`,`first_name`,`last_name`,`email`,`password`,`is_admin`,`is_super`,CONCAT (`first_name`, " " , `last_name`) `full_name` from `users` where `id` = "6" order by `users`.`last_name`, `users`.`first_name` limit 0, 1 [:a]
insert into `users` (`password`,`is_admin`,`is_super`) values ("pass",NULL,NULL) [:a_3, :a_2, :a]
select `id`,`first_name`,`last_name`,`email`,`password`,`is_admin`,`is_super`,CONCAT (`first_name`, " " , `last_name`) `full_name` from `users` where `id` = "18" order by `users`.`last_name`, `users`.`first_name` limit 0, 1 [:a]
<?phpclass page_admin_resetpassword extends Page { function init(){ parent::init();
$this->api->addLocation('atk4-addons',array( 'php'=>'misc/lib' ));
$id = $_GET['id'];
$m = $this->add("Model_User");
$m->loadData($id);
$this->add('P')->setHTML('<strong>Resetting password for ' . $m['full_name'] . '</strong>');
$f = $this->add('Form'); $f->setModel($this->api->auth->model,array("password"))->loadData($id); $f->api->stickyGet('id'); //need to call stickyGet here so that the id value will passed with form/submit url
$f->getElement('password')->set(null)->add('StrengthChecker',null,'after_field'); $f->addField('password','password_confirm', 'Confirm password');
$f->addSubmit('Change Password');
$f->addClass('stacked');
$f->onSubmit(function($f){
if($f->get('password') != $f->get('password_confirm')){ $f->displayError('password','Passwords do not match!'); } else { $f->update(); $f->js()->univ(null,$f->js()->_selector('.autoreload')->trigger('autoreload')) ->closeDialog()->execute(); } }); }}$this->api->auth->model['fullname'].$this->api->auth->model with just $m.->loadData($id) after crud->setModel, because model is already loaded (isn't it?).