Skip to content

Commit

Permalink
uses custom validation message for login types (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Thomson <git@alfreido.com>
  • Loading branch information
der-On and bennothommo committed Feb 20, 2024
1 parent 9c1798b commit 540a4ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,25 @@ public function onSignin()
*/
$data = post();
$rules = [];
$messages = [];

$rules['login'] = $this->loginAttribute() == UserSettings::LOGIN_USERNAME
? 'required|between:2,255'
: 'required|email|between:6,255';

$rules['password'] = 'required|between:' . UserModel::getMinPasswordLength() . ',255';

$messages['login'] = $this->loginAttribute() == UserSettings::LOGIN_USERNAME
? trans('winter.user::lang.account.invalid_username')
: trans('winter.user::lang.account.invalid_email');

if (!array_key_exists('login', $data)) {
$data['login'] = post('username', post('email'));
}

$data['login'] = trim($data['login']);

$validation = Validator::make($data, $rules);
$validation = Validator::make($data, $rules, $messages);
if ($validation->fails()) {
throw new ValidationException($validation);
}
Expand Down
2 changes: 2 additions & 0 deletions lang/de/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
'force_secure_desc' => 'Verwende für Weiterleitungen immer das HTTPS-Protokoll.',
'invalid_activation_code' => 'Ungültiger Aktivierungscode übermittelt',
'invalid_deactivation_pass' => 'Das eingegebene Passwort war ungültig.',
'invalid_username' => 'Der eingegebene Nutzername ist ungültig.',
'invalid_email' => 'Die eingegebene E-Mail ist ungültig.',
'success_activation' => 'Benutzerkonto erfolgreich aktiviert.',
'success_deactivation' => 'Konto erfolgreich deaktiviert. Schade, dass du gehst!',
'success_saved' => 'Einstellungen erfolgreich gespeichert!',
Expand Down
2 changes: 2 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
'invalid_activation_code' => 'Invalid activation code supplied.',
'invalid_deactivation_pass' => 'The password you entered was invalid.',
'invalid_current_pass' => 'The current password you entered was invalid.',
'invalid_username' => 'The username you have entered is invalid.',
'invalid_email' => 'The email address you have entered is invalid.',
'success_activation' => 'Successfully activated your account.',
'success_deactivation' => 'Successfully deactivated your account. Sorry to see you go!',
'success_saved' => 'Settings successfully saved!',
Expand Down

0 comments on commit 540a4ff

Please sign in to comment.