-
I try to use validFields to login with username Is this function operational? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Yes, you can.
public array $views = [
'login' => '\App\Views\Shield\login',
]; and comment /**
* --------------------------------------------------------------------
* Valid login fields
* --------------------------------------------------------------------
* Fields that are available to be used as credentials for login.
*/
public array $validFields = [
//'email',
'username',
];
<!-- Email -->
<div class="mb-2">
<input type="text" class="form-control" name="username" placeholder="<?= lang('Auth.usernam') ?>" value="<?= old('username') ?>" required />
</div>
protected function getValidationRules(): array
{
return setting('Validation.login') ?? [
'username' => config('AuthSession')->usernameValidationRules,
// 'email' => config('AuthSession')->emailValidationRules,
'password' => 'required',
];
} I have not tested but it should work. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to log in with a username or email using the same input box? like GitHub. |
Beta Was this translation helpful? Give feedback.
Yes, you can.
app/Config/Auth.php
and comment
email
and uncommentusername
:vendor\codeigniter4\shield\src\Views\login.php
toapp\Views\Shield\login.php
and edit :