Redirect to the user's profile after registration

- Updated the view
 - Updated the tests
 - Fixed a weirdness in the registration view where the 'user'
   variable used to be called 'entry'
This commit is contained in:
Christopher Allan Webber 2011-07-29 08:22:26 -05:00
parent 7074304c91
commit 0bc036209d
3 changed files with 16 additions and 12 deletions

View File

@ -19,9 +19,6 @@ from routes.route import Route
auth_routes = [ auth_routes = [
Route('mediagoblin.auth.register', '/register/', Route('mediagoblin.auth.register', '/register/',
controller='mediagoblin.auth.views:register'), controller='mediagoblin.auth.views:register'),
Route('mediagoblin.auth.register_success', '/register/success/',
template='mediagoblin/auth/register_success.html',
controller='mediagoblin.views:simple_template_render'),
Route('mediagoblin.auth.login', '/login/', Route('mediagoblin.auth.login', '/login/',
controller='mediagoblin.auth.views:login'), controller='mediagoblin.auth.views:login'),
Route('mediagoblin.auth.logout', '/logout/', Route('mediagoblin.auth.logout', '/logout/',

View File

@ -55,16 +55,23 @@ def register(request):
else: else:
# Create the user # Create the user
entry = request.db.User() user = request.db.User()
entry['username'] = request.POST['username'].lower() user['username'] = request.POST['username'].lower()
entry['email'] = request.POST['email'] user['email'] = request.POST['email']
entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash( user['pw_hash'] = auth_lib.bcrypt_gen_password_hash(
request.POST['password']) request.POST['password'])
entry.save(validate=True) user.save(validate=True)
send_verification_email(entry, request) send_verification_email(user, request)
return redirect(request, "mediagoblin.auth.register_success") messages.add_message(
request,
messages.INFO,
('Registration successful! '
'You should get a registration email soon.'))
return redirect(
request, 'mediagoblin.user_pages.user_home',
user=user['username'])
return render_to_response( return render_to_response(
request, request,

View File

@ -153,9 +153,9 @@ def test_register_views(test_app):
## Did we redirect to the proper page? Use the right template? ## Did we redirect to the proper page? Use the right template?
assert_equal( assert_equal(
urlparse.urlsplit(response.location)[2], urlparse.urlsplit(response.location)[2],
'/auth/register/success/') '/u/happygirl/')
assert util.TEMPLATE_TEST_CONTEXT.has_key( assert util.TEMPLATE_TEST_CONTEXT.has_key(
'mediagoblin/auth/register_success.html') 'mediagoblin/user_pages/user.html')
## Make sure user is in place ## Make sure user is in place
new_user = mg_globals.database.User.find_one( new_user = mg_globals.database.User.find_one(