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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:28:12
Script start
Timing: Jan 18 2025 11:28:12
Module start 'layout'
Timing: Jan 18 2025 11:28:12
Module start 'content'
Timing: Jan 18 2025 11:28:13
Module end 'content'
Timing: Jan 18 2025 11:28:13
Script end

Main resources:

Total runtime0.9339 sec
Peak memory usage4,096.0000 KB
Database Queries75

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 589.4453152.6250
Module start 'layout' 0.00800.0045 742.070339.4453
Module start 'content' 0.01240.9203 781.5156727.9141
Module end 'content' 0.93270.0011 1,509.429720.1563
Script end 0.9338  1,529.5859 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3868160.0002
Check MTime0.00150.1608160.0001
Mysql Total
Database connection0.00120.123710.0012
Mysqli_queries0.859892.0720750.0115
Looping result0.00090.0935730.0000
Template Total0.894995.820.4474
Template load0.00180.197720.0009
Template processing0.893095.625220.4465
Template load and register function0.00010.015010.0001
states
state_id_array0.00130.141710.0013
state_identifier_array0.00130.143520.0007
Override
Cache load0.00160.1748440.0000
Sytem overhead
Fetch class attribute can translate value0.00050.055150.0001
Fetch class attribute name0.00120.1306110.0001
XML
Image XML parsing0.00210.228250.0004
class_abstraction
Instantiating content class attribute0.00000.0020130.0000
General
dbfile0.00180.1912380.0000
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 40
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs