summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2020-02-26 17:29:36 +0000
committerMagnus Hagander2020-02-26 17:29:36 +0000
commit0fd852c405f3969b5e124e31bed5f0419e6e51ed (patch)
tree59cb8cea8c5842cfb9d303bf0823b9eafe574551
parent22c82a8039ec47d7406d4714c2088a42cf6b4674 (diff)
Sync up community auth plugin to latest-and-greatest
-rw-r--r--pgmailmgr/auth.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/pgmailmgr/auth.py b/pgmailmgr/auth.py
index 13e5b28..4ae553b 100644
--- a/pgmailmgr/auth.py
+++ b/pgmailmgr/auth.py
@@ -30,9 +30,9 @@ import json
import socket
from urllib.parse import urlparse, urlencode, parse_qs
import requests
-from Crypto.Cipher import AES
-from Crypto.Hash import SHA
-from Crypto import Random
+from Cryptodome.Cipher import AES
+from Cryptodome.Hash import SHA
+from Cryptodome import Random
import time
@@ -58,7 +58,7 @@ def login(request):
r = Random.new()
iv = r.read(16)
encryptor = AES.new(SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, iv)
- cipher = encryptor.encrypt(s + ' ' * (16 - (len(s) % 16))) # pad to 16 bytes
+ cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # pad to 16 bytes
return HttpResponseRedirect("%s?d=%s$%s" % (
settings.PGAUTH_REDIRECT,
@@ -133,13 +133,25 @@ def auth_receive(request):
a different username than %s.
This is almost certainly caused by some legacy data in our database.
-Please send an email to [email protected], indicating the username
+Please send an email to [email protected], indicating the username
and email address from above, and we'll manually merge the two accounts
for you.
We apologize for the inconvenience.
""" % (data['e'][0], data['u'][0]), content_type='text/plain')
+ if getattr(settings, 'PGAUTH_CREATEUSER_CALLBACK', None):
+ res = getattr(settings, 'PGAUTH_CREATEUSER_CALLBACK')(
+ data['u'][0],
+ data['e'][0],
+ ['f'][0],
+ data['l'][0],
+ )
+ # If anything is returned, we'll return that as our result.
+ # If None is returned, it means go ahead and create the user.
+ if res:
+ return res
+
user = User(username=data['u'][0],
first_name=data['f'][0],
last_name=data['l'][0],