def form_valid(self, form): user = form.save(commit=False) user.username = user.username.lower() user.set_password(user.password) user.save() user_activated.send(sender=self, user=user, request=self.request) return HttpResponseRedirect('/register/perfil/')
def activate_users(self, request, queryset): """ Activates the selected users, if they are not alrady activated. """ for profile in queryset: activated = RegistrationProfile.objects.activate_user(profile.activation_key) if activated: user_activated.send( sender=self.__class__, user=activated, request=request )
def activate(request, activation_key): log.info("Activating key %s" % activation_key) account = RegistrationProfile.objects.activate_user(activation_key) log.debug("Account=%s" % account) if account: user_activated.send(sender=None, user=account, request=request) return redirect('registration_activation_complete') context = RequestContext(request) return render_to_response('registration/activate.html', context_instance=context)
def activate_users(self, request, queryset): """ Activates the selected users, if they are not already activated. """ for profile in queryset: activated = self.registration_profile.objects.activate_user( profile.activation_key) if activated: # also fire the activated signal user_activated.send(sender=self.__class__, user=profile.user, request=request)
def activate_user(self, activation_key): """ Validate an activation key and activate the corresponding ``User`` if valid. If the key is valid and has not expired, return the ``User`` after activating. If the key is not valid or has expired, return ``False``. If the key is valid but the ``User`` is already active, return ``False``. To prevent reactivation of an account which has been deactivated by site administrators, the activation key is reset to the string constant ``RegistrationProfile.ACTIVATED`` after successful activation. To execute customized logic when a ``User`` is activated, connect a function to the signal ``registration.signals.user_activated``; this signal will be sent (with the ``User`` as the value of the keyword argument ``user``) after a successful activation. """ from registration.signals import user_activated # Make sure the key we're trying conforms to the pattern of a # SHA1 hash; if it doesn't, no point trying to look it up in # the database. if SHA1_RE.search(activation_key): try: profile = self.get(activation_key=activation_key) except self.model.DoesNotExist: return False if not profile.activation_key_expired(): user = profile.user user.is_active = True user.save() profile.activation_key = self.model.ACTIVATED profile.save() user_activated.send(sender=self.model, user=user) # MODIF: create the Profile object too user_profile = Profile(user=user) user_profile.save() return user return False
def activate_users(self, request, queryset): """ Activates the selected users, if they are not already activated. """ for profile in queryset: activated = self.registration_profile.objects.activate_user( profile.activation_key ) if activated: # also fire the activated signal user_activated.send( sender=self.__class__, user=profile.user, request=request )
def activate(self, request, activation_key): activated_user = RegistrationProfile.objects.activate_user(activation_key) if activated_user: user_activated.send(sender='activate_user', user=activated_user, request=request) if getattr(settings, 'SEND_EMAIL_AFTER_ACTIVATION', False): if Site._meta.installed: site = Site.objects.get_current() else: site = RequestSite(request) ctx_dict = {'user': activated_user, 'site': site} subject = render_to_string('registration/postactivation_email_subject.txt', ctx_dict) subject = ''.join(subject.splitlines()) send_mail_using_template(subject, 'registration/postactivation_email.html', settings.DEFAULT_FROM_EMAIL, [activated_user.email], ctx_dict, html=True) return activated_user
def activate_user(self, activation_key): """ Validate an activation key and activate the corresponding ``User`` if valid. If the key is valid and has not expired, return the ``User`` after activating. If the key is not valid or has expired, return ``False``. If the key is valid but the ``User`` is already active, return ``False``. To prevent reactivation of an account which has been deactivated by site administrators, the activation key is reset to the string constant ``RegistrationProfile.ACTIVATED`` after successful activation. To execute customized logic when a ``User`` is activated, connect a function to the signal ``registration.signals.user_activated``; this signal will be sent (with the ``User`` as the value of the keyword argument ``user``) after a successful activation. """ from registration.signals import user_activated # Make sure the key we're trying conforms to the pattern of a # SHA1 hash; if it doesn't, no point trying to look it up in # the database. if SHA1_RE.search(activation_key): try: profile = self.get(activation_key=activation_key) except self.model.DoesNotExist: return False if not profile.activation_key_expired(): user = profile.user user.is_active = True user.save() profile.activation_key = self.model.ACTIVATED profile.save() user_activated.send(sender=self.model, user=user) return user return False
def activate(request, activation_key, template_name='registration/activate.html', extra_context=None): """ Activate a ``User``'s account, if their key is valid and hasn't expired. By default, uses the template ``registration/activate.html``; to change this, pass the name of a template as the keyword argument ``template_name``. **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. Any values passed in the keyword argument ``extra_context`` (which must be a dictionary) will be added to the context as well; any values in ``extra_context`` which are callable will be called prior to being added to the context. **Template:** registration/activate.html or ``template_name`` keyword argument. """ #amalgamation of registration.views.activate and registration.models.RegistrationManager.activate_user #however, we don't actually acivate! Instead we use signals. from registration.signals import user_activated import re SHA1_RE = re.compile('^[a-f0-9]{40}$') activation_key = activation_key.lower() # Normalize before trying anything with it. if SHA1_RE.search(activation_key): try: profile = RegistrationProfile.objects.get(activation_key=activation_key) except RegistrationProfile.DoesNotExist: account = False else: account = profile.user if not profile.activation_key_expired(): profile.activation_key = RegistrationProfile.ACTIVATED profile.save() user_activated.send(sender=RegistrationProfile, user=account) if extra_context is None: extra_context = {} context = RequestContext(request) for key, value in extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(template_name, { 'account': account, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS }, context_instance=context)
def test_should_create_a_userprofile_when_user_is_activated(self): user = User.objects.create(username="******") request = RequestFactory().get("/") user_activated.send(sender=self.__class__, user=user, request=request) self.assertTrue(AccountProfile.objects.filter(user=user).exists())
def test_should_create_a_userprofile_when_user_is_activated(self): user = User.objects.create(username="******") request = RequestFactory().get("/") user_activated.send(sender=self.__class__, user=user, request=request) self.assertTrue(AccountProfile.objects.filter(user=user).exists())
def activate(self, request, activation_key): player = models.RegisteredPlayer.objects.get(activation_key=activation_key) result = tasks.enableplayer.delay(player.id).get(timeout=5) user_activated.send(sender=self.__class__, user=player, request=request) return player