def activate_account(request,account_activation_key = None): csrfContext = RequestContext(request) try: key = ConfirmationKey.objects.get(key = account_activation_key,function = 'signup') except ConfirmationKey.DoesNotExist: request.flash["error"] = _(u"The supplied key does not exist.") raise Http404 if not key.is_valid: return render_to_response('information.html',{'title':_(u"User account already activated"),'text':_(u"It seems that your user account has already been activated.")},csrfContext) if User.objects.filter(email = key.email,profile__isnull = False).count(): return render_to_response('information.html',{'title':_(u"A user with this e-mail address already exists."),'text':_(u"We are sorry, but the e-mail address you have chosen is already associated to a user account.")},csrfContext) else: data = key.get_data() user = User() profile = Profile() obsolete_users = User.objects.filter(email = key.email) for obsolete_user in obsolete_users: obsolete_user.email = '' obsolete_user.save() user.username = generate_random_key() user.email = key.email user.set_password(data["password"]) notify_staff({'title':'New user account','text':"Somebody with email %s has created a new user account." % key.email},notification_object = user) user.save() profile.user = user profile.has_verified_email = True profile.is_active = True profile.has_beta_key = True profile.save() #We remove the sensitive password from the key's data. del data["password"] key.set_data(data) key.invalidate() _directly_login_user(request,profile.user) csrfContext = RequestContext(request) next_url = None if 'next_url' in data: next_url = data['next_url'] return render_to_response('profiles/activate_account.html', {'next_url':next_url},csrfContext)