def register_user(self, form):
        user = form.save()
        user.is_active = False
        user.save()

        user_registered.send_robust(
            sender=self, request=self.request, user=user)

        if getattr(settings, 'OSCAR_SEND_REGISTRATION_EMAIL', True):
            self.send_registration_email(user)

        try:
            user = authenticate(
                username=user.email,
                password=form.cleaned_data['password1'])
        except User.MultipleObjectsReturned:
            logger.warning(
                'Multiple users with identical email address and password'
                'were found. Marking all but one as not active.')
            users = User.objects.filter(email=user.email)
            user = users[0]
            for u in users[1:]:
                u.is_active = False
                u.save()

        # auth_login(self.request, user)

        return user
示例#2
0
    def register_user(self, form):
        """
        Create a user instance and send a new registration email (if configured
        to).
        """
        user = form.save()

        if getattr(settings, 'OSCAR_SEND_REGISTRATION_EMAIL', True):
            self.send_registration_email(user)

        # Raise signal
        user_registered.send_robust(sender=self, user=user)

        # We have to authenticate before login
        try:
            user = authenticate(
                username=user.email,
                password=form.cleaned_data['password1'])
        except User.MultipleObjectsReturned:
            # Handle race condition where the registration request is made
            # multiple times in quick succession.  This leads to both requests
            # passing the uniqueness check and creating users (as the first one
            # hasn't committed when the second one runs the check).  We retain
            # the first one and delete the dupes.
            users = User.objects.filter(email=user.email)
            user = users[0]
            for u in users[1:]:
                u.delete()

        auth_login(self.request, user)

        return user
示例#3
0
    def register_user(self, form):
        """
        Create a user instance and send a new registration email (if configured
        to).
        """
        user = form.save()

        # Raise signal robustly (we don't want exceptions to crash the request
        # handling).
        user_registered.send_robust(sender=self,
                                    request=self.request,
                                    user=user)

        if getattr(settings, 'OSCAR_SEND_REGISTRATION_EMAIL', True):
            self.send_registration_email(user)

        # We have to authenticate before login
        try:
            user = authenticate(username=user.email,
                                password=form.cleaned_data['password1'])
        except User.MultipleObjectsReturned:
            # Handle race condition where the registration request is made
            # multiple times in quick succession.  This leads to both requests
            # passing the uniqueness check and creating users (as the first one
            # hasn't committed when the second one runs the check).  We retain
            # the first one and delete the dupes.
            users = User.objects.filter(email=user.email)
            user = users[0]
            for u in users[1:]:
                u.delete()

        auth_login(self.request, user)

        return user
示例#4
0
    def register_user(self, form):
        """
        Create a user instance and send a new registration email (if configured
        to).
        创建用户实例并发送新的注册电子邮件(如果已配置)。
        """
        user = form.save()

        # Raise signal robustly (we don't want exceptions to crash the request
        # handling).
        # 有力地提高信号(我们不希望异常崩溃请求处理)。
        user_registered.send_robust(sender=self,
                                    request=self.request,
                                    user=user)

        if getattr(settings, 'OSCAR_SEND_REGISTRATION_EMAIL', True):
            self.send_registration_email(user)

        # We have to authenticate before login
        # 我们必须在登录前进行身份验证。
        try:
            user = authenticate(username=user.email,
                                password=form.cleaned_data['password1'])
        except User.MultipleObjectsReturned:
            # Handle race condition where the registration request is made
            # multiple times in quick succession.  This leads to both requests
            # passing the uniqueness check and creating users (as the first one
            # hasn't committed when the second one runs the check).  We retain
            # the first one and deactivate the dupes.
            # 处理快速连续多次登记请求的竞争条件。 这导致两个请求都通过唯
            # 一性检查并创建用户(因为第一个请求在第二个运行检查时未提
            # 交)。 我们保留第一个并停用欺骗。
            logger.warning(
                'Multiple users with identical email address and password'
                'were found. Marking all but one as not active.')
            # 找到具有相同电子邮件地址和密码的多个用户。 标记除一个以外的所有活动。

            # As this section explicitly deals with the form being submitted
            # twice, this is about the only place in Oscar where we don't
            # ignore capitalisation when looking up an email address.
            # We might otherwise accidentally mark unrelated users as inactive
            # 由于本节明确处理了两次提交的表单,因此这是奥斯卡唯一一个在
            # 查找电子邮件地址时不会忽略大写的地方。 否则我们可能会意外
            # 地将不相关的用户标记为非活动状
            users = User.objects.filter(email=user.email)
            user = users[0]
            for u in users[1:]:
                u.is_active = False
                u.save()

        auth_login(self.request, user)

        return user
示例#5
0
    def register_user(self, form):
        """
        Create a user instance and send a new registration email (if configured
        to).
        注册的同时给用户生成唯一的数字码,可以用来用户的转账等
        """
        user = form.save()

        account_type = AccountType.objects.get(name='Web')
        Account.objects.create(
            account_type=account_type,
            code=codes.generate(size=5),
            primary_user=user,
        )
        # Raise signal robustly (we don't want exceptions to crash the request
        # handling).
        user_registered.send_robust(sender=self,
                                    request=self.request,
                                    user=user)

        if getattr(settings, 'OSCAR_SEND_REGISTRATION_EMAIL', True):
            self.send_registration_email(user)

        # We have to authenticate before login
        try:
            user = authenticate(username=user.email,
                                password=form.cleaned_data['password1'])
        except User.MultipleObjectsReturned:
            # Handle race condition where the registration request is made
            # multiple times in quick succession.  This leads to both requests
            # passing the uniqueness check and creating users (as the first one
            # hasn't committed when the second one runs the check).  We retain
            # the first one and deactivate the dupes.
            logger.warning(
                'Multiple users with identical email address and password'
                'were found. Marking all but one as not active.')
            # As this section explicitly deals with the form being submitted
            # twice, this is about the only place in Oscar where we don't
            # ignore capitalisation when looking up an email address.
            # We might otherwise accidentally mark unrelated users as inactive
            users = User.objects.filter(email=user.email)
            user = users[0]
            for u in users[1:]:
                u.is_active = False
                u.save()

        auth_login(self.request, user)

        return user
示例#6
0
    def register_user(self, form):
        """
        Create a user instance and send a new registration email (if configured
        to).
        """
        user = form.save()

        # Raise signal robustly (we don't want exceptions to crash the request
        # handling).
        user_registered.send_robust(
            sender=self, request=self.request, user=user)

        if getattr(settings, 'OSCAR_SEND_REGISTRATION_EMAIL', True):
            self.send_registration_email(user)

        # We have to authenticate before login
        try:
            user = authenticate(
                username=user.email,
                password=form.cleaned_data['password1'])
        except User.MultipleObjectsReturned:
            # Handle race condition where the registration request is made
            # multiple times in quick succession.  This leads to both requests
            # passing the uniqueness check and creating users (as the first one
            # hasn't committed when the second one runs the check).  We retain
            # the first one and deactivate the dupes.
            logger.warning(
                'Multiple users with identical email address and password'
                'were found. Marking all but one as not active.')
            # As this section explicitly deals with the form being submitted
            # twice, this is about the only place in Oscar where we don't
            # ignore capitalisation when looking up an email address.
            # We might otherwise accidentally mark unrelated users as inactive
            users = User.objects.filter(email=user.email)
            user = users[0]
            for u in users[1:]:
                u.is_active = False
                u.save()

        auth_login(self.request, user)

        return user
示例#7
0
def save_profile(strategy, details, user=None, *args, **kwargs):
    """
    This is the last stage where we should have a newly created user and
    a profile, need to match between the user and the profile and save it to DB
    """
    def link_potential_user(user):
        PotentialUser.objects\
            .filter(email=user.email.lower())\
            .update(user=user)

    profile = kwargs.get('profile')
    first_name = kwargs.get('first_name')
    last_name = kwargs.get('last_name')
    mixpanel_anon_id = kwargs.get('mixpanel_anon_id')
    register_type = kwargs.get('register_type')

    if user and profile and first_name and last_name:
        #set user attribute and save profile
        profile.user = user
        profile.uuid = generate_uuid()
        profile.save()
        #set first name and last name of the user and save
        user.first_name = first_name
        user.last_name = last_name
        user.save()
        #link user to potential user so we won't send the follow up email
        link_potential_user(user)
        #send registration email for new social networks user - for mixpanel processing to start
        fields = {
            'request': strategy.request,
            'mixpanel_anon_id': mixpanel_anon_id,
            'register_type': register_type
        }
        if 'social' in kwargs:
            fields['backend'] = kwargs['social'].provider.title()
        user_registered.send_robust(sender=strategy,
                                    user=user,
                                    profile=profile,
                                    **fields)
        senders.add_new_registration_notification(user)