Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit bbaa21d

Browse files
Epcon auth improvements (#1437)
* clarified cfp submission steps and moved AddSpeakerToTalkForm into talks.py file * Fixed tests to better reflect new changes * added i_accept_speaker_release to test_update_speaker_updated_speaker_name * bolded both steps for clarity * removed "of the speaker" from labels on the form * removed print statement * requirements upgrade * better handling of username auth Co-authored-by: ethan <[email protected]> Co-authored-by: Ethan Carlsson <[email protected]>
1 parent d8919af commit bbaa21d

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

conference/api.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ def isauth(request):
184184
"password": str (not encrypted)
185185
}
186186
187+
or
188+
189+
{
190+
"username": str,
191+
"password": str (not encrypted)
192+
}
193+
187194
Output (JSON)
188195
{
189196
"username": str,
@@ -207,22 +214,37 @@ def isauth(request):
207214
"error": int
208215
}
209216
"""
210-
required_fields = {'email', 'password'}
211-
212217
try:
213218
data = json.loads(request.body)
214219
except json.decoder.JSONDecodeError as ex:
215220
return _error(ApiError.INPUT_ERROR, ex.msg)
216221

217-
if not isinstance(data, dict) or not required_fields.issubset(data.keys()):
222+
if not isinstance(data, dict):
218223
return _error(ApiError.INPUT_ERROR,
219224
'please provide credentials in JSON format')
220-
221-
# First, let's find the user/account profile given the email address
222-
try:
223-
profile = AttendeeProfile.objects.get(user__email=data['email'])
224-
except AttendeeProfile.DoesNotExist:
225-
return _error(ApiError.AUTH_ERROR, 'unknown user')
225+
if 'password' not in data:
226+
return _error(ApiError.INPUT_ERROR,
227+
'please provide user password in JSON payload')
228+
if 'username' not in data and 'email' not in data:
229+
return _error(ApiError.INPUT_ERROR,
230+
'please provide username or email in JSON payload')
231+
232+
# First, let's find the user/account profile given the email/username as
233+
# appropriate.
234+
if 'email' in data:
235+
try:
236+
profile = AttendeeProfile.objects.get(user__email=data['email'])
237+
except AttendeeProfile.DoesNotExist:
238+
return _error(ApiError.AUTH_ERROR, 'unknown user')
239+
elif 'username' in data:
240+
try:
241+
profile = AttendeeProfile.objects.get(
242+
user__username=data['username']
243+
)
244+
except AttendeeProfile.DoesNotExist:
245+
return _error(ApiError.AUTH_ERROR, 'unknown user')
246+
else:
247+
return _error(ApiError.INPUT_ERROR, 'no email/username provided')
226248

227249
# Is the password OK?
228250
if not check_user_password(profile.user, data['password']):

0 commit comments

Comments
 (0)