예제 #1
0
    def register(self, request, form):
        """
        Register a new user account, inactive user account with the specified
        username, email, and password.

        Creates a new user model object, and a new
        ``registration.models.RegistrationProfile`` tied to the new user
        and containing the activation key used for this account.

        An email will be sent to the supplied email address containing an
        activation link. The email is rendered using two templates. See the
        documentation for ``RegistrationProfile.send_activation_email()`` for
        information about these templates and the contexts provided to
        them.

        After the ``User`` and ``RegistrationProfile`` are created and
        the activation email is sent, the signal
        ``registration.signals.user_registered`` is be sent, with
        the new ``User`` as the keyword argument ``user`` and the
        class of this backend as the sender.
        """
        cleaned_data = form.cleaned_data

        username = cleaned_data['username']
        email = cleaned_data['email']
        password = cleaned_data['password1']

        # TODO: Either add some Site fixtures or remove the Sites framework
        # if Site._meta.installed:
        #     site = Site.objects.get_current()
        # else:
        site = RequestSite(request)

        should_email = should_send_user_activation(
            request, username, email, password)

        user = RegistrationProfile.objects.create_inactive_user(
            site, send_email=should_email, username=username,
            email=email, password=password, request=request)

        user.first_name = cleaned_data.get('first_name', '')
        user.last_name = cleaned_data.get('last_name', '')
        user.organization = cleaned_data.get('organization', '')
        user.allow_email_contact = cleaned_data.get(
            'allow_email_contact', False)
        user.make_info_public = cleaned_data.get(
            'make_info_public', False)
        user.save_with_user(user)

        if hasattr(request, 'instance'):
            InstanceUser.objects.get_or_create(
                user=user,
                instance=request.instance,
                role=request.instance.default_role)

        signals.user_registered.send(sender=self.__class__,
                                     user=user,
                                     request=request,
                                     password=password)
        return user
예제 #2
0
파일: views.py 프로젝트: jwalgran/otm-core
    def register(self, request, form):
        """
        Register a new user account, inactive user account with the specified
        username, email, and password.

        Creates a new user model object, and a new
        ``registration.models.RegistrationProfile`` tied to the new user
        and containing the activation key used for this account.

        An email will be sent to the supplied email address containing an
        activation link. The email is rendered using two templates. See the
        documentation for ``RegistrationProfile.send_activation_email()`` for
        information about these templates and the contexts provided to
        them.

        After the ``User`` and ``RegistrationProfile`` are created and
        the activation email is sent, the signal
        ``registration.signals.user_registered`` is be sent, with
        the new ``User`` as the keyword argument ``user`` and the
        class of this backend as the sender.
        """
        cleaned_data = form.cleaned_data

        username = cleaned_data['username']
        email = cleaned_data['email']
        password = cleaned_data['password1']

        # TODO: Either add some Site fixtures or remove the Sites framework
        # if Site._meta.installed:
        #     site = Site.objects.get_current()
        # else:
        site = RequestSite(request)

        should_email = should_send_user_activation(
            request, username, email, password)

        user = RegistrationProfile.objects.create_inactive_user(
            site, send_email=should_email, username=username,
            email=email, password=password)

        user.first_name = cleaned_data.get('first_name', '')
        user.last_name = cleaned_data.get('last_name', '')
        user.organization = cleaned_data.get('organization', '')
        user.allow_email_contact = cleaned_data.get(
            'allow_email_contact', False)
        user.make_info_public = cleaned_data.get(
            'make_info_public', False)
        user.save_with_user(user)

        if hasattr(request, 'instance'):
            InstanceUser.objects.get_or_create(
                user=user,
                instance=request.instance,
                role=request.instance.default_role)

        signals.user_registered.send(sender=self.__class__,
                                     user=user,
                                     request=request,
                                     password=password)
        return user
예제 #3
0
파일: views.py 프로젝트: heath/OTM2
    def register(self, request, **cleaned_data):
        """
        Register a new user account, inactive user account with the specified
        username, email, and password.

        Creates a new user model object, and a new
        ``registration.models.RegistrationProfile`` tied to the new user
        and containing the activation key used for this account.

        An email will be sent to the supplied email address containing an
        activation link. The email is rendered using two templates. See the
        documentation for ``RegistrationProfile.send_activation_email()`` for
        information about these templates and the contexts provided to
        them.

        After the ``User`` and ``RegistrationProfile`` are created and
        the activation email is sent, the signal
        ``registration.signals.user_registered`` is be sent, with
        the new ``User`` as the keyword argument ``user`` and the
        class of this backend as the sender.
        """
        username = cleaned_data["username"]
        email = cleaned_data["email"]
        password = cleaned_data["password1"]

        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)

        should_email = should_send_user_activation(request, username, email, password)

        user = RegistrationProfile.objects.create_inactive_user(
            username, email, password, site, send_email=should_email
        )

        user.firstname = cleaned_data.get("firstname", "")
        user.lastname = cleaned_data.get("lastname", "")
        user.organization = cleaned_data.get("organization", "")
        user.allow_email_contact = cleaned_data.get("allow_email_contact", False)
        user.save_with_user(user)

        if hasattr(request, "instance"):
            InstanceUser.objects.get_or_create(user=user, instance=request.instance, role=request.instance.default_role)

        signals.user_registered.send(sender=self.__class__, user=user, request=request, password=password)
        return user