Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Brett Conoly
username not accepting special characters
March 19, 2009 11:00 AM
Answer

Brett Conoly

Rank: Regular Member

Posts: 121

Join Date: July 19, 2007

Recent Posts

It seems that liferay's user names don't allow for any special characters, is there any way we can change this and allow the user name to contain any amount of special characters?
Thanks
Minhchau Dang
RE: username not accepting special characters
March 19, 2009 11:12 AM
Answer

Minhchau Dang

LIFERAY STAFF

Rank: Expert

Posts: 349

Join Date: October 22, 2007

Recent Posts

Usernames are used as the friendly URL for each user's personal page, so allowing special characters which aren't accepted in the URL path defined in RFC-1738 would be a bad idea.

However, if you still wish to allow for it (and accept the consequence that user pages for users with screen names that have special characters will not be accessible without additional Liferay customizations), it's possible by writing your own ScreenNameValidator and setting the users.screen.name.validator property in your portal-ext.properties.
Brett Conoly
RE: username not accepting special characters
March 19, 2009 11:19 AM
Answer

Brett Conoly

Rank: Regular Member

Posts: 121

Join Date: July 19, 2007

Recent Posts

Awesome, that's exactly what i needed to know, we're not currently using personal pages but I don't think we want to limit their use in the future...
Brett Conoly
RE: username not accepting special characters
March 20, 2009 8:46 AM
Answer

Brett Conoly

Rank: Regular Member

Posts: 121

Join Date: July 19, 2007

Recent Posts

Ok, it seems that we are going to try to allow special characters in the user name but after I implemented the ScreenNameValidator it is allowing special characters but the add user method is still giving the message to enter a valid screen name. So it seems that something else is preventing the use of special characters. Does anyone have a clue what this might be?
Thanks
Manish Kumar Gupta
RE: username not accepting special characters
March 20, 2009 9:07 AM
Answer

Manish Kumar Gupta

LIFERAY STAFF

Rank: Liferay Master

Posts: 535

Join Date: May 15, 2008

Recent Posts

This restriction may be from portal-impl/src/com/liferay/portal/service/impl/UserLocalServiceImpl
Minhchau Dang
RE: username not accepting special characters
March 20, 2009 11:27 AM
Answer

Minhchau Dang

LIFERAY STAFF

Rank: Expert

Posts: 349

Join Date: October 22, 2007

Recent Posts

You're right. My mistake, there was an additional validation in validateScreenName() beyond the ScreenNameValidator. This is the code that does the additional validation:

1for (char c : screenName.toCharArray()) {
2    if ((!Validator.isChar(c)) && (!Validator.isDigit(c)) &&
3        (c != CharPool.DASH) && (c != CharPool.PERIOD) &&
4        (c != CharPool.UNDERLINE)) {
5
6        throw new UserScreenNameException();
7    }
8}

You'll have to extend the existing UserLocalServiceImpl and override the validateScreenName() method to not do the additional validation. Then, update the Spring configuration to let it know to use your new UserLocalServiceImpl in ext-spring.xml

1<bean id="com.liferay.portal.service.UserLocalService.impl"
2    class="com.package.CustomUserLocalServiceImpl" />
Christian Merkel
RE: username not accepting special characters
January 21, 2010 3:12 AM
Answer

Christian Merkel

Rank: Regular Member

Posts: 111

Join Date: December 14, 2009

Recent Posts

hi,

i got exectly the same problem!

I've found the files that makes the validation.

I got user-screen-names like "AB#123"

If i create a user in backend with such a user id it is changed to "AB-123".

so i take the source of liferay, go to:
portal-impl
com.liferay.portal.util.FriendlyURLNormalizer and remove the '#' from _REPLACE_CHARS

com.liferay.portal.service.impl.UserLocalServiceImpl and changed following in the validateScreenName() Methode:
1        for (char c : screenName.toCharArray()) {
2            if ((!Validator.isChar(c)) && (!Validator.isDigit(c)) &&
3                (c != CharPool.DASH) && (c != CharPool.PERIOD) &&
4                (c != CharPool.UNDERLINE)[color=#FD0303] && (c != CharPool.POUND)[/color]) {
5
6                throw new UserScreenNameException();
7            }
8        }



Is this correct so far??
Or do ihave to create a own class and copy the whole method?

can i copy the modified files into the portal-impl.jar ?
Shagul Khajamohideen
RE: username not accepting special characters
January 21, 2010 7:21 AM
Answer

Shagul Khajamohideen

Rank: Liferay Master

Posts: 759

Join Date: September 27, 2007

Recent Posts

Hi,

Take a look at the below forum on how to extend Liferay. You should find more related articles in Wiki's and Blog's.

Best Regards,
Shagul