Validating a user attribute on login form

Permalink
Can anyone guide me to the answer please!. I have to set up new users manually which involves assigning them a particular number. I have set this up in the user attributes in the User & Groups. There is an option to add the field to the registration form but not to the login form. As the user won't know what number I've assigned until their registration has been processed I need it on the login form. I also need to validate that the number the user enters is correct... I have created the input field on the login page but can't see / hack the validation.

leertes
 
jordanlev replied on at Permalink Reply
jordanlev
This is not going to be easy to do with the system's built-in login form.

I think it might be easier to create a single_page for this purpose (because you only want people to enter the number the first time they log in, not every time they log in after that, right?).

By creating a single_page for this, you then have complete manual control over the logic of this functionality, without having to worry about how concrete5's login validation works and without having to hack it at all.

Perhaps you can create 2 groups in your system, one for unverified users and another for verified. When you first register them, put them in the unverified group. Change the permissions on your site so only verified people can access certain pages. Then in your single_page that checks the number, you can programatically add the person to the verified users group. Now they will be able to access all of those protected pages.

If you search around the docs and forums for how to create single_pages and how to programatically add users to groups, you should be able to find the resources you need to make this happen.

Good luck!

-Jordan
domwhooley replied on at Permalink Reply
Similarly, i'm looking to add a check box to the login page form that gets validated (when checked) on login. Any ideas?
jordanlev replied on at Permalink Reply
jordanlev
Add your question as a user attribute. Go to Dashboard -> Users and Groups -> User Attributes, scroll down to "Add User Attribute", choose "Checkbox" from the dropdown. When you're entering the attribute info, check the box for "required".
domwhooley replied on at Permalink Reply
Nice one jordanlev. I thought there must be a simple way of achieving what I wanted to do. However, having just had a go at implementing it, it's not quite what I was looking for. Adding the attribute is fine, and great I can add it on the registration form. But I needed this to be an option that appears on a custom themed Single Pages - Login page form by default every time. And unless i've missed something your way doesn't achieve that?

I have since managed to achieve this by hacking / hijaking, the 'remember me on login' check box (which doesn't seem to do anything btw):

<?php echo $form->checkbox('uDisclaimerLogin', 1)?> <label for="uDisclaimerLogin"><?php echo t('I agree to the disclaimer')?></label>


and validating it in the controller/login.php page with:

// My validation efforts
if (!$this->post('uDisclaimerLogin', 1)) {
   throw new Exception(t('Please accept the disclaimer.'));
}


After getting the validation working from this helpful posthttp://www.concrete5.org/documentation/how-tos/designers/themimg-sy...

Not the most elegant solution I know, but it works and that'll do me.