mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-24 07:17:55 +01:00
feat(login): 🐛 Aggiunta validazione form
This commit is contained in:
parent
9949ebdc58
commit
9e7f3371b5
@ -43,13 +43,15 @@ class AuthController extends Controller
|
|||||||
private function rules(Request $request): array
|
private function rules(Request $request): array
|
||||||
{
|
{
|
||||||
$additional_validation = '';
|
$additional_validation = '';
|
||||||
|
$db_field = 'username';
|
||||||
if (filter_var($request->input('username'), FILTER_VALIDATE_EMAIL)) {
|
if (filter_var($request->input('username'), FILTER_VALIDATE_EMAIL)) {
|
||||||
$additional_validation = '|email';
|
$additional_validation = '|email';
|
||||||
|
$db_field = 'email';
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'username' => 'required'.$additional_validation,
|
'username' => "required|string|exists:users,$db_field|$additional_validation",
|
||||||
'password' => 'required',
|
'password' => 'required|string',
|
||||||
'remember' => 'boolean',
|
'remember' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import Mdi from '../Components/Mdi.jsx';
|
|||||||
import Page from '../Components/Page.jsx';
|
import Page from '../Components/Page.jsx';
|
||||||
import {
|
import {
|
||||||
getFormData,
|
getFormData,
|
||||||
|
isFormValid,
|
||||||
showSnackbar
|
showSnackbar
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
|
|
||||||
@ -27,10 +28,10 @@ export default class LoginPage extends Page {
|
|||||||
<img src={logoUrl} className="center stretch" alt={__('OpenSTAManager')}/>
|
<img src={logoUrl} className="center stretch" alt={__('OpenSTAManager')}/>
|
||||||
<form id="login" style="padding: 16px; text-align: center;">
|
<form id="login" style="padding: 16px; text-align: center;">
|
||||||
<h3 style="margin-top: 0;">{__('Accedi')}</h3>
|
<h3 style="margin-top: 0;">{__('Accedi')}</h3>
|
||||||
<text-field label={__('Nome utente/email')} id="username" name="username" style="margin-bottom: 16px;">
|
<text-field label={__('Nome utente/email')} id="username" name="username" required style="margin-bottom: 16px;">
|
||||||
<Mdi icon="account-outline" slot="icon"/>
|
<Mdi icon="account-outline" slot="icon"/>
|
||||||
</text-field>
|
</text-field>
|
||||||
<text-field label={__('Password')} id="password" name="password" type="password">
|
<text-field label={__('Password')} id="password" name="password" required type="password">
|
||||||
<Mdi icon="lock-outline" slot="icon"/>
|
<Mdi icon="lock-outline" slot="icon"/>
|
||||||
</text-field>
|
</text-field>
|
||||||
<mwc-formfield label={__('Ricordami')} style="display: block;">
|
<mwc-formfield label={__('Ricordami')} style="display: block;">
|
||||||
@ -58,8 +59,14 @@ export default class LoginPage extends Page {
|
|||||||
async onLoginButtonClicked() {
|
async onLoginButtonClicked() {
|
||||||
this.loading.show();
|
this.loading.show();
|
||||||
|
|
||||||
const formData = getFormData($(this.element)
|
const form = $(this.element).find('#login');
|
||||||
.find('#login'));
|
|
||||||
|
if (!isFormValid(form)) {
|
||||||
|
this.loading.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = getFormData(form);
|
||||||
|
|
||||||
formData._token = $('meta[name="csrf-token"]').attr('content');
|
formData._token = $('meta[name="csrf-token"]').attr('content');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user