diff options
author | Rodney Ewing <ewing.rj@gmail.com> | 2013-05-24 12:52:14 -0700 |
---|---|---|
committer | Rodney Ewing <ewing.rj@gmail.com> | 2013-05-27 08:58:09 -0700 |
commit | 68cc79eb4adf8046bc2a6c00d97af4fb637440f6 (patch) | |
tree | 3d07788df77709eae78a8846fe4dfc25eda434e3 /mediagoblin/auth/views.py | |
parent | 81907fa0aac7757d1c39cafef4da89f8b2bfb417 (diff) | |
download | mediagoblin-68cc79eb4adf8046bc2a6c00d97af4fb637440f6.tar.lz mediagoblin-68cc79eb4adf8046bc2a6c00d97af4fb637440f6.tar.xz mediagoblin-68cc79eb4adf8046bc2a6c00d97af4fb637440f6.zip |
added a register_user function
Diffstat (limited to 'mediagoblin/auth/views.py')
-rw-r--r-- | mediagoblin/auth/views.py | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 6a8e9a4c..574adab5 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -25,7 +25,7 @@ from mediagoblin.tools.mail import email_debug_message from mediagoblin.auth import lib as auth_lib from mediagoblin.auth import forms as auth_forms from mediagoblin.auth.lib import send_fp_verification_email -from mediagoblin.auth.tools import send_verification_email +from mediagoblin.auth.tools import send_verification_email, register_user from sqlalchemy import or_ @@ -47,38 +47,9 @@ def register(request): if request.method == 'POST' and register_form.validate(): # TODO: Make sure the user doesn't exist already - users_with_username = User.query.filter_by(username=register_form.data['username']).count() - users_with_email = User.query.filter_by(email=register_form.data['email']).count() - - extra_validation_passes = True - - if users_with_username: - register_form.username.errors.append( - _(u'Sorry, a user with that name already exists.')) - extra_validation_passes = False - if users_with_email: - register_form.email.errors.append( - _(u'Sorry, a user with that email address already exists.')) - extra_validation_passes = False - - if extra_validation_passes: - # Create the user - user = User() - user.username = register_form.data['username'] - user.email = register_form.data['email'] - user.pw_hash = auth_lib.bcrypt_gen_password_hash( - register_form.password.data) - user.verification_key = unicode(uuid.uuid4()) - user.save() - - # log the user in - request.session['user_id'] = unicode(user.id) - request.session.save() - - # send verification email - email_debug_message(request) - send_verification_email(user, request) + user = register_user(request, register_form) + if user: # redirect the user to their homepage... there will be a # message waiting for them to verify their email return redirect( |