Forums / Developer / Add extra validation on user creation

Add extra validation on user creation

Author Message

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 advance
Benoit

Łukasz Serwatka

Thursday 01 October 2009 3:25:37 am

Hi,

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

André R.

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.

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ś

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

--
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

eZ debug

Timing: Jan 30 2025 20:31:53
Script start
Timing: Jan 30 2025 20:31:53
Module start 'content'
Timing: Jan 30 2025 20:31:53
Module end 'content'
Timing: Jan 30 2025 20:31:53
Script end

Main resources:

Total runtime0.4576 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0553 587.9531370.2891
Module start 'content' 0.05530.0590 958.24221,013.6563
Module end 'content' 0.11430.3357 1,971.89843,902.9609
Script end 0.4501  5,874.8594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.03868.4257200.0019
Check MTime0.01122.4453200.0006
Mysql Total
Database connection0.02244.900910.0224
Mysqli_queries0.191641.86111410.0014
Looping result0.00150.32341390.0000
Template Total0.335373.310.3353
Template load0.00511.109410.0051
Template processing0.330272.160410.3302
Override
Cache load0.00481.040810.0048
Sytem overhead
Fetch class attribute can translate value0.00210.458910.0021
XML
Image XML parsing0.00030.069410.0003
General
dbfile0.02475.3885200.0012
String conversion0.00000.001530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs