cannot log a user in right after creating them :/

2 views
Skip to first unread message

vbgunz

unread,
Sep 6, 2008, 8:34:43 AM9/6/08
to Django users
here is a better version of the code below while it still lasts:
http://dpaste.com/76325/

# the illest issue is right after the except clause. New accounts
should be
# logged in right after creation BUT the new account cannot
immediately log
# in. Whats the issue?

def create(request):
''' create an account if one does not exist else warn users to
handles that
already exists and always offer the option to create a new
account.'''

context = {
'pagetype': 'create user form',
'status_msg': 'create your desired username now'
}

if request.method == 'POST':

username = request.POST['username']
password = request.POST['password']
email = request.POST['email']

try:
User.objects.get(username=username) # must find better method!
context['status_msg'] = 'Sorry that handle already exist'

except ObjectDoesNotExist:
User.objects.create_user(
username=username,
password=password,
email=email,
)

authorized = auth.authenticate(username=username,
password=password)
auth.login(request, authorized) # USER DOES NOT LOG IN!
context['status_msg'] = 'The account was successfully created'

return render('create_user.html', context)

vbgunz

unread,
Sep 12, 2008, 11:53:00 AM9/12/08
to Django users
Regarding this thread posted on Google
http://groups.google.com/group/django-users/browse_thread/thread/9ba514c46d9fd2b3/e64ba2c91cc16a0a#e64ba2c91cc16a0a
(cannot log a user in right after creating them :/)

This very same code does not work in 0.96.2 but upgrading to 1.0 and
without modifying the view, revisiting this view works as I thought it
should. I have noticed a lot of bugs crushed in 1.0 using the same
exact code. this is just one example.

Caching in 0.96.2 was a horrifying subject, it was the last chapter in
the definitive guide before I got tired of things not working and just
lunged for an upgrade in hopes matters would be better. How true
indeed 1.0 is much better in stuff just working.

So, this view works out the box in 1.0 and so many caching problems
are gone. I am quite happy with 1.0 and thought I share my thought on
it here.
Reply all
Reply to author
Forward
0 new messages