コード例 #1
0
ファイル: utils.py プロジェクト: egr-kittner/pootle
def verify_user(user):
    """Verify a user account without email confirmation

    If the user has an existing primary allauth.EmailAddress set then this is
    verified.

    Otherwise, an allauth.EmailAddress is created using email set for
    User.email.

    If the user is already verified raises a ValueError

    :param user: `User` to verify
    """
    # already has primary?
    existing_primary = EmailAddress.objects.filter(user=user, primary=True)
    if existing_primary.exists():
        existing_primary = existing_primary.first()
        if not existing_primary.verified:
            existing_primary.verified = True
            existing_primary.save()
            return
        else:
            # already verified
            raise ValueError("User '%s' is already verified" % user.username)
    sync_user_email_addresses(user)
    email_address = (EmailAddress.objects
                     .filter(user=user, email__iexact=user.email)
                     .order_by("primary")).first()
    email_address.verified = True
    email_address.primary = True
    email_address.save()
コード例 #2
0
ファイル: generate_fake_data.py プロジェクト: wjdp/xSACdb
    def generateFluffyUsers(self):
        U = get_user_model()

        for i in range(0, self.FLUFFY_USER_COUNT):
            u = U.objects.create_user(
                email=self.fake.email(),
                password="******",
                first_name=self.fake.first_name(),
                last_name=self.fake.last_name(),
            )
            u.save()
            if self.fake.boolean(chance_of_getting_true=90):
                u.memberprofile.fake(self.fake)
                if self.fake.boolean(chance_of_getting_true=80):
                    self.verifyEmail(u)
                else:
                    sync_user_email_addresses(u)

                if self.fake.boolean(chance_of_getting_true=80):
                    u.memberprofile.approve(random.choice(self.memberActionUsers))

                if self.fake.boolean(chance_of_getting_true=90):
                    for i in range(random.randint(1,4)):
                        self._awardQualification(u.memberprofile, random.choice(self.PERSONAL_QUALS))

                    if self.fake.boolean(chance_of_getting_true=10):
                        for i in range(random.randint(1, 4)):
                            self._awardQualification(u.memberprofile, random.choice(self.INSTRUCTOR_QUALS))

            if self.fake.boolean(chance_of_getting_true=10):
                # Archive some
                u.memberprofile.archive(random.choice(self.memberActionUsers))
            u.memberprofile.save()

        self.status_write('Generated {} fluffy users'.format(self.FLUFFY_USER_COUNT))
コード例 #3
0
ファイル: admin.py プロジェクト: MuckRock/squarelet
 def save_model(self, request, obj, form, change):
     """Sync all auth email addresses"""
     if change:
         super().save_model(request, obj, form, change)
         sync_user_email_addresses(obj)
     else:
         Organization.objects.create_individual(obj)
         setup_user_email(request, obj, [])
コード例 #4
0
    def dispatch(self, request, *args, **kwargs):

        # Retrieves user's emails
        sync_user_email_addresses(request.user)
        user_id = User.objects.get(pk=self.request.user.id).id

        # Returns the user to the profile page on success
        self.success_url = reverse_lazy('users:user-detail',
                                        kwargs={'pk': user_id})
        return super(CustomEmailView, self).dispatch(request, *args, **kwargs)
コード例 #5
0
ファイル: ff.py プロジェクト: stephsalou/BlogNaN
 def _make_hash_value(self, user, timestamp):
     ret = super(EmailAwarePasswordResetTokenGenerator,
                 self)._make_hash_value(user, timestamp)
     sync_user_email_addresses(user)
     emails = set([user.email] if user.email else [])
     emails.update(
         EmailAddress.objects.filter(user=user).values_list('email',
                                                            flat=True))
     ret += '|'.join(sorted(emails))
     return ret
コード例 #6
0
ファイル: models.py プロジェクト: RevelSystems/cat-pootle
    def sync_email(self, old_email):
        """Syncs up `self.email` with allauth's own `EmailAddress` model.

        :param old_email: Address this user previously had
        """
        if old_email != self.email:  # Update
            EmailAddress.objects.filter(
                user=self,
                email__iexact=old_email,
            ).update(email=self.email)
        else:
            sync_user_email_addresses(self)
コード例 #7
0
    def configure_user(self, user):
        username = user.get_username()
        user.email = username
        sync_user_email_addresses(user)
        user.save()

        emails = EmailAddress.objects.filter(user=user, verified=False)
        for email in emails:
            email.verified = True
            email.save()

        return user
コード例 #8
0
    def dispatch(self, request, *args, **kwargs):

        # Retrieves user's emails
        sync_user_email_addresses(request.user)

        # Returns the user to the profile page on success
        self.success_url = reverse_lazy('users:user-detail',
                                        kwargs={
                                            'username': request.user.username,
                                            'pk': request.user.id
                                        })
        return super().dispatch(request, *args, **kwargs)
コード例 #9
0
    def sync_email(self, old_email):
        """Syncs up `self.email` with allauth's own `EmailAddress` model.

        :param old_email: Address this user previously had
        """
        if old_email != self.email:  # Update
            EmailAddress.objects.filter(
                user=self,
                email__iexact=old_email,
            ).update(email=self.email)
        else:
            sync_user_email_addresses(self)
コード例 #10
0
    def verify(self, user):
        """Verify user within account app."""
        from allauth.account import utils as account_utils
        from allauth.account import models as account_models

        account_utils.sync_user_email_addresses(user)
        email = account_models.EmailAddress.objects.get(user=user)
        email.verified = True
        email.primary = True
        email.save(using=self._db)
        user.is_active = True
        user.save(using=self._db)
        return user
コード例 #11
0
ファイル: utils.py プロジェクト: claudep/pootle
def verify_user(user):
    """Verify a user account without email confirmation

    If the user has an existing primary allauth.EmailAddress set then this is
    verified.

    Otherwise, an allauth.EmailAddress is created using email set for
    User.email.

    If the user is already verified raises a ValueError

    :param user: `User` to verify
    """
    if not user.email:
        raise ValidationError("You cannot verify an account with no email "
                              "set. You can set this user's email with "
                              "'pootle update_user_email %s EMAIL'"
                              % user.username)

    # Ensure this user's email address is unique
    try:
        validate_email_unique(user.email, user)
    except ValidationError:
        raise ValidationError("This user's email is not unique. You can find "
                              "duplicate emails with 'pootle "
                              "find_duplicate_emails'")

    # already has primary?
    existing_primary = EmailAddress.objects.filter(user=user, primary=True)
    if existing_primary.exists():
        existing_primary = existing_primary.first()
        if not existing_primary.verified:
            existing_primary.verified = True
            existing_primary.save()
            return
        else:
            # already verified
            raise ValueError("User '%s' is already verified" % user.username)

    sync_user_email_addresses(user)
    email_address = (EmailAddress.objects
                     .filter(user=user, email__iexact=user.email)
                     .order_by("primary")).first()
    email_address.verified = True
    email_address.primary = True
    email_address.save()
コード例 #12
0
ファイル: utils.py プロジェクト: felfilali/pootle
def verify_user(user):
    """Verify a user account without email confirmation

    If the user has an existing primary allauth.EmailAddress set then this is
    verified.

    Otherwise, an allauth.EmailAddress is created using email set for
    User.email.

    If the user is already verified raises a ValueError

    :param user: `User` to verify
    """
    if not user.email:
        raise ValidationError("You cannot verify an account with no email "
                              "set. You can set this user's email with "
                              "'pootle update_user_email %s EMAIL'"
                              % user.username)

    # Ensure this user's email address is unique
    try:
        validate_email_unique(user.email, user)
    except ValidationError:
        raise ValidationError("This user's email is not unique. You can find "
                              "duplicate emails with 'pootle "
                              "find_duplicate_emails'")

    # already has primary?
    existing_primary = EmailAddress.objects.filter(user=user, primary=True)
    if existing_primary.exists():
        existing_primary = existing_primary.first()
        if not existing_primary.verified:
            existing_primary.verified = True
            existing_primary.save()
            return
        else:
            # already verified
            raise ValueError("User '%s' is already verified" % user.username)

    sync_user_email_addresses(user)
    email_address = (EmailAddress.objects
                     .filter(user=user, email__iexact=user.email)
                     .order_by("primary")).first()
    email_address.verified = True
    email_address.primary = True
    email_address.save()
コード例 #13
0
    def generateFluffyUsers(self):
        U = get_user_model()

        for i in range(0, self.FLUFFY_USER_COUNT):
            u = U.objects.create_user(
                email=self.fake.email(),
                password="******",
                first_name=self.fake.first_name(),
                last_name=self.fake.last_name(),
            )
            u.save()
            if self.fake.boolean(chance_of_getting_true=90):
                u.memberprofile.fake(self.fake)
                if self.fake.boolean(chance_of_getting_true=80):
                    self.verifyEmail(u)
                else:
                    sync_user_email_addresses(u)

                if self.fake.boolean(chance_of_getting_true=80):
                    u.memberprofile.approve(
                        random.choice(self.memberActionUsers))

                if self.fake.boolean(chance_of_getting_true=90):
                    for i in range(random.randint(1, 4)):
                        self._awardQualification(
                            u.memberprofile,
                            random.choice(self.PERSONAL_QUALS))

                    if self.fake.boolean(chance_of_getting_true=10):
                        for i in range(random.randint(1, 4)):
                            self._awardQualification(
                                u.memberprofile,
                                random.choice(self.INSTRUCTOR_QUALS))

            if self.fake.boolean(chance_of_getting_true=10):
                # Archive some
                u.memberprofile.archive(random.choice(self.memberActionUsers))
            u.memberprofile.save()

        self.status_write('Generated {} fluffy users'.format(
            self.FLUFFY_USER_COUNT))
コード例 #14
0
 def dispatch(self, request, *args, **kwargs):
     sync_user_email_addresses(request.user)
     self.opendb_user = get_object_by_name(self.request.user.username)
     return super(ProfileView, self).dispatch(request, *args, **kwargs)
コード例 #15
0
 def setUp(self):
     self.user = get_user_model()()
     allauth_utils.user_username(self.user, 'spam')
     allauth_utils.user_email(self.user, '*****@*****.**')
     self.user.save()
     allauth_utils.sync_user_email_addresses(self.user)
コード例 #16
0
ファイル: generate_fake_data.py プロジェクト: wjdp/xSACdb
 def verifyEmail(self, user):
     sync_user_email_addresses(user)
     ea = EmailAddress.objects.get_for_user(user, user.email)
     ea.verified = True
     ea.save()
コード例 #17
0
ファイル: views.py プロジェクト: Rousong/Django-Super-Blog
 def dispatch(self, request, *args, **kwargs):
     # user=User.objects.filter(id=self.request.session.get('user_info')['uid']).first()
     sync_user_email_addresses(request.user)
     return super(UserInfoView, self).dispatch(request, *args, **kwargs)
コード例 #18
0
ファイル: views.py プロジェクト: fumuumuf/drf_allauthmail
 def initial(self, *args, **kwargs):
     super(EmailViewSet, self).initial(*args, **kwargs)
     # sync the user's email when accessed
     sync_user_email_addresses(self.request.user)
コード例 #19
0
 def verifyEmail(self, user):
     sync_user_email_addresses(user)
     ea = EmailAddress.objects.get_for_user(user, user.email)
     ea.verified = True
     ea.save()
コード例 #20
0
ファイル: auth_sync.py プロジェクト: ScubaJimmE/xSACdb
 def handle(self, *args, **options):
     for user in User.objects.all():
         sync_user_email_addresses(user)