Skip to content

Commit ea3f964

Browse files
committed
Sync up community auth plugin to latest-and-greatest
1 parent 88ba279 commit ea3f964

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pgcommitfest/auth.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import socket
3131
from urllib.parse import urlparse, urlencode, parse_qs
3232
import requests
33-
from Crypto.Cipher import AES
34-
from Crypto.Hash import SHA
35-
from Crypto import Random
33+
from Cryptodome.Cipher import AES
34+
from Cryptodome.Hash import SHA
35+
from Cryptodome import Random
3636
import time
3737

3838

@@ -58,7 +58,7 @@ def login(request):
5858
r = Random.new()
5959
iv = r.read(16)
6060
encryptor = AES.new(SHA.new(settings.SECRET_KEY.encode('ascii')).digest()[:16], AES.MODE_CBC, iv)
61-
cipher = encryptor.encrypt(s + ' ' * (16 - (len(s) % 16))) # pad to 16 bytes
61+
cipher = encryptor.encrypt(s.encode('ascii') + b' ' * (16 - (len(s) % 16))) # pad to 16 bytes
6262

6363
return HttpResponseRedirect("%s?d=%s$%s" % (
6464
settings.PGAUTH_REDIRECT,
@@ -140,6 +140,18 @@ def auth_receive(request):
140140
We apologize for the inconvenience.
141141
""" % (data['e'][0], data['u'][0]), content_type='text/plain')
142142

143+
if getattr(settings, 'PGAUTH_CREATEUSER_CALLBACK', None):
144+
res = getattr(settings, 'PGAUTH_CREATEUSER_CALLBACK')(
145+
data['u'][0],
146+
data['e'][0],
147+
['f'][0],
148+
data['l'][0],
149+
)
150+
# If anything is returned, we'll return that as our result.
151+
# If None is returned, it means go ahead and create the user.
152+
if res:
153+
return res
154+
143155
user = User(username=data['u'][0],
144156
first_name=data['f'][0],
145157
last_name=data['l'][0],
@@ -191,8 +203,9 @@ def user_search(searchterm=None, userid=None):
191203
else:
192204
q = {'s': searchterm}
193205

194-
r = requests.get('{0}search/'.format(settings.PGAUTH_REDIRECT),
195-
params=q,
206+
r = requests.get(
207+
'{0}search/'.format(settings.PGAUTH_REDIRECT),
208+
params=q,
196209
)
197210
if r.status_code != 200:
198211
return []

0 commit comments

Comments
 (0)