mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Fixes for issues in API calls, more error checking
This commit is contained in:
@@ -57,16 +57,16 @@ class LoginHandler(BaseHandler):
|
|||||||
except (User.DoesNotExist, ValueError):
|
except (User.DoesNotExist, ValueError):
|
||||||
return rc.NOT_HERE
|
return rc.NOT_HERE
|
||||||
|
|
||||||
if 'user' in request.GET:
|
if request.GET.get('user', None):
|
||||||
try:
|
try:
|
||||||
u = User.objects.get(username=request.GET['user'])
|
u = User.objects.get(username=request.GET['user'])
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return rc.NOT_HERE
|
return rc.NOT_HERE
|
||||||
|
|
||||||
d = { 'auth': 'ok', 'id': u.id, 'username': u.username,
|
d = { 'auth': 'ok', 'id': u.id, 'username': u.username,
|
||||||
'password': u.password, 'email': u.email, 'groups': u.groups.all() }
|
'email': u.email, 'groups': u.groups.all() }
|
||||||
|
|
||||||
if request.GET['pass'] == user.password:
|
if request.GET.get('pass', None) and request.GET['pass'] == u.password:
|
||||||
return d
|
return d
|
||||||
|
|
||||||
return { 'auth': 'failed' }
|
return { 'auth': 'failed' }
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class AuthAPIKey(models.Model):
|
|||||||
key = models.CharField("API Key", max_length=200)
|
key = models.CharField("API Key", max_length=200)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not key or key = '':
|
if not key or key == '':
|
||||||
self.key = uuid.uuid4()
|
self.key = uuid.uuid4()
|
||||||
|
|
||||||
models.Model.save(self, *args, **kwargs)
|
models.Model.save(self, *args, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user