2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides User Account Update functions
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage Account
|
|
|
|
* @category Controllers/User
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
2011-08-26 01:16:48 +00:00
|
|
|
class Controller_User_Account extends Controller_TemplateDefault_User {
|
|
|
|
protected $secure_actions = array(
|
2010-11-29 22:41:08 +00:00
|
|
|
'edit'=>TRUE,
|
|
|
|
'resetpassword'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
public function action_resetpassword() {
|
|
|
|
// @todo Fix this next logic, since matches_ifset is not being called when the value is on the form, but empty
|
|
|
|
if (empty($_POST['password_confirm']))
|
|
|
|
$_POST['password_confirm'] = ' ';
|
|
|
|
|
|
|
|
// Store our new values
|
2011-08-26 01:16:48 +00:00
|
|
|
$this->ao->values($_POST);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
// Run validation and save
|
2011-08-26 01:16:48 +00:00
|
|
|
if ($this->ao->changed())
|
|
|
|
if ($this->ao->check()) {
|
2010-11-29 22:41:08 +00:00
|
|
|
SystemMessage::add(array(
|
|
|
|
'title'=>_('Record updated'),
|
|
|
|
'type'=>'info',
|
|
|
|
'body'=>_('Your account record has been updated.')
|
|
|
|
));
|
|
|
|
|
2011-08-26 01:16:48 +00:00
|
|
|
$this->ao->save();
|
2011-05-14 07:35:33 +00:00
|
|
|
Request::current()->redirect('login');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
} else {
|
2011-05-14 07:35:33 +00:00
|
|
|
$output = '';
|
2011-08-26 01:16:48 +00:00
|
|
|
foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
|
2011-05-14 07:35:33 +00:00
|
|
|
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
|
|
|
|
|
|
|
|
if ($output)
|
|
|
|
$output = sprintf('<ul>%s</ul>',$output);
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
SystemMessage::add(array(
|
|
|
|
'title'=>_('Record NOT updated'),
|
|
|
|
'type'=>'error',
|
2011-05-14 07:35:33 +00:00
|
|
|
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
|
2010-11-29 22:41:08 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Password Reset'),
|
|
|
|
'body'=>View::factory('account/password_reset')
|
2011-08-26 01:16:48 +00:00
|
|
|
->set('record',$this->ao),
|
2010-11-29 22:41:08 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a product
|
|
|
|
*/
|
|
|
|
public function action_edit() {
|
|
|
|
// Store our new values
|
2011-08-26 01:16:48 +00:00
|
|
|
$this->ao->values($_POST);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
// Run validation and save
|
2011-08-26 01:16:48 +00:00
|
|
|
if ($this->ao->changed())
|
|
|
|
if ($this->ao->check()) {
|
2010-11-29 22:41:08 +00:00
|
|
|
SystemMessage::add(array(
|
|
|
|
'title'=>_('Record updated'),
|
|
|
|
'type'=>'info',
|
|
|
|
'body'=>_('Your account record has been updated.')
|
|
|
|
));
|
|
|
|
|
2011-08-26 01:16:48 +00:00
|
|
|
$this->ao->save();
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
} else {
|
2011-05-14 07:35:33 +00:00
|
|
|
$output = '';
|
2011-08-26 01:16:48 +00:00
|
|
|
foreach ($this->ao->validation()->errors('forms/login') as $field => $error)
|
2011-05-14 07:35:33 +00:00
|
|
|
$output .= sprintf('<li><b>%s</b> %s</li>',$field,$error);
|
|
|
|
|
|
|
|
if ($output)
|
|
|
|
$output = sprintf('<ul>%s</ul>',$output);
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
SystemMessage::add(array(
|
|
|
|
'title'=>_('Record NOT updated'),
|
|
|
|
'type'=>'error',
|
2011-05-14 07:35:33 +00:00
|
|
|
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
|
2010-11-29 22:41:08 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
2011-08-26 01:16:48 +00:00
|
|
|
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$this->ao->accnum(),$this->ao->name(TRUE)),
|
2011-08-27 06:33:46 +00:00
|
|
|
'body'=>View::factory('account/user/edit')
|
2011-08-26 01:16:48 +00:00
|
|
|
->set('record',$this->ao),
|
2010-11-29 22:41:08 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|