This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/account/classes/controller/user/account.php
2011-05-03 09:49:04 +10:00

116 lines
2.8 KiB
PHP

<?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
*/
class Controller_User_Account extends Controller_TemplateDefault {
public $secure_actions = array(
'edit'=>TRUE,
'resetpassword'=>TRUE,
);
public function action_resetpassword() {
$ao = Auth::instance()->get_user();
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$ao->id));
// @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
$ao->values($_POST);
// Run validation and save
if ($ao->changed())
if ($ao->check()) {
SystemMessage::add(array(
'title'=>_('Record updated'),
'type'=>'info',
'body'=>_('Your account record has been updated.')
));
$ao->save();
Request::instance()->redirect('login');
} else {
SystemMessage::add(array(
'title'=>_('Record NOT updated'),
'type'=>'error',
'body'=>_('Your updates didnt pass validation.')
));
foreach ($ao->validate()->errors('form_errors') as $field => $error)
SystemMessage::add(array(
'title'=>$field,
'type'=>'error',
'body'=>$error,
));
}
Block::add(array(
'title'=>_('Password Reset'),
'body'=>View::factory('account/password_reset')
->set('record',$ao),
));
$this->template->content = Block::factory();
}
/**
* Show a product
*/
public function action_edit() {
$ao = Auth::instance()->get_user();
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$ao->id));
// Store our new values
$ao->values($_POST);
// Run validation and save
if ($ao->changed())
if ($ao->check()) {
SystemMessage::add(array(
'title'=>_('Record updated'),
'type'=>'info',
'body'=>_('Your account record has been updated.')
));
$ao->save();
} else {
SystemMessage::add(array(
'title'=>_('Record NOT updated'),
'type'=>'error',
'body'=>_('Your updates didnt pass validation.')
));
foreach ($ao->validate()->errors('form_errors') as $field => $error)
SystemMessage::add(array(
'title'=>$field,
'type'=>'error',
'body'=>$error,
));
}
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Account Edit'),$ao->accnum(),$ao->name(TRUE)),
'body'=>View::factory('account/edit')
->set('record',$ao),
));
$this->template->content = Block::factory();
}
}
?>