Skip to content

Commit

Permalink
Run CodeIgniter4 Coding Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
mjamilasfihani committed Jul 1, 2022
1 parent 782ac1d commit 8babd47
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
40 changes: 23 additions & 17 deletions src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class Auth extends BaseConfig
* @var array
*/
public $reservedRoutes = [
'login' => 'login',
'logout' => 'logout',
'register' => 'register',
'activate-account' => 'activate-account',
'login' => 'login',
'logout' => 'logout',
'register' => 'register',
'activate-account' => 'activate-account',
'resend-activate-account' => 'resend-activate-account',
'forgot' => 'forgot',
'reset-password' => 'reset-password',
'forgot' => 'forgot',
'reset-password' => 'reset-password',
];

/**
Expand All @@ -74,11 +74,11 @@ class Auth extends BaseConfig
* @var array
*/
public $views = [
'login' => 'Myth\Auth\Views\login',
'register' => 'Myth\Auth\Views\register',
'forgot' => 'Myth\Auth\Views\forgot',
'reset' => 'Myth\Auth\Views\reset',
'emailForgot' => 'Myth\Auth\Views\emails\forgot',
'login' => 'Myth\Auth\Views\login',
'register' => 'Myth\Auth\Views\register',
'forgot' => 'Myth\Auth\Views\forgot',
'reset' => 'Myth\Auth\Views\reset',
'emailForgot' => 'Myth\Auth\Views\emails\forgot',
'emailActivation' => 'Myth\Auth\Views\emails\activation',
];

Expand Down Expand Up @@ -252,7 +252,7 @@ class Auth extends BaseConfig
* If you choose to use any ARGON algorithm, then you might want to
* uncomment the "ARGON2i/D Algorithm" options to suit your needs
*
* @var string|int
* @var int|string
*/
public $hashAlgorithm = PASSWORD_DEFAULT;

Expand All @@ -271,13 +271,19 @@ class Auth extends BaseConfig
* cost. This makes the hashing process takes longer.
*/

/** @var int */
/**
* @var int
*/
public $hashMemoryCost = 2048; // PASSWORD_ARGON2_DEFAULT_MEMORY_COST;

/** @var int */
/**
* @var int
*/
public $hashTimeCost = 4; // PASSWORD_ARGON2_DEFAULT_TIME_COST;

/** @var int */
/**
* @var int
*/
public $hashThreads = 4; // PASSWORD_ARGON2_DEFAULT_THREADS;

/**
Expand Down Expand Up @@ -342,7 +348,7 @@ class Auth extends BaseConfig
public $userActivators = [
'Myth\Auth\Authentication\Activators\EmailActivator' => [
'fromEmail' => null,
'fromName' => null,
'fromName' => null,
],
];

Expand All @@ -358,7 +364,7 @@ class Auth extends BaseConfig
public $userResetters = [
'Myth\Auth\Authentication\Resetters\EmailResetter' => [
'fromEmail' => null,
'fromName' => null,
'fromName' => null,
],
];

Expand Down
2 changes: 1 addition & 1 deletion src/Filters/BaseFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct()
$config = config(AuthConfig::class);

// Load the routes
$this->landingRoute = $config->landingRoute;
$this->landingRoute = $config->landingRoute;
$this->reservedRoutes = $config->reservedRoutes;

// Load the authenticate service
Expand Down
6 changes: 2 additions & 4 deletions src/Filters/LoginFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Myth\Auth\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class LoginFilter extends BaseFilter implements FilterInterface
{
/**
* Verifies that a user is logged in, or redirects to login.
*
* @param RequestInterface $request
* @param array|null $params
*
* @return mixed
Expand All @@ -28,13 +27,12 @@ public function before(RequestInterface $request, $params = null)
// If no user is logged in then send them to the login form.
if (! $this->authenticate->check()) {
session()->set('redirect_url', current_url());

return redirect($this->reservedRoutes['login']);
}
}

/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @param array|null $arguments
*
* @return void
Expand Down
15 changes: 7 additions & 8 deletions src/Filters/PermissionFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Myth\Auth\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
use Myth\Auth\Exceptions\PermissionException;

class PermissionFilter extends BaseFilter implements FilterInterface
Expand All @@ -19,8 +19,7 @@ class PermissionFilter extends BaseFilter implements FilterInterface
* sent back to the client, allowing for error pages,
* redirects, etc.
*
* @param RequestInterface $request
* @param array|null $params
* @param array|null $params
*
* @return mixed
*/
Expand All @@ -29,6 +28,7 @@ public function before(RequestInterface $request, $params = null)
// If no user is logged in then send them to the login form.
if (! $this->authenticate->check()) {
session()->set('redirect_url', current_url());

return redirect($this->reservedRoutes['login']);
}

Expand All @@ -47,10 +47,11 @@ public function before(RequestInterface $request, $params = null)
if ($this->authenticate->silent()) {
$redirectURL = session('redirect_url') ?? route_to($this->landingRoute);
unset($_SESSION['redirect_url']);

return redirect()->to($redirectURL)->with('error', lang('Auth.notEnoughPrivilege'));
} else {
throw new PermissionException(lang('Auth.notEnoughPrivilege'));
}

throw new PermissionException(lang('Auth.notEnoughPrivilege'));
}
}

Expand All @@ -60,9 +61,7 @@ public function before(RequestInterface $request, $params = null)
* to stop execution of other after filters, short of
* throwing an Exception or Error.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param array|null $arguments
* @param array|null $arguments
*
* @return void
*/
Expand Down
15 changes: 7 additions & 8 deletions src/Filters/RoleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Myth\Auth\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
use Myth\Auth\Exceptions\PermissionException;

class RoleFilter extends BaseFilter implements FilterInterface
Expand All @@ -19,8 +19,7 @@ class RoleFilter extends BaseFilter implements FilterInterface
* sent back to the client, allowing for error pages,
* redirects, etc.
*
* @param RequestInterface $request
* @param array|null $params
* @param array|null $params
*
* @return mixed
*/
Expand All @@ -29,6 +28,7 @@ public function before(RequestInterface $request, $params = null)
// If no user is logged in then send them to the login form.
if (! $this->authenticate->check()) {
session()->set('redirect_url', current_url());

return redirect($this->reservedRoutes['login']);
}

Expand All @@ -46,10 +46,11 @@ public function before(RequestInterface $request, $params = null)
if ($this->authenticate->silent()) {
$redirectURL = session('redirect_url') ?? route_to($this->landingRoute);
unset($_SESSION['redirect_url']);

return redirect()->to($redirectURL)->with('error', lang('Auth.notEnoughPrivilege'));
} else {
throw new PermissionException(lang('Auth.notEnoughPrivilege'));
}

throw new PermissionException(lang('Auth.notEnoughPrivilege'));
}

/**
Expand All @@ -58,9 +59,7 @@ public function before(RequestInterface $request, $params = null)
* to stop execution of other after filters, short of
* throwing an Exception or Error.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param array|null $arguments
* @param array|null $arguments
*
* @return void
*/
Expand Down

0 comments on commit 8babd47

Please sign in to comment.