#11894 closed enhancement (worksforme)
Make (clear that) username policy (is) configurable
Reported by: | anonymous | Owned by: | Steffen Hoffmann |
---|---|---|---|
Priority: | normal | Component: | AccountManagerPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: |
Description (last modified by )
It seems it is hard coded the username policy. I think it would be nice if it could be configured in the trac.ini file.
Example, I don't want the minimum of 5 chars long user names.
I found the code, but I don't know python.
register.py
:
username_regexp = Option('account-manager', 'username_regexp', r'(?i)^[A-Z0-9.\-_]{5,}$', doc="A validation regular expression describing new usernames.")
couldn't it be loaded from the ini file like:
def validate_registration(self, req): acctmgr = AccountManager(self.env) """ New """ regexp = req.args.get('username.regexp', ''); if regexp="" username_regexp = Option('account-manager', 'username_regexp', r'(?i)^[A-Z0-9.\-_]{5,}$', doc="A validation regular expression describing new usernames.") else: username_regexp = Option('account-manager', 'username_regexp', regexp, """ Notice I dont know how to handle the r'...' """ doc="A validation regular expression describing new usernames.") """ End new username = acctmgr.handle_username_casing( req.args.get('username', '').strip()) if self.username_regexp != "" and \ not re.match(self.username_regexp.strip(), username): raise RegistrationError(N_( "Username %s doesn't match local naming policy."), tag.b(username) ) ...
Of course cleaning up constants and so on.
Attachments (0)
Change History (16)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 10 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Replying to anonymous:
Example, I don't want the minimum of 5 chars long user names. I found the code, but I don't know python.
register.py
:username_regexp = Option('account-manager', 'username_regexp', r'(?i)^[A-Z0-9.\-_]{5,}$', doc="A validation regular expression describing new usernames.")
That's an Option
, so it can be set from trac.ini. Look on the TracIni page of your installation for more details. AccountManagerPlugin must be enabled to see its documentation on TracIni and we are using it on this site, so you can just look at TracIni#account-manager-section.
Add the following to trac.ini:
[account-manager] username_regexp = (?i)^[A-Z0-9.\-_]{5,}$
and modify the value on the right-hand side to meet your needs.
comment:4 follow-up: 9 Changed 10 years ago by
Thanks rjollos. I actually tried something like that and didn't work out... I might have done it wrong. I will check it out again. BTW, shouldn't the tickets be closed by the one who opened it? (as best-practice I mean).
comment:5 follow-up: 10 Changed 10 years ago by
confirmed! it did work! I think I just inserted the "r'" in the past... As a hint, I never saw the documentation you are referencing to, so it is my fault. However I did search (google) and never find it :(
I advise adding more info to the description: "A validation regular expression describing new usernames." (such as description for allow_delete_account "Allow users to delete their own account.")
"Allows the definition of constraints of allowed user names. A validation regular expression describing new usernames." (or something like the first sentence, which defines the purpose: why someone would want to use this parameter beyond how internally it's done). That would help people find. Notice that in the beginning of a search !nobody -beyond insiders- knows that it is through a regular expression or even that it is a parameter in the ini file.
Thanks again for the help. :D
PS. So, IMO, now it would be the time to close the ticket :) solution confirmed by the reporter. :D
comment:6 Changed 10 years ago by
Thanks for the suggestions about improving the documentation for username_regexp
. I added that to my todo list and will try to make sure it gets done before the next major release.
comment:8 Changed 10 years ago by
Sorry for responding a bit later, but Ryan already was pretty much helpful - thanks.
Replying to anonymous:
Example, I don't want the minimum of 5 chars long user names.
I'm pretty much sure there are no sensible usernames with 1 or 2 characters. If it doesn't apply to you, this is fine. It is not Python, just a bit of regular expression foo, that many site on the internet offer information upon, but you may even guess to alter the number in brackets to another more suitable value, i.e. {5,}
--> {3,}
. And super-long names won't be great either, so you could even like an upper limit as well: {3,50}
.
comment:9 follow-up: 11 Changed 10 years ago by
Replying to luis.robledano.iwes:
Thanks rjollos. I actually tried something like that and didn't work out... I might have done it wrong. I will check it out again. BTW, shouldn't the tickets be closed by the one who opened it? (as best-practice I mean).
It depends, but because this is a development ticket system, the code author or developer in charge shall rule, no? Personally I prefer user feed-back, but tend to close tickets after confirmation but rarely before availability of the changes in a stable release.
IMHO it's largely a matter of taste, because there are a couple of pros and cons for a great variety of approaches.
comment:10 follow-up: 12 Changed 10 years ago by
Replying to luis.robledano.iwes:
However I did search (google) and never find it :(
Lesson to learn: Trac is so much self-documenting, that it pays of much more to search for it in TracWiki before trying anything else.
I advise adding more info to the description: "A validation regular expression describing new usernames." "Allows the definition of constraints of allowed user names. A validation regular expression describing new usernames." (or something like the first sentence, which defines the purpose: why someone would want to use this parameter beyond how internally it's done).
I see. My take:
A validation regular expression describing new usernames. Define constraints for allowed user names corresponding to local naming policy. - Here you even have the hint keywords 'local naming policy'. Initially I planned to even go for an optional configurable link to a (TracWiki) page describing that policy.
That would help people find. Notice that in the beginning of a search !nobody -beyond insiders- knows that it is through a regular expression or even that it is a parameter in the ini file.
Configuration of Trac is largely done through trac.ini
or a bit more point-n-click-friendly through the Trac web admin interface. But by the time you ask questions like the one you did, your bound to learn about TracIni, one way or another.
For what its worth MailingLists are the preferred way for beginners anyway. A great red box above our new ticket form tells just that, but I know, such disclaimers are never clear enough. :-)
comment:11 Changed 10 years ago by
Replying to hasienda:
It depends, but because this is a development ticket system, the code author or developer in charge shall rule, no?
IMHO, no. But that would be for another ticket/discussion ;)
comment:12 Changed 10 years ago by
I see. My take:
A validation regular expression describing new usernames. Define constraints for allowed user names corresponding to local naming policy. - Here you even have the hint keywords 'local naming policy'. Initially I planned to even go for an optional configurable link to a (TracWiki) page describing that policy.
For me perfect. You have a very good point there, use same text as in the error message! :D
PS. It is still luis here, this and previous comment. I´m having problems with login...
comment:13 Changed 10 years ago by
Summary: | User Name policy configurable? → Make (clear that) username policy (is) configurable |
---|
comment:15 follow-up: 16 Changed 7 years ago by
It would be great if the admin can configure a custom message describing the policy (I'm assuming they can configure the policy too). For a visitor who wants to register, just saying "doesn't match local naming policy" is so unhelpful! At the very least, it should say something like: should be at least 5 characters, not have spaces and only contain these: a-z A-Z 0-9 . - _
Actually I (am the same as the reporter, I just registered afterwards) changed manually the could and rebuilt and update the plugin... but still get the error
"Username abc doesn't match local naming policy."