mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-22 21:38:11 -05:00
Add AccountsByCanonicalEmail.
This commit is contained in:
@@ -648,7 +648,7 @@ class ApiController(RedditController):
|
||||
|
||||
#anything else we know (email, languages)?
|
||||
if email:
|
||||
user.email = email
|
||||
user.set_email(email)
|
||||
emailer.verify_email(user)
|
||||
|
||||
user.pref_lang = c.lang
|
||||
@@ -1157,7 +1157,7 @@ class ApiController(RedditController):
|
||||
if c.user.email:
|
||||
emailer.email_change_email(c.user)
|
||||
|
||||
c.user.email = email
|
||||
c.user.set_email(email)
|
||||
c.user.email_verified = None
|
||||
c.user._commit()
|
||||
Award.take_away("verified_email", c.user)
|
||||
@@ -1178,7 +1178,7 @@ class ApiController(RedditController):
|
||||
c.errors.remove((errors.NO_EMAILS, 'email'))
|
||||
if c.user.email:
|
||||
emailer.email_change_email(c.user)
|
||||
c.user.email = ''
|
||||
c.user.set_email('')
|
||||
c.user.email_verified = None
|
||||
c.user._commit()
|
||||
Award.take_away("verified_email", c.user)
|
||||
@@ -1245,7 +1245,7 @@ class ApiController(RedditController):
|
||||
if (not hasattr(c.user,'email') or c.user.email != email):
|
||||
if c.user.email:
|
||||
emailer.email_change_email(c.user)
|
||||
c.user.email = email
|
||||
c.user.set_email(email)
|
||||
# unverified email for now
|
||||
c.user.email_verified = None
|
||||
c.user._commit()
|
||||
@@ -1266,7 +1266,7 @@ class ApiController(RedditController):
|
||||
if (not email and c.user.email and
|
||||
(errors.NO_EMAILS, 'email') in c.errors):
|
||||
c.errors.remove((errors.NO_EMAILS, 'email'))
|
||||
c.user.email = ''
|
||||
c.user.set_email('')
|
||||
c.user.email_verified = None
|
||||
c.user._commit()
|
||||
Award.take_away("verified_email", c.user)
|
||||
|
||||
@@ -556,6 +556,12 @@ class Account(Thing):
|
||||
|
||||
return rv
|
||||
|
||||
def set_email(self, email):
|
||||
old_email = self.email
|
||||
self.email = email
|
||||
self._commit()
|
||||
AccountsByCanonicalEmail.update_email(self, old_email, email)
|
||||
|
||||
def has_banned_email(self):
|
||||
canon = self.canonical_email()
|
||||
which = self.which_emails_are_banned((canon,))
|
||||
@@ -937,3 +943,34 @@ def on_account_deletion(mature_items):
|
||||
|
||||
account.password = ""
|
||||
account._commit()
|
||||
|
||||
|
||||
class AccountsByCanonicalEmail(tdb_cassandra.View):
|
||||
__metaclass__ = tdb_cassandra.ThingMeta
|
||||
|
||||
_use_db = True
|
||||
_compare_with = tdb_cassandra.UTF8_TYPE
|
||||
_extra_schema_creation_args = dict(
|
||||
key_validation_class=tdb_cassandra.UTF8_TYPE,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def update_email(cls, account, old, new):
|
||||
old, new = map(canonicalize_email, (old, new))
|
||||
|
||||
if old == new:
|
||||
return
|
||||
|
||||
with cls._cf.batch() as b:
|
||||
if old:
|
||||
b.remove(old, {account._id36: ""})
|
||||
if new:
|
||||
b.insert(new, {account._id36: ""})
|
||||
|
||||
@classmethod
|
||||
def get_accounts(cls, email_address):
|
||||
canonical = canonicalize_email(email_address)
|
||||
if not canonical:
|
||||
return []
|
||||
account_id36s = cls.get_time_sorted_columns(canonical).keys()
|
||||
return Account._byID36(account_id36s, data=True, return_dict=False)
|
||||
|
||||
Reference in New Issue
Block a user