Skip to content

Commit 540a4ff

Browse files
der-Onbennothommo
andauthored
uses custom validation message for login types (#47)
Co-authored-by: Ben Thomson <[email protected]>
1 parent 9c1798b commit 540a4ff

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

components/Account.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,25 @@ public function onSignin()
194194
*/
195195
$data = post();
196196
$rules = [];
197+
$messages = [];
197198

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

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

205+
$messages['login'] = $this->loginAttribute() == UserSettings::LOGIN_USERNAME
206+
? trans('winter.user::lang.account.invalid_username')
207+
: trans('winter.user::lang.account.invalid_email');
208+
204209
if (!array_key_exists('login', $data)) {
205210
$data['login'] = post('username', post('email'));
206211
}
207212

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

210-
$validation = Validator::make($data, $rules);
215+
$validation = Validator::make($data, $rules, $messages);
211216
if ($validation->fails()) {
212217
throw new ValidationException($validation);
213218
}

lang/de/lang.php

+2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182
'force_secure_desc' => 'Verwende für Weiterleitungen immer das HTTPS-Protokoll.',
183183
'invalid_activation_code' => 'Ungültiger Aktivierungscode übermittelt',
184184
'invalid_deactivation_pass' => 'Das eingegebene Passwort war ungültig.',
185+
'invalid_username' => 'Der eingegebene Nutzername ist ungültig.',
186+
'invalid_email' => 'Die eingegebene E-Mail ist ungültig.',
185187
'success_activation' => 'Benutzerkonto erfolgreich aktiviert.',
186188
'success_deactivation' => 'Konto erfolgreich deaktiviert. Schade, dass du gehst!',
187189
'success_saved' => 'Einstellungen erfolgreich gespeichert!',

lang/en/lang.php

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@
178178
'invalid_activation_code' => 'Invalid activation code supplied.',
179179
'invalid_deactivation_pass' => 'The password you entered was invalid.',
180180
'invalid_current_pass' => 'The current password you entered was invalid.',
181+
'invalid_username' => 'The username you have entered is invalid.',
182+
'invalid_email' => 'The email address you have entered is invalid.',
181183
'success_activation' => 'Successfully activated your account.',
182184
'success_deactivation' => 'Successfully deactivated your account. Sorry to see you go!',
183185
'success_saved' => 'Settings successfully saved!',

0 commit comments

Comments
 (0)