0
votes

I have following login code:

if ($logged == true) {
                HTTP::redirect('profile/private');
            } else {
                $validation = Validation::factory($_POST)
                        ->rule('username', 'not_empty')
                        ->rule('password', 'not_empty');
                if ($validation->check()) {

                }
                $errors = $validation->errors('login');

The case here is if no username is entered, the proper message will be sown (I have messages in login.php file in messages folder for example: 'username' => array('not_empty' => 'Field :field can not be empty', the same for password field). And theese two rules are working properly with errors. But when both username and password are given and user is not authenticated as 'valid' (for example wrong password or mistyped username) I need one custom error message (for example: 'Check username or password, Maybe CAPSLOCK is pressed'). How to achieve this? What with error message i don't want it to be related with just one field like all messages in login.php field. Please help

2

2 Answers

1
votes

Then answering your question: this is a extra error message for user purposes. This is not a specific error on one or your model's properties (username, password), so this belongs in your controller.

Just in your controller, check if user is logged in and echo the error.

if (!Auth::instance()->login($_POST['username'], $_POST['password'], $_POST['autologin'])) 
{
    echo 'Check username or password, Maybe CAPSLOCK is pressed';
}
0
votes

according to the documentation if you call $validation->errors() with no template defined, it will give you an array of errors back, then you can look thru the $errors array and determine what kinds of errors you get, and react appropriately