Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/addons/jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class LoginController extends BaseController
$rules = $this->getValidationRules();

// Validate credentials
if (! $this->validateData($this->request->getJSON(true), $rules)) {
if (! $this->validateData($this->request->getJSON(true), $rules, [], config('Auth')->DBGroup)) {
return $this->fail(
['errors' => $this->validator->getErrors()],
$this->codes['unauthorized']
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/mobile_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LoginController extends BaseController
],
];

if (! $this->validateData($this->request->getPost(), $rules)) {
if (! $this->validateData($this->request->getPost(), $rules, [], config('Auth')->DBGroup)) {
return $this->response
->setJSON(['errors' => $this->validator->getErrors()])
->setStatusCode(401);
Expand Down
10 changes: 10 additions & 0 deletions src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class Auth extends BaseConfig
'magic-link-email' => '\CodeIgniter\Shield\Views\Email\magic_link_email',
];

/**
* --------------------------------------------------------------------
* Customize the DB group used for each model
* --------------------------------------------------------------------
* if no database connection instance is passed to the constructor,
* it will automatically connect to the default database group,
* as set in the configuration
Comment thread
arashsaffari marked this conversation as resolved.
Outdated
*/
public ?string $DBGroup = null;

/**
* --------------------------------------------------------------------
* Customize Name of Shield Tables
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function loginAction(): RedirectResponse
// like the password, can only be validated properly here.
$rules = $this->getValidationRules();

if (! $this->validateData($this->request->getPost(), $rules)) {
if (! $this->validateData($this->request->getPost(), $rules, [], config('Auth')->DBGroup)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/MagicLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function loginAction()
{
// Validate email format
$rules = $this->getValidationRules();
if (! $this->validateData($this->request->getPost(), $rules)) {
if (! $this->validateData($this->request->getPost(), $rules, [], config('Auth')->DBGroup)) {
return redirect()->route('magic-link')->with('errors', $this->validator->getErrors());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function registerAction(): RedirectResponse
// like the password, can only be validated properly here.
$rules = $this->getValidationRules();

if (! $this->validateData($this->request->getPost(), $rules)) {
if (! $this->validateData($this->request->getPost(), $rules, [], config('Auth')->DBGroup)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class CreateAuthTables extends Migration

public function __construct(?Forge $forge = null)
{
parent::__construct($forge);

/** @var Auth $authConfig */
$authConfig = config('Auth');
$this->tables = $authConfig->tables;
$this->attributes = ($this->db->getPlatform() === 'MySQLi') ? ['ENGINE' => 'InnoDB'] : [];

$this->DBGroup = $authConfig->DBGroup;
parent::__construct($forge);
Comment thread
arashsaffari marked this conversation as resolved.
}

public function up(): void
Expand Down
11 changes: 11 additions & 0 deletions src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ abstract class BaseModel extends Model
*/
protected array $tables;
Comment thread
arashsaffari marked this conversation as resolved.

public function __construct()
{
$authConfig = config('Auth');

if (! empty($authConfig->DBGroup)) {
$this->DBGroup = $authConfig->DBGroup;
}
Comment thread
arashsaffari marked this conversation as resolved.
Outdated

parent::__construct();
}

protected function initialize(): void
{
/** @var Auth $authConfig */
Comment thread
arashsaffari marked this conversation as resolved.
Outdated
Expand Down