Skip to content

Commit

Permalink
Labelling the field names for better language-support
Browse files Browse the repository at this point in the history
Refs #444
  • Loading branch information
daftspunk committed Aug 19, 2021
1 parent a03663e commit f346907
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions components/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,13 @@ public function onSignin()

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

$messages = (new UserModel)->customMessages;
$validation = Validator::make(
$data,
$rules,
$this->getValidatorMessages(),
$this->getCustomAttributes()
);

$validation = Validator::make($data, $rules, $messages);
if ($validation->fails()) {
throw new ValidationException($validation);
}
Expand Down Expand Up @@ -296,9 +300,13 @@ public function onRegister()
unset($rules['username']);
}

$messages = (new UserModel)->customMessages;
$validation = Validator::make(
$data,
$rules,
$this->getValidatorMessages(),
$this->getCustomAttributes()
);

$validation = Validator::make($data, $rules, $messages);
if ($validation->fails()) {
throw new ValidationException($validation);
}
Expand Down Expand Up @@ -333,7 +341,7 @@ public function onRegister()
}

$intended = false;

/*
* Activation is by the admin, show message
* For automatic email on account activation RainLab.Notify plugin is needed
Expand Down Expand Up @@ -618,4 +626,26 @@ protected function isRegisterThrottled()

return UserModel::isRegisterThrottled(Request::ip());
}

/**
* getValidatorMessages
*/
protected function getValidatorMessages(): array
{
return (array) (new UserModel)->customMessages;
}

/**
* getCustomAttributes
*/
protected function getCustomAttributes(): array
{
return [
'login' => $this->loginAttributeLabel(),
'password' => Lang::get('rainlab.user::lang.account.password'),
'email' => Lang::get('rainlab.user::lang.account.email'),
'username' => Lang::get('rainlab.user::lang.user.username'),
'name' => Lang::get('rainlab.user::lang.account.full_name')
];
}
}

0 comments on commit f346907

Please sign in to comment.