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
|
|
|
*/
|
2013-04-04 22:42:29 +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,
|
|
|
|
);
|
|
|
|
|
2013-04-04 22:42:29 +00:00
|
|
|
/**
|
|
|
|
* 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()) {
|
2013-04-26 01:42:09 +00:00
|
|
|
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 = '';
|
2013-04-26 01:42:09 +00:00
|
|
|
|
|
|
|
// @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);
|
|
|
|
|
2013-04-26 01:42:09 +00:00
|
|
|
SystemMessage::factory()
|
|
|
|
->title(_('Record NOT updated'))
|
|
|
|
->type('error')
|
|
|
|
->body(_('Your updates didnt pass validation.').'<br/>'.$output);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 01:42:09 +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
|
|
|
}
|
|
|
|
|
2013-04-04 22:42:29 +00:00
|
|
|
public function action_resetpassword() {
|
2013-06-05 14:03:55 +00:00
|
|
|
if ($this->request->post()) {
|
|
|
|
$validation = Validation::factory($this->request->post())
|
|
|
|
->rule('password','not_empty')
|
|
|
|
->rule('password','min_length',array(':value',6))
|
|
|
|
->rule('password_confirm','matches',array(':validation',':field','password'));
|
2013-04-04 22:42:29 +00:00
|
|
|
|
2013-06-05 14:03:55 +00:00
|
|
|
// Store our new values
|
|
|
|
$this->ao->values($this->request->post());
|
2011-05-14 07:35:33 +00:00
|
|
|
|
2013-06-05 14:03:55 +00:00
|
|
|
if (! $validation->check())
|
2013-04-26 01:42:09 +00:00
|
|
|
SystemMessage::factory()
|
|
|
|
->title(_('Record NOT updated'))
|
|
|
|
->type('error')
|
2013-06-05 14:03:55 +00:00
|
|
|
->body(_('Your password didnt pass validation.'));
|
|
|
|
|
|
|
|
// Run validation and save
|
|
|
|
elseif ($this->ao->changed())
|
|
|
|
if ($this->ao->save()) {
|
|
|
|
SystemMessage::factory()
|
|
|
|
->title('Record updated')
|
|
|
|
->type('success')
|
|
|
|
->body(_('Your account record has been updated.'));
|
|
|
|
|
|
|
|
// Log the password reset
|
|
|
|
$this->ao->log('Password reset');
|
|
|
|
|
|
|
|
HTTP::redirect('login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure())
|
|
|
|
Script::factory()
|
|
|
|
->type('src')
|
|
|
|
->data('media/js/jquery/jquery.validate-1.11.1.min.js');
|
|
|
|
else
|
|
|
|
Script::factory()
|
|
|
|
->type('src')
|
|
|
|
->data('http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js');
|
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
->type('stdin')
|
|
|
|
->data('
|
|
|
|
$("#reset").validate({
|
|
|
|
wrapper: "div",
|
|
|
|
errorElement: "span",
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
password_confirm: {
|
|
|
|
equalTo: "input[name=password]",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
highlight: function(element) {
|
|
|
|
$(element).parents(".control-group").removeClass("success").addClass("error");
|
|
|
|
},
|
|
|
|
success: function(element) {
|
|
|
|
$(element).parents(".control-group").removeClass("error").addClass("success");
|
|
|
|
},
|
|
|
|
errorPlacement: function(error, element) {
|
|
|
|
error.appendTo(element.parents(".controls"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2013-04-26 01:42:09 +00:00
|
|
|
Block::factory()
|
|
|
|
->title(sprintf('Password Reset: %s',$this->ao->accnum()))
|
|
|
|
->title_icon('icon-cog')
|
2013-06-05 14:03:55 +00:00
|
|
|
->id('reset')
|
2013-04-26 01:42:09 +00:00
|
|
|
->type('form-horizontal')
|
|
|
|
->body(View::factory('account/user/resetpassword')->set('o',$this->ao));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|