forked from brosner/django-email-confirmation
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://django-email-confirmation.googlecode.com/svn/trunk@9 e143efbd-a74b-0410-b764-bd10452ab0ba
- Loading branch information
Showing
1 changed file
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,41 @@ | ||
from django.db import models | ||
from django.db import models, IntegrityError | ||
from django.template.loader import render_to_string | ||
from django.core.mail import send_mail | ||
from django.conf import settings | ||
|
||
# Create your models here. | ||
from django.contrib.auth.models import User | ||
|
||
# this code based in-part on django-registration | ||
|
||
class EmailAddressManager(models.Manager): | ||
|
||
def add_email(self, user, email): | ||
try: | ||
email_address = self.create(user=user, email=email) | ||
subject = render_to_string("emailconfirmation/email_confirmation_subject.txt") | ||
message = render_to_string("emailconfirmation/email_confirmation_message.txt") | ||
# @@@ eventually use django-mailer | ||
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email]) | ||
print "sent %s '%s' to %s" % (subject, message, email) | ||
return email_address | ||
except IntegrityError: | ||
return None | ||
|
||
class EmailAddress(models.Model): | ||
|
||
user = models.ForeignKey(User) | ||
email = models.EmailField() | ||
verified = models.BooleanField(default=False) | ||
|
||
objects = EmailAddressManager() | ||
|
||
def __unicode__(self): | ||
return u"%s (%s)" % (self.email, self.user) | ||
|
||
class Meta: | ||
unique_together = ( | ||
("user", "email"), | ||
) | ||
|
||
class Admin: | ||
pass |