-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Use the user model as the email model. #353
Open
jonathan-s
wants to merge
1
commit into
pinax:master
Choose a base branch
from
jonathan-s:user-as-email
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -15,7 +15,7 @@ | |||||
|
||||||
import pytz | ||||||
from account import signals | ||||||
from account.conf import settings | ||||||
from account.conf import settings, user_as_email | ||||||
from account.fields import TimeZoneField | ||||||
from account.hooks import hookset | ||||||
from account.languages import DEFAULT_LANGUAGE | ||||||
|
@@ -272,11 +272,6 @@ def set_as_primary(self, conditional=False): | |||||
self.user.save() | ||||||
return True | ||||||
|
||||||
def send_confirmation(self, **kwargs): | ||||||
confirmation = EmailConfirmation.create(self) | ||||||
confirmation.send(**kwargs) | ||||||
return confirmation | ||||||
|
||||||
def change(self, new_email, confirm=True): | ||||||
""" | ||||||
Given a new email address, change self and re-confirm. | ||||||
|
@@ -288,12 +283,12 @@ def change(self, new_email, confirm=True): | |||||
self.verified = False | ||||||
self.save() | ||||||
if confirm: | ||||||
self.send_confirmation() | ||||||
EmailAddress.objects.send_confirmation(email=self) | ||||||
|
||||||
|
||||||
class EmailConfirmation(models.Model): | ||||||
|
||||||
email_address = models.ForeignKey(EmailAddress, on_delete=models.CASCADE) | ||||||
email_address = models.ForeignKey(settings.ACCOUNT_EMAIL_MODEL, on_delete=models.CASCADE) | ||||||
created = models.DateTimeField(default=timezone.now) | ||||||
sent = models.DateTimeField(null=True) | ||||||
key = models.CharField(max_length=64, unique=True) | ||||||
|
@@ -321,7 +316,8 @@ def confirm(self): | |||||
if not self.key_expired() and not self.email_address.verified: | ||||||
email_address = self.email_address | ||||||
email_address.verified = True | ||||||
email_address.set_as_primary(conditional=True) | ||||||
if not user_as_email(): | ||||||
email_address.set_as_primary(conditional=True) | ||||||
email_address.save() | ||||||
signals.email_confirmed.send(sender=self.__class__, email_address=email_address) | ||||||
return email_address | ||||||
|
@@ -334,9 +330,11 @@ def send(self, **kwargs): | |||||
current_site.domain, | ||||||
reverse(settings.ACCOUNT_EMAIL_CONFIRMATION_URL, args=[self.key]) | ||||||
) | ||||||
|
||||||
user = self.email_address.user if not user_as_email() else self | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
ctx = { | ||||||
"email_address": self.email_address, | ||||||
"user": self.email_address.user, | ||||||
"user": user, | ||||||
"activate_url": activate_url, | ||||||
"current_site": current_site, | ||||||
"key": self.key, | ||||||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.