Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added registration via api call and agent authentication. #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions rtt_backend/api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.shortcuts import render
from django.contrib.auth.models import User
from django import http
import secrets
import json

def err(sc):
Expand All @@ -19,16 +20,40 @@ def invoke(request):
return err(422)
needs = dictIn['Needs']
dictOut = {}
if (needs == 'Schedule'):
dictOut['Sunday'] = '<Activity>'
dictOut['Monday'] = '<Activity>'
dictOut['Tuesday'] = '<Activity>'
dictOut['Wednesday'] = '<Activity>'
dictOut['Thursday'] = '<Activity>'
dictOut['Friday'] = '<Activity>'
dictOut['Saturday'] = '<Activity>'
if (needs == 'Register'):
lng = -1
while (lng != 0):
nm = ''
for _ in range(128):
nm += chr(65 + secrets.randbelow(26))
lng = len(User.objects.filter(username=nm))
raw = ''
for _ in range(100):
raw += chr(65 + secrets.randbelow(26))
newClient = User()
newClient.username=nm
newClient.set_password(raw)
newClient.save()
dictOut['User'] = nm
dictOut['Pass'] = raw
else:
return err(422)
if 'User' not in dictIn:
return err(401)
inst = User.objects.filter(username=dictIn['User'])
if (len(inst) == 0):
return err(401)
if inst[0].check_password(dictIn['Pass']) != True:
return err(401)
if (needs == 'Schedule'):
dictOut['Sunday'] = '<Activity>'
dictOut['Monday'] = '<Activity>'
dictOut['Tuesday'] = '<Activity>'
dictOut['Wednesday'] = '<Activity>'
dictOut['Thursday'] = '<Activity>'
dictOut['Friday'] = '<Activity>'
dictOut['Saturday'] = '<Activity>'
else:
return err(422)
return http.JsonResponse(dictOut)
except json.decoder.JSONDecodeError:
return err(406)
Expand Down