Support Libravatar matching by OpenID URL as well as by email address

This commit is contained in:
Danielle McLean 2018-07-11 13:13:12 +10:00
parent 6efcc450a3
commit 4fd2ff826a
Signed by: 00dani
GPG key ID: 8EB789DDF3ABD240
3 changed files with 33 additions and 3 deletions

View file

@ -70,6 +70,10 @@ class User(ModelMeta, AbstractUser):
compute_from='calc_email_sha256', max_length=64, unique=True,
help_text="SHA-256 hash of the user's email, used for Libravatar"
)
openid_sha256 = ComputedCharField(
compute_from='calc_openid_sha256', max_length=64, unique=True,
help_text="SHA-256 hash of the user's OpenID URL, used for Libravatar"
)
@property
def calc_email_md5(self):
@ -79,6 +83,10 @@ class User(ModelMeta, AbstractUser):
def calc_email_sha256(self):
return sha256(self.email.lower().encode('utf-8')).hexdigest()
@property
def calc_openid_sha256(self):
return sha256(self.full_url.encode('utf-8')).hexdigest()
@property
def name(self):
return '{0} {1}'.format(self.first_name, self.last_name)