2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace Backend\Controllers;
|
|
|
|
|
2014-07-01 17:17:53 +10:00
|
|
|
use Lang;
|
2014-05-14 23:24:20 +10:00
|
|
|
use Backend;
|
|
|
|
use Redirect;
|
|
|
|
use BackendMenu;
|
|
|
|
use BackendAuth;
|
|
|
|
use Backend\Classes\Controller;
|
2014-07-24 15:19:00 +11:00
|
|
|
use System\Classes\SettingsManager;
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend user controller
|
|
|
|
*
|
|
|
|
* @package october\backend
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Users extends Controller
|
|
|
|
{
|
|
|
|
public $implement = [
|
|
|
|
'Backend.Behaviors.FormController',
|
|
|
|
'Backend.Behaviors.ListController'
|
|
|
|
];
|
|
|
|
|
|
|
|
public $formConfig = 'config_form.yaml';
|
|
|
|
public $listConfig = 'config_list.yaml';
|
|
|
|
|
|
|
|
public $requiredPermissions = ['backend.manage_users'];
|
|
|
|
|
|
|
|
public $bodyClass = 'compact-container';
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
2014-07-01 17:17:53 +10:00
|
|
|
if ($this->action == 'myaccount')
|
2014-06-16 21:12:50 +10:00
|
|
|
$this->requiredPermissions = null;
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
BackendMenu::setContext('October.System', 'system', 'users');
|
2014-07-27 15:07:22 +11:00
|
|
|
SettingsManager::setContext('October.System', 'administrators');
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update controller
|
|
|
|
*/
|
|
|
|
public function update($recordId, $context = null)
|
|
|
|
{
|
|
|
|
// Users cannot edit themselves, only use My Settings
|
2014-07-01 17:17:53 +10:00
|
|
|
if ($context != 'myaccount' && $recordId == $this->user->id)
|
|
|
|
return Redirect::to(Backend::url('backend/users/myaccount'));
|
2014-05-14 23:24:20 +10:00
|
|
|
|
2014-08-23 09:41:48 +10:00
|
|
|
return $this->asExtension('FormController')->update($recordId, $context);
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* My Settings controller
|
|
|
|
*/
|
2014-07-01 17:17:53 +10:00
|
|
|
public function myaccount()
|
2014-05-14 23:24:20 +10:00
|
|
|
{
|
2014-07-24 15:19:00 +11:00
|
|
|
SettingsManager::setContext('October.Backend', 'myaccount');
|
|
|
|
|
2014-07-01 17:17:53 +10:00
|
|
|
$this->pageTitle = Lang::get('backend::lang.myaccount.menu_label');
|
|
|
|
return $this->update($this->user->id, 'myaccount');
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxy update onSave event
|
|
|
|
*/
|
2014-07-01 17:17:53 +10:00
|
|
|
public function myaccount_onSave()
|
2014-05-14 23:24:20 +10:00
|
|
|
{
|
2014-08-23 09:41:48 +10:00
|
|
|
$result = $this->asExtension('FormController')->update_onSave($this->user->id, 'myaccount');
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the password or login name has been updated, reauthenticate the user
|
|
|
|
*/
|
|
|
|
$loginChanged = $this->user->login != post('User[login]');
|
|
|
|
$passwordChanged = strlen(post('User[password]'));
|
|
|
|
if ($loginChanged || $passwordChanged)
|
|
|
|
BackendAuth::login($this->user->reload(), true);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add available permission fields to the User form.
|
|
|
|
*/
|
2014-10-08 18:54:45 +11:00
|
|
|
protected function formExtendFields($form)
|
2014-05-14 23:24:20 +10:00
|
|
|
{
|
2014-10-08 18:54:45 +11:00
|
|
|
if ($form->getContext() == 'myaccount')
|
2014-05-14 23:24:20 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
$permissionFields = [];
|
|
|
|
foreach (BackendAuth::listPermissions() as $permission) {
|
|
|
|
|
|
|
|
$fieldName = 'permissions['.$permission->code.']';
|
|
|
|
$fieldConfig = [
|
|
|
|
'label' => $permission->label,
|
|
|
|
'comment' => $permission->comment,
|
|
|
|
'type' => 'balloon-selector',
|
|
|
|
'options' => [
|
2014-08-12 21:46:19 +01:00
|
|
|
1 => 'backend::lang.user.allow',
|
|
|
|
0 => 'backend::lang.user.inherit',
|
|
|
|
-1 => 'backend::lang.user.deny',
|
2014-05-14 23:24:20 +10:00
|
|
|
],
|
|
|
|
'attributes' => [
|
|
|
|
'data-trigger' => "input[name='User[permissions][superuser]']",
|
|
|
|
'data-trigger-type' => 'disable',
|
|
|
|
'data-trigger-condition' => 'checked',
|
|
|
|
],
|
|
|
|
'span' => 'auto',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (isset($permission->tab))
|
|
|
|
$fieldConfig['tab'] = $permission->tab;
|
|
|
|
|
|
|
|
$permissionFields[$fieldName] = $fieldConfig;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:54:45 +11:00
|
|
|
$form->addTabFields($permissionFields);
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
}
|