def confirm(request, confirm_auth): """The confirmation page, which is displayed when the user follows the link sent to them in the confirmation email. @type confirm_auth: str @param confirm_auth: The user's confirmation authorization key. """ user = get_object_or_404(Subscriber, confirm_auth=confirm_auth) router = user.router if not user.confirmed: # confirm the user's subscription user.confirmed = True user.save() if not router.welcomed: #We assume that people will only subscribe to relays they are running. #We set welcomed to True so that we don't accidentally send welcome #emails to users who are already subscribed. router.welcomed = True router.save() else: # the user is already confirmed, send to an error page error_url_ext = url_helper.get_error_ext('already_confirmed', confirm_auth) return HttpResponseRedirect(error_url_ext) # get the urls for the user's unsubscribe and prefs pages to add links unsubURL = url_helper.get_unsubscribe_url(user.unsubs_auth) prefURL = url_helper.get_preferences_url(user.pref_auth) # spawn a daemon to send an email confirming subscription and #providing the links email_thread=threading.Thread(target=emails.send_confirmed, args=[user.email, router.fingerprint, router.name, user.unsubs_auth, user.pref_auth]) email_thread.setDaemon(True) email_thread.start() # get the template for the confirm page template = templates.confirm return render_to_response(template, {'email': user.email, 'fingerprint' : router.fingerprint, 'nodeName' : router.name, 'unsubURL' : unsubURL, 'prefURL' : prefURL})
def confirm(request, confirm_auth): """The confirmation page, which is displayed when the user follows the link sent to them in the confirmation email. @type confirm_auth: str @param confirm_auth: The user's confirmation authorization key. """ user = get_object_or_404(Subscriber, confirm_auth=confirm_auth) router = user.router if not user.confirmed: # confirm the user's subscription user.confirmed = True user.save() else: # the user is already confirmed, send to an error page error_url_ext = url_helper.get_error_ext('already_confirmed', confirm_auth) return HttpResponseRedirect(error_url_ext) if not router.welcomed: #We assume that people will only subscribe to relays they are running. #We set welcomed to True so that we don't accidentally send welcome #emails to users who are already subscribed. router.welcomed = True router.save() # get the urls for the user's unsubscribe and prefs pages to add links unsubURL = url_helper.get_unsubscribe_url(user.unsubs_auth) prefURL = url_helper.get_preferences_url(user.pref_auth) # spawn a daemon to send an email confirming subscription and #providing the links email_thread=threading.Thread(target=emails.send_confirmed, args=[user.email, router.fingerprint, router.name, user.unsubs_auth, user.pref_auth]) email_thread.setDaemon(True) email_thread.start() # get the template for the confirm page template = templates.confirm return render_to_response(template, {'email': user.email, 'fingerprint' : router.fingerprint, 'nodeName' : router.name, 'unsubURL' : unsubURL, 'prefURL' : prefURL})
def preferences(request, pref_auth): """The preferences page, which contains the preferences form initially populated by user-specific data @type pref_auth: str @param pref_auth: The user's preferences authorization key. """ user = get_object_or_404(Subscriber, pref_auth = pref_auth) if not user.confirmed: # the user hasn't confirmed, send them to an error page error_extension = url_helper.get_error_ext('need_confirmation', user.confirm_auth) return HttpResponseRedirect(error_extension) if request.method != "POST": form = PreferencesForm(user) else: form = PreferencesForm(user, request.POST) if form.is_valid(): # Creates/changes/deletes subscriptions and subscription info # based on form data form.change_subscriptions(form.cleaned_data) # Redirect the user to the pending page url_extension = url_helper.get_confirm_pref_ext(pref_auth) return HttpResponseRedirect(url_extension) fields = {'pref_auth': pref_auth, 'fingerprint': user.router.fingerprint, 'form': form} fields.update(csrf(request)) # get the template template = templates.preferences # display the page return render_to_response(template, fields)
def test_ok(self): val = url_helper.get_error_ext("01234", "56789") self.assertEqual(val, "/error/01234/56789/")