Forums / Developer / Add extra validation on user creation
Benoit Vodkaster
Thursday 01 October 2009 2:52:49 am
Hi,
I'd like to add to extra validation on the user name entered by a new user (e.g no @ or space in the user name)
I've seen that the verifications are done in /kernel/classes/datatypes/ezuser/ezusertype.php
in the function
function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
The code I'm interested in is :
$existUser = eZUser::fetchByName( $loginName ); if ( $existUser != null ) { // ez code in case this uaser already exists } // THIS IS WHERE I'D LIKE TO ADD EXTRA CHECKS $isValidate = eZMail::validate( $email ); // all other validations ...
How can I do that without modifying the kernel (which I'd rather avoid of course :)) ?
Thank you very much in advanceBenoit
Łukasz Serwatka
Thursday 01 October 2009 3:25:37 am
You can override the kernel class in the extension.http://ezpedia.org/solution/overriding_kernel_classes_within_an_extension
Of course you have to then maintain it on your own.
Other solution which you can try is:http://serwatka.net/blog/enhanced_content_edit_handler_for_validation_rules_in_ez_publish_4_1
Personal website -> http://serwatka.net Blog (about eZ Publish) -> http://serwatka.net/blog
Bruce Morrison
Thursday 01 October 2009 5:03:42 am
Hi Benoit
There appears to be settings in site.ini that will allow you to do this without any coding. See settings/site.ini under [UserSettings]
# Custom validation of user login name # Will only affect new users, and existing users when they edit their credentials UserNameValidationRegex[] UserNameValidationErrorText[] DefaultUserNameValidationErrorText=User login name did not validate! # Examples of validation #UserNameValidationRegex[sw]=/^\s/ #UserNameValidationErrorText[sw]=The username cannot start with a whitespace. #UserNameValidationRegex[ew]=/\s$/ #UserNameValidationErrorText[ew]=The username cannot end with a whitespace. #UserNameValidationRegex[rw]=/\s+/ #UserNameValidationErrorText[rw]=The username cannot contain repeated whitespace. #UserNameValidationRegex[lb]=/\n|\r/ #UserNameValidationErrorText[lb]=The username cannot contain line breaks. #UserNameValidationRegex[t]=/\t/ #UserNameValidationErrorText[t]=The username cannot contain tabs. # Alternative example only allowing 'word' charthers #UserNameValidationRegex[w]=/\W/ #UserNameValidationErrorText[w]=The username can only contain a-z, digits or underline. # Or #UserNameValidationRegex[wh]=/[^A-Za-z0-9_-]/ #UserNameValidationErrorText[wh]=The username can only contain a-z, digits, underline or hyphen. # While testing add this at the end, just remember to remove it when your done.. #UserNameValidationRegex[test]=/\w/ #UserNameValidationErrorText[test]=The username seems to be ok!
My Blog: http://www.stuffandcontent.com/ Follow me on twitter: http://twitter.com/brucemorrison Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
André R.
Thursday 01 October 2009 7:58:22 am
The setting above was added in 4.1.
eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription @: http://twitter.com/andrerom
Piotrek Karaś
Sunday 04 October 2009 11:56:59 am
# Custom validation of user login name # Will only affect new users, and existing users when they edit their credentials
Out of curiosity, how is that possible or make sense for existing users if login name cannot change? Or can it? If your login doesn't pass validation because the validation rules had changed and then changing login is also not permitted... what am I missing here? ;)
-- Company: mediaSELF Sp. z o.o., http://www.mediaself.pl eZ references: http://ez.no/partners/worldwide_partners/mediaself eZ certified developer: http://ez.no/certification/verify/272585 eZ blog: http://ez.ryba.eu
Monday 05 October 2009 2:03:52 am
Not sure, the question never came up. Feel free to try it out and create an issue for it.
Monday 05 October 2009 5:18:55 am
As expected, new validation rules make it impossible to (re)publish the user object if the login contains characters out of range.Created an issue for it: http://issues.ez.no/IssueView.php?Id=15621
Cheers,Piotrek