commit/galaxy-central: dan: Add a transform_publicname method that coerces a provided string into a valid username. This is now used during user creation.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/7ca527380818/ changeset: 7ca527380818 user: dan date: 2012-04-19 16:16:30 summary: Add a transform_publicname method that coerces a provided string into a valid username. This is now used during user creation. affected #: 2 files diff -r d346bd2efc9798547ba9a4ac80d305ee6d7aedcc -r 7ca52738081826b32f57d43eff6510bd2cc1bdba lib/galaxy/security/validate_user_input.py --- a/lib/galaxy/security/validate_user_input.py +++ b/lib/galaxy/security/validate_user_input.py @@ -1,6 +1,8 @@ import re VALID_PUBLICNAME_RE = re.compile( "^[a-z0-9\-]+$" ) +VALID_PUBLICNAME_SUB = re.compile( "[^a-z0-9\-]" ) +FILL_CHAR = '-' def validate_email( trans, email, user=None, check_dup=True ): message = '' @@ -31,6 +33,19 @@ return "Public name is taken; please choose another" return '' +def transform_publicname( trans, publicname, user=None ): + # User names must be at least four characters in length and contain only lower-case + # letters, numbers, and the '-' character. + #TODO: Enhance to allow generation of semi-random publicnnames e.g., when valid but taken + if user and user.username == publicname: + return publicname + elif publicname not in [ 'None', None, '' ]: + publicname = publicname.lower() + publicname = re.sub( VALID_PUBLICNAME_SUB, FILL_CHAR, publicname ) + if not trans.sa_session.query( trans.app.model.User ).filter_by( username=publicname ).first(): + return publicname + return '' + def validate_password( trans, password, confirm ): if len( password ) < 6: return "Use a password of at least 6 characters" diff -r d346bd2efc9798547ba9a4ac80d305ee6d7aedcc -r 7ca52738081826b32f57d43eff6510bd2cc1bdba lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py +++ b/lib/galaxy/web/controllers/user.py @@ -10,7 +10,7 @@ from galaxy.web.form_builder import * from galaxy.util.json import from_json_string, to_json_string from galaxy.web.framework.helpers import iff -from galaxy.security.validate_user_input import validate_email, validate_publicname, validate_password +from galaxy.security.validate_user_input import validate_email, validate_publicname, validate_password, transform_publicname log = logging.getLogger( __name__ ) @@ -341,7 +341,7 @@ email=email, password='', confirm='', - username=username, + username=transform_publicname( trans, username ), header='', use_panels=use_panels, redirect=redirect, @@ -581,7 +581,7 @@ email=email, password=password, confirm=confirm, - username=username, + username=transform_publicname( trans, username ), subscribe_checked=subscribe_checked, user_type_fd_id_select_field=user_type_fd_id_select_field, user_type_form_definition=user_type_form_definition, Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket