We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



17.0k
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 :)



17.0k
edited May '14

Yet, this validation happens :)

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?



17.0k

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



17.0k
Accepted
answer

I have found it out.

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