Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Verifications in INVO

Good day everyone. I have two questions regarding verification in INVO example.

  1. I have built a validator in model User that checks if password field is longer than 8 characters. The problem is, when SessionController registerAction sends $password variable to model, it is already encrypted with sha1 and therefore model validator considers it longer that 8 characters and the validation passes, which shouldn't. Any suggestions?

  2. In this registration form , I dont understand how warnigs like ''Warning! Please provide a valid password'' are generated if I dont enter the password. Where is the validation code that shows the warning? What activates the warning?

Since I'm a beginner, I would appreciate long explainations :P

Thank you all :)

1

I would add a check like this one here

https://github.com/phalcon/invo/blob/master/app/controllers/SessionController.php#L33

that checks the password length and if not 8 or more sets the relevant flash error message and returns false. This way you know how long your password is before it is hashed.

2

The validation comes from the model. It the record is correctly saved then all good otherwise the validate function provides the necessary messages back to the caller and the controller then sends them to the flash object

https://github.com/phalcon/invo/blob/master/app/models/Users.php#L8 https://github.com/phalcon/invo/blob/master/app/controllers/SessionController.php#L98

edited May '14
  1. This one checks if passwords are the same . But how do I check for length? If strlen($a)=8 ?

  2. I think you are not referring to right thing. In session/register there is this :

    if ($password != $repeatPassword) { $this->flash->error('Passwords are diferent'); return false; }

But if you enter different password, warning you get is

<div class="alert"id="repeatPassword_alert"><strong>Warning!</strong>The password does not match</div> which is from views/session/register.volt .

What activates that one ?

Yes strlen will allow you to do that check. I would use this:

if (strlen(trim($password)) > 7) {
....
}

I don't know about the warning you get. The block of code you present is present in the volt template but I cannot see how it is activated if at all. All I see is that for the registration page the $flash->error() messages are the ones that cause any error message (or success) to show up on screen.

Play around with it. Change the test in the template and see what causes it. Change text in the controller or th emodel. You will soon figure out how things work :)

edited May '14

Yet, this validation happens :) VALIDATION

So far I have realised that when i remove this part * 'onclick': 'return SignUp.validate();' * from the submut button code:

{{ submit_button('Register', 'class': 'btn btn-primary btn-large', 'onclick': 'return SignUp.validate();') }}

the validation doesn't happen. Is this some javascript from bootstrap or HTML5 javascript for required elements, or jquery? It calls for SignUp.validate() function, where can i find it?

Sorry but i'd like to BUMP this one. I still dont understand where is this function 'onclick': 'return SignUp.validate();' which validates as shown on picture above. Example is from INVO



9.8k
Accepted
answer

I have found it out.

'onclick': 'return SignUp.validate(); calls for a javascript validation in public/js/utils.js .