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/application/classes/Controller/User/Account.php

106 lines
2.9 KiB
PHP
Raw Normal View History

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
* @category Controllers/User
* @author Deon George
2013-03-19 22:35:19 +00:00
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
2010-11-29 22:41:08 +00:00
*/
class Controller_User_Account extends Controller_Account {
2011-08-26 01:16:48 +00:00
protected $secure_actions = array(
2010-11-29 22:41:08 +00:00
'edit'=>TRUE,
'resetpassword'=>TRUE,
);
/**
* Enable User to Edit their Account Details
*/
public function action_edit() {
2010-11-29 22:41:08 +00:00
// 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()) {
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your account record has been updated.'));
2010-11-29 22:41:08 +00:00
2011-08-26 01:16:48 +00:00
$this->ao->save();
2011-09-27 11:22:13 +00:00
2010-11-29 22:41:08 +00:00
} else {
2011-05-14 07:35:33 +00:00
$output = '';
// @todo Need to check that this still works with the new bootstrap theming
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);
SystemMessage::factory()
->title(_('Record NOT updated'))
->type('error')
->body(_('Your updates didnt pass validation.').'<br/>'.$output);
2010-11-29 22:41:08 +00:00
}
Block::factory()
->title(sprintf('Account: %s',$this->ao->accnum()))
->title_icon('icon-wrench')
->type('form-horizontal')
->body(View::factory('account/user/edit')->set('o',$this->ao));
2010-11-29 22:41:08 +00:00
}
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'] = ' ';
2010-11-29 22:41:08 +00:00
// 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()) {
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Your account record has been updated.'));
2010-11-29 22:41:08 +00:00
2011-08-26 01:16:48 +00:00
$this->ao->save();
2010-11-29 22:41:08 +00:00
// Log the password reset
$this->ao->log('Password reset');
HTTP::redirect('login');
2010-11-29 22:41:08 +00:00
} else {
// @todo Need to check that this still works with the new bootstrap theming
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);
SystemMessage::factory()
->title(_('Record NOT updated'))
->type('error')
->body(_('Your updates didnt pass validation.').'<br/>'.$output);
2010-11-29 22:41:08 +00:00
}
// @todo To add JS password validation (minimum length and both values equal)
Block::factory()
->title(sprintf('Password Reset: %s',$this->ao->accnum()))
->title_icon('icon-cog')
->type('form-horizontal')
->body(View::factory('account/user/resetpassword')->set('o',$this->ao));
2010-11-29 22:41:08 +00:00
}
}
?>