def activate(request, activation_key, template_name='users/activate.html'): """ Activates a ``User``'s account, if their key is valid and hasn't expired. Logging in then. Context: account The ``User`` object corresponding to the account, if the activation was successful. ``False`` if the activation was not successful. expiration_days The number of days for which activation keys stay valid after registration. """ from users.models import RegistrationProfile activation_key = activation_key.lower() account = RegistrationProfile.objects.activate_user(activation_key) if account: login_without_password(request, account) return render_to_response( request, template_name, { 'account': account, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, }, context_instance=RequestContext(request))
def register(request, success_url='/signup/complete/', profile_callback=None, template_name='users/registration_form.html'): """ Allows a new user to register an account. Following successful registration, redirects to either ``/signup/complete/`` or, if supplied, the URL specified in the keyword argument ``success_url``. `RegistrationFormUniqueEmail`` must have a method ``save`` which will create and return the new ``User``, and that method must accept the keyword argument ``profile_callback`` To enable creation of a site-specific user profile object for the new user, pass a function which will create the profile object as the keyword argument ``profile_callback``. See ``RegistrationManager.create_inactive_user`` in the file ``models.py`` for details on how to write this function. """ if request.user.is_authenticated(): logout(request) from users.forms import RegistrationFormUniqueEmail from users.models import RegistrationProfile if request.method == 'POST': form = RegistrationFormUniqueEmail(request.POST) if form.is_valid(): new_user = form.save(activate=settings.ACTIVATION_ENABLED, profile_callback=profile_callback) if settings.ACTIVATION_ENABLED: return HttpResponseRedirect(success_url) else: login_without_password(request, new_user) return HttpResponseRedirect(success_url) return render_to_response(template_name, { 'form': form, }, context_instance=RequestContext(request)) else: form = RegistrationFormUniqueEmail() return render_to_response(template_name, { 'form': form, }, context_instance=RequestContext(request))
def activate(request, activation_key, template_name='users/activate.html'): """ Activates a ``User``'s account, if their key is valid and hasn't expired. Logging in then. Context: account The ``User`` object corresponding to the account, if the activation was successful. ``False`` if the activation was not successful. expiration_days The number of days for which activation keys stay valid after registration. """ from users.models import RegistrationProfile activation_key = activation_key.lower() account = RegistrationProfile.objects.activate_user(activation_key) if account: login_without_password(request, account) return render_to_response(request, template_name, { 'account': account, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, }, context_instance=RequestContext(request))