Skip to content

Commit

Permalink
Changed controller config variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
LEWE, GEORGE committed Mar 18, 2024
1 parent 180be3b commit e7becb7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/Config/AuthInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AuthInfo extends BaseConfig {
*
* @var string
*/
public $version = '3.4.0';
public $version = '3.5.0';

/**
* --------------------------------------------------------------------------
Expand Down
66 changes: 33 additions & 33 deletions src/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AuthController extends BaseController {
/**
* @var AuthConfig
*/
protected $config;
protected $authConfig;

/**
* @var Session
Expand Down Expand Up @@ -57,10 +57,10 @@ public function __construct() {
// Most services in this controller require the session to be started
//
$this->session = service('session');
$this->config = config('Auth');
$this->authConfig = config('Auth');
$this->auth = service('authentication');
$this->authorize = service('authorization');
$this->tfa = new TwoFactorAuth($this->config->authenticatorTitle);
$this->tfa = new TwoFactorAuth($this->authConfig->authenticatorTitle);
$this->passphrase = hex2bin('8849523a8e0e1ff45f440da048428b2554d2660c80957fcedbeb9575c079d7eb');
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public function activateAccount() {
* @return mixed
*/
public function activateAccountResend() {
if ($this->config->requireActivation === null) {
if ($this->authConfig->requireActivation === null) {
return redirect()->route('login');
}

Expand Down Expand Up @@ -144,19 +144,19 @@ public function activateAccountResend() {
* Displays the CI4-Auth error page.
*/
public function error() {
return $this->_render($this->config->views[ 'error_auth' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'error_auth' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
/**
* Displays the forgot password form.
*/
public function forgotPassword() {
if ($this->config->activeResetter === null) {
if ($this->authConfig->activeResetter === null) {
return redirect()->route('login')->with('error', lang('Auth.forgot.disabled'));
}

return $this->_render($this->config->views[ 'forgot' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'forgot' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
Expand All @@ -165,7 +165,7 @@ public function forgotPassword() {
* password reset instructions to them.
*/
public function forgotPasswordDo() {
if ($this->config->activeResetter === null) {
if ($this->authConfig->activeResetter === null) {
return redirect()->route('login')->with('error', lang('Auth.forgot.disabled'));
}

Expand Down Expand Up @@ -213,7 +213,7 @@ public function login() {
//
$_SESSION[ 'redirect_url' ] = session('redirect_url') ?? previous_url() ?? site_url('/');

return $this->_render($this->config->views[ 'login' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'login' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
Expand All @@ -226,7 +226,7 @@ public function loginDo() {
'password' => 'required',
];

if ($this->config->validFields == [ 'email' ]) {
if ($this->authConfig->validFields == [ 'email' ]) {
$rules[ 'login' ] .= '|valid_email';
}

Expand Down Expand Up @@ -277,7 +277,7 @@ public function loginDo() {
//
// User has not setup 2FA.
//
if ($this->config->require2FA) {
if ($this->authConfig->require2FA) {
//
// 2FA is required. Login the user and redirect to 2FA Setup.
//
Expand Down Expand Up @@ -329,9 +329,9 @@ public function login2fa() {
$user = $users->where('email', session('2fa_in_progress'))->first();

return $this->_render(
$this->config->views[ 'login2fa' ],
$this->authConfig->views[ 'login2fa' ],
[
'config' => $this->config,
'config' => $this->authConfig,
'user' => $user,
'remember' => session('ci4auth-remember'),
]
Expand Down Expand Up @@ -393,9 +393,9 @@ public function login2faDo() {
$qrcode = $this->tfa->getQRCodeImageAsDataUri($user->email, $secret);
session()->setFlashdata('error', lang('Auth.2fa.setup.mismatch'));
return $this->_render(
$this->config->views[ 'login2fa' ],
$this->authConfig->views[ 'login2fa' ],
[
'config' => $this->config,
'config' => $this->authConfig,
'user' => $user,
'remember' => session('ci4auth-remember'),
]
Expand Down Expand Up @@ -431,9 +431,9 @@ public function register() {
//
// Redirect back with error if registration is not allowed
//
if (!$this->config->allowRegistration) return redirect()->back()->withInput()->with('error', lang('Auth.register.disabled'));
if (!$this->authConfig->allowRegistration) return redirect()->back()->withInput()->with('error', lang('Auth.register.disabled'));

return $this->_render($this->config->views[ 'register' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'register' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
Expand All @@ -444,7 +444,7 @@ public function registerDo() {
//
// Check if registration is allowed
//
if (!$this->config->allowRegistration) return redirect()->back()->withInput()->with('error', lang('Auth.register.disabled'));
if (!$this->authConfig->allowRegistration) return redirect()->back()->withInput()->with('error', lang('Auth.register.disabled'));

$users = model(UserModel::class);

Expand Down Expand Up @@ -474,19 +474,19 @@ public function registerDo() {
//
// Save the user
//
$allowedPostFields = array_merge([ 'password' ], $this->config->validFields, $this->config->personalFields);
$allowedPostFields = array_merge([ 'password' ], $this->authConfig->validFields, $this->authConfig->personalFields);
$user = new User($this->request->getPost($allowedPostFields));

$this->config->requireActivation === null ? $user->activate() : $user->generateActivateHash();
$this->authConfig->requireActivation === null ? $user->activate() : $user->generateActivateHash();

//
// Ensure default role gets assigned if set
//
if (!empty($this->config->defaultUserRole)) $users = $users->withRole($this->config->defaultUserRole);
if (!empty($this->authConfig->defaultUserRole)) $users = $users->withRole($this->authConfig->defaultUserRole);

if (!$users->save($user)) return redirect()->back()->withInput()->with('errors', $users->errors());

if ($this->config->requireActivation !== null) {
if ($this->authConfig->requireActivation !== null) {
$activator = service('activator');
$sent = $activator->send($user);
if (!$sent) return redirect()->back()->withInput()->with('error', $activator->error() ?? lang('Auth.exception.unknown_error'));
Expand All @@ -507,14 +507,14 @@ public function registerDo() {
* Displays the Reset Password form.
*/
public function resetPassword() {
if ($this->config->activeResetter === null) {
if ($this->authConfig->activeResetter === null) {
return redirect()->route('login')->with('error', lang('Auth.forgot.disabled'));
}

$token = $this->request->getGet('token');

return $this->_render($this->config->views[ 'reset' ], [
'config' => $this->config,
return $this->_render($this->authConfig->views[ 'reset' ], [
'config' => $this->authConfig,
'token' => $token,
]);
}
Expand All @@ -527,7 +527,7 @@ public function resetPassword() {
* @return mixed
*/
public function resetPasswordDo() {
if ($this->config->activeResetter === null) {
if ($this->authConfig->activeResetter === null) {
return redirect()->route('login')->with('error', lang('Auth.forgot.disabled'));
}

Expand Down Expand Up @@ -660,9 +660,9 @@ public function setup2fa($secret = null) {
// Render the page
//
return $this->_render(
$this->config->views[ 'setup2fa' ],
$this->authConfig->views[ 'setup2fa' ],
[
'config' => $this->config,
'config' => $this->authConfig,
'qrcode' => $qrcode,
'secret' => $secret,
'user' => $user,
Expand Down Expand Up @@ -728,9 +728,9 @@ public function setup2faDo() {
$qrcode = $this->tfa->getQRCodeImageAsDataUri($user->email, $secret);
session()->setFlashdata('error', lang('Auth.2fa.setup.mismatch'));
return $this->_render(
$this->config->views[ 'setup2fa' ],
$this->authConfig->views[ 'setup2fa' ],
[
'config' => $this->config,
'config' => $this->authConfig,
'qrcode' => $qrcode,
'secret' => $secret,
'user' => $user,
Expand All @@ -751,23 +751,23 @@ public function setup2faDo() {
* Displays the About page.
*/
public function about() {
return $this->_render($this->config->views[ 'about' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'about' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
/**
* Displays the Welcome page.
*/
public function welcome() {
return $this->_render($this->config->views[ 'welcome' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'welcome' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
/**
* Displays the Whoami page.
*/
public function whoami() {
return $this->_render($this->config->views[ 'whoami' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'whoami' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions src/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GroupController extends BaseController {
/**
* @var AuthConfig
*/
protected $config;
protected $authConfig;

/**
* @var Session
Expand All @@ -37,7 +37,7 @@ public function __construct() {
// Most services in this controller require the session to be started
//
$this->session = service('session');
$this->config = config('Auth');
$this->authConfig = config('Auth');
$this->auth = service('authorization');
$this->validation = service('validation');
}
Expand All @@ -53,7 +53,7 @@ public function groups() {
$allGroups = $groups->orderBy('name', 'asc')->findAll();

$data = [
'config' => $this->config,
'config' => $this->authConfig,
'groups' => $allGroups,
];

Expand All @@ -79,7 +79,7 @@ public function groups() {
if (!$groups->deleteGroup($recId)) {

$this->session->set('errors', $groups->errors());
return $this->_render($this->config->views[ 'groups' ], $data);
return $this->_render($this->authConfig->views[ 'groups' ], $data);
}
return redirect()->route('groups')->with('success', lang('Auth.group.delete_success', [ $group->name ]));
}
Expand All @@ -94,7 +94,7 @@ public function groups() {
}
}

return $this->_render($this->config->views[ 'groups' ], $data);
return $this->_render($this->authConfig->views[ 'groups' ], $data);
}

//---------------------------------------------------------------------------
Expand All @@ -104,7 +104,7 @@ public function groups() {
* @return string
*/
public function groupsCreate($id = null): string {
return $this->_render($this->config->views[ 'groupsCreate' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'groupsCreate' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -179,8 +179,8 @@ public function groupsEdit($id = null) {
$permissions = $this->auth->permissions();
$groupPermissions = $groups->getPermissionsForGroup($id);

return $this->_render($this->config->views[ 'groupsEdit' ], [
'config' => $this->config,
return $this->_render($this->authConfig->views[ 'groupsEdit' ], [
'config' => $this->authConfig,
'group' => $group,
'permissions' => $permissions,
'groupPermissions' => $groupPermissions,
Expand Down
16 changes: 8 additions & 8 deletions src/Controllers/PermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PermissionController extends BaseController {
/**
* @var AuthConfig
*/
protected $config;
protected $authConfig;

/**
* @var Session
Expand All @@ -37,7 +37,7 @@ public function __construct() {
// Most services in this controller require the session to be started
//
$this->session = service('session');
$this->config = config('Auth');
$this->authConfig = config('Auth');
$this->auth = service('authorization');
$this->validation = service('validation');
}
Expand All @@ -52,7 +52,7 @@ public function permissions() {
$permissions = model(PermissionModel::class);

$data = [
'config' => $this->config,
'config' => $this->authConfig,
'permissions' => $permissions->orderBy('name', 'asc')->findAll(),
];

Expand All @@ -70,7 +70,7 @@ public function permissions() {
} else {
if (!$permissions->deletePermission($recId)) {
$this->session->set('errors', $permissions->errors());
return $this->_render($this->config->views[ 'permissions' ], $data);
return $this->_render($this->authConfig->views[ 'permissions' ], $data);
}
return redirect()->route('permissions')->with('success', lang('Auth.permission.delete_success', [ $permission->name ]));
}
Expand All @@ -88,15 +88,15 @@ public function permissions() {
//
// Show the list view
//
return $this->_render($this->config->views[ 'permissions' ], $data);
return $this->_render($this->authConfig->views[ 'permissions' ], $data);
}

//---------------------------------------------------------------------------
/**
* Displays the user create page.
*/
public function permissionsCreate($id = null) {
return $this->_render($this->config->views[ 'permissionsCreate' ], [ 'config' => $this->config ]);
return $this->_render($this->authConfig->views[ 'permissionsCreate' ], [ 'config' => $this->authConfig ]);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -169,8 +169,8 @@ public function permissionsEdit($id = null) {
$permRoles = $permissions->getRolesForPermission($id);
$permUsers = $permissions->getUsersForPermission($id);

return $this->_render($this->config->views[ 'permissionsEdit' ], [
'config' => $this->config,
return $this->_render($this->authConfig->views[ 'permissionsEdit' ], [
'config' => $this->authConfig,
'permission' => $permission,
'permGroups' => $permGroups,
'permRoles' => $permRoles,
Expand Down
Loading

0 comments on commit e7becb7

Please sign in to comment.