Esempio n. 1
0
    def ready(self):
        from allauth.account.signals import email_confirmed
        from django.db.models.signals import post_save
        from django.contrib.auth.models import User

        email_confirmed.connect(create_key_for_verified_user)
        post_save.connect(create_profile, sender=User)
Esempio n. 2
0
    def ready(self):
        super(UserConfig, self).ready()

        # the user signal handlers to connect to
        User = self.get_model("User")
        signals.post_save.connect(self.on_user_save, sender=User, dispatch_uid="users.user.post_save")
        user_signed_up.connect(self.on_user_signed_up)
        email_confirmed.connect(self.on_email_confirmed)
        social_account_removed.connect(self.on_social_account_removed)

        # the user ban signal handlers to connect to
        UserBan = self.get_model("UserBan")
        signals.post_save.connect(self.on_ban_save, sender=UserBan, dispatch_uid="users.user_ban.save")
        signals.post_delete.connect(self.on_ban_delete, sender=UserBan, dispatch_uid="users.user_ban.delete")
Esempio n. 3
0
    def ready(self):
        super(UserConfig, self).ready()

        # the user signal handlers to connect to
        User = self.get_model('User')
        signals.post_save.connect(self.on_user_save,
                                  sender=User,
                                  dispatch_uid='users.user.post_save')
        user_signed_up.connect(self.on_user_signed_up)
        email_confirmed.connect(self.on_email_confirmed)
        social_account_removed.connect(self.on_social_account_removed)

        # the user ban signal handlers to connect to
        UserBan = self.get_model('UserBan')
        signals.post_save.connect(self.on_ban_save,
                                  sender=UserBan,
                                  dispatch_uid='users.user_ban.save')
        signals.post_delete.connect(self.on_ban_delete,
                                    sender=UserBan,
                                    dispatch_uid='users.user_ban.delete')
Esempio n. 4
0
    def ready(self):
        user_signed_up.connect(log_user_signed_up,
                               dispatch_uid="user_signed_up")
        email_confirmed.connect(log_email_confirmed,
                                dispatch_uid="email_confirmed")

        from allauth.account.models import EmailAddress
        post_save.connect(handle_email_created,
                          sender=EmailAddress,
                          dispatch_uid="email_created")

        from mainsite.signals import handle_token_save
        from mainsite.models import AccessTokenProxy
        from oauth2_provider.models import AccessToken
        post_save.connect(handle_token_save,
                          sender=AccessToken,
                          dispatch_uid="token_saved")
        post_save.connect(handle_token_save,
                          sender=AccessTokenProxy,
                          dispatch_uid="token_proxy_saved")
Esempio n. 5
0
    def set_registration_active(self):
        from allauth.account.signals import user_signed_up, email_confirmed

        user_signed_up.connect(self.set_inactive)
        email_confirmed.connect(self.set_active)
    subscription = Subscription.objects.create(
        user=user, 
        pricing=free_trial_pricing
    )
    stripe_customer = stripe.Customer.create(
        email=user.email
    )
    stripe_subscription = stripe.Subscription.create(
        customer=stripe_customer["id"],
        items=[{'price': 'django-free-trial'}],
        trial_period_days=7
    )
    subscription.status = stripe_subscription["status"]  # trialing
    subscription.stripe_subscription_id = stripe_subscription["id"]
    subscription.save()
    user.stripe_customer_id = stripe_customer["id"]
    user.save()


def user_logged_in_receiver(sender, user, **kwargs):
    subscription = user.subscription
    sub = stripe.Subscription.retrieve(subscription.stripe_subscription_id)

    subscription.status = sub["status"]
    subscription.save()


user_logged_in.connect(user_logged_in_receiver)
email_confirmed.connect(post_email_confirmed)
pre_save.connect(pre_save_course, sender=Course)
pre_save.connect(pre_save_video, sender=Video)
Esempio n. 7
0
 def ready(self):
     user_signed_up.connect(log_user_signed_up,
                            dispatch_uid="user_signed_up")
     email_confirmed.connect(log_email_confirmed,
                             dispatch_uid="email_confirmed")
Esempio n. 8
0
    d.status=ipn_obj.auth_status
    d.save()

payment_was_successful.connect(donation_successful)
"""

from datatrans.utils import register
from django.contrib.flatpages.models import FlatPage


class FlatPageTranslation(object):
    fields = ('content')


register(FlatPage, FlatPageTranslation)
"""
class PoiTranslation(object):
    fields = ('short', 'description')
register(Poi, PoiTranslation)
"""


def on_email_confirmed(*args, **kwargs):
    user = kwargs['email_address'].user
    group_verified = Group.objects.get(name='verified')
    group_verified.user_set.add(user)


from allauth.account.signals import email_confirmed
email_confirmed.connect(on_email_confirmed)
Esempio n. 9
0
""" Users models """
# -*- coding: utf-8 -*-

from django.contrib.auth.models import AbstractUser
#from django.utils.translation import ugettext_lazy as _

from allauth.account.signals import (user_signed_up, user_logged_in,
                                     email_confirmed, password_reset)
from .signals import (user_created_handler, user_logged_in_handler,
                      email_confirmed_handler, user_password_reset_handler)


# Subclass AbstractUser
class User(AbstractUser):
    """
    This is the extended Django user on the web application, so that
    we can add additional data and behavior to the base user model.

    Each front end django user has a corresponding user entry in the
    API backend.
    """
    def __unicode__(self):
        return self.username


# Hook up signals to django-allauth
user_signed_up.connect(user_created_handler)
email_confirmed.connect(email_confirmed_handler)
user_logged_in.connect(user_logged_in_handler)
password_reset.connect(user_password_reset_handler)
Esempio n. 10
0
 def ready(self):
     print("Registering email_confirmed.connect callback")
     email_confirmed.connect(callback)
Esempio n. 11
0
    def save(self, *args, **kwargs):
        if self.signup_email_is_trusted or self.verification_email_is_trusted:
            self.is_verified = True
            self.verified_at = now()

        super().save(*args, **kwargs)

    @property
    def user_info(self):
        return format_html(
            "<span>{} <br/> {} <br/> {} <br/> {} <br/> {}</span>",
            self.user.get_full_name(),
            self.user.user_profile.institution,
            self.user.user_profile.department,
            self.user.user_profile.country,
            self.user.user_profile.website,
        )


def create_verification(email_address, *_, **__):
    if (
        email_is_trusted(email=email_address.email)
        and not Verification.objects.filter(user=email_address.user).exists()
    ):
        Verification.objects.create(
            user=email_address.user, email=email_address.email
        )


email_confirmed.connect(create_verification)
Esempio n. 12
0
        except:
            # whoops, user is gone...
            user = None
        if user is not None:
            self.upsert_user(user)


mongo = MongoConnector()

def update_user_handler(sender, **kwargs):
    mongo.upsert_user(kwargs.get('user'))

def update_related_user_handler(sender, **kwargs):
    mongo.upsert_related_user(kwargs.get('instance'))

def update_emailrelated_handler(sender, **kwargs):
    mongo.upsert_related_user(kwargs.get('email_address'))

def user_delete_handler(sender, **kwargs):
    mongo.remove_user(kwargs.get('instance'))

user_signed_up.connect(update_user_handler, dispatch_uid='dd_user_signed_up')
user_logged_in.connect(update_user_handler, dispatch_uid='dd_user_logged_in')
email_changed.connect(update_user_handler, dispatch_uid='dd_email_changed')
email_added.connect(update_user_handler, dispatch_uid='dd_email_added')
email_confirmed.connect(update_emailrelated_handler, dispatch_uid='dd_email_donfirmed')
post_delete.connect(user_delete_handler, sender=User, dispatch_uid='dd_user_delete')
post_delete.connect(update_related_user_handler, sender=EmailAddress, dispatch_uid='dd_email_delete')
post_delete.connect(update_related_user_handler, sender=SocialAccount, dispatch_uid='dd_social_delete')
post_save.connect(update_related_user_handler, sender=SocialAccount, dispatch_uid='dd_social_save')