Пример #1
0
        self.user = AnonymousUser()
        self.timezone = settings.TIME_ZONE
        if request is not None:
            self.language = get_language_from_request(request)
        else:
            self.language = settings.LANGUAGE_CODE

    def __unicode__(self):
        return "AnonymousAccount"


class PasswordReset(models.Model):

    user = models.ForeignKey(User, verbose_name=_("user"))

    temp_key = models.CharField(_("temp_key"), max_length=100)
    timestamp = models.DateTimeField(_("timestamp"), default=datetime.now)
    reset = models.BooleanField(_("reset yet?"), default=False)

    def __unicode__(self):
        return "%s (key=%s, reset=%r)" % (self.user.username, self.temp_key, self.reset)


def mark_user_active(sender, instance=None, **kwargs):
    user = kwargs.get("email_address").user
    user.is_active = True
    user.save()


email_confirmed.connect(mark_user_active, sender=EmailConfirmation)
Пример #2
0
from django.db.models.signals import post_save
from django.utils.translation import get_language_from_request, ugettext_lazy as _

from django.contrib.auth.models import User, AnonymousUser

from emailconfirmation.models import EmailAddress, EmailConfirmation
from emailconfirmation.signals import email_confirmed

# class PasswordReset(models.Model):
#     user = models.ForeignKey(User, verbose_name=_("user"))
#
#     temp_key = models.CharField(_("temp_key"), max_length=100)
#     timestamp = models.DateTimeField(_("timestamp"), default=datetime.now)
#     reset = models.BooleanField(_("reset yet?"), default=False)
#
#     def __unicode__(self):
#         return "%s (key=%s, reset=%r)" % (
#             self.user.username,
#             self.temp_key,
#             self.reset
#         )


def mark_user_active(sender, instance=None, **kwargs):
    user = kwargs.get("email_address").user
    user.is_active = True
    user.save()


email_confirmed.connect(mark_user_active, sender=EmailConfirmation)
Пример #3
0
from emailconfirmation.signals import email_confirmed
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context
from django.conf import settings

def mail_to_admin(sender, email_address, **kwargs):
	email_address.user.is_active = False
	email_address.user.save()

	html = get_template('mail_profile.html')
	try:
		domain = Site.objects.all()[0].domain
	except:
		domain = 'example.com'
	mail_context = Context({ 'user': email_address.user, 'domain':domain })
	admins = User.objects.filter(is_superuser = True)
	emails = []
	for admin in admins:
		emails = emails + [admin.email]
	EMAIL_RECIPIENTS = emails
	subject, from_email, to = 'Новий користувач на сайті Дебатної організації', settings.DEFAULT_FROM_EMAIL, EMAIL_RECIPIENTS
	html_content = html.render(mail_context)
	msg = EmailMultiAlternatives(subject, u'Новий користувач на сайті Дебатної організації', from_email, to)
	msg.attach_alternative(html_content, "text/html")
	msg.send()

email_confirmed.connect(mail_to_admin)
Пример #4
0
        stat.save()
        invite_accepted.send(sender=JoinInvitation, invitation=invite)
    except JoinInvitation.DoesNotExist:
        pass


signup_code_used.connect(process_used_signup_code, sender=SignupCodeResult)


def process_email_confirmed(sender, **kwargs):
    email_address = kwargs.get("email_address")
    invites = JoinInvitation.objects.filter(
        to_user__isnull=True,
        signup_code__email=email_address.email
    )
    for invite in invites:
        invite.to_user = email_address.user
        invite.status = JoinInvitation.STATUS_JOINED_INDEPENDENTLY
        invite.save()

email_confirmed.connect(process_email_confirmed, sender=EmailConfirmation)


def create_stat(sender, instance=None, **kwargs):
    if instance is None:
        return
    InvitationStat.objects.get_or_create(user=instance)


post_save.connect(create_stat, sender=User)
Пример #5
0
from emailconfirmation.models import EmailAddress, EmailConfirmation
from emailconfirmation.signals import email_confirmed


def delete_other_email(sender, instance=None, **kwargs):
    email_address = kwargs.get("email_address")
    user = email_address.user
    if user.emailaddress_set.all().count() > 1:
        user.emailaddress_set.exclude(pk=email_address.pk).delete()
        email_address.set_as_primary()
        


email_confirmed.connect(delete_other_email, sender=EmailConfirmation)