unique auth login

This commit is contained in:
Raffu Khondaker 2020-06-16 18:15:32 -04:00
parent 9fec8ad95d
commit 9fefe43da6
3 changed files with 26 additions and 25 deletions

View File

@ -102,7 +102,7 @@ def command(command):
# public methods: deleteClass, makeClass, update # public methods: deleteClass, makeClass, update
class Student: class Student:
def __init__(self, data): def __init__(self, data, password):
# teacher info already stored in API # teacher info already stored in API
# intitialze fields after GET request # intitialze fields after GET request
self.git = data['git'] self.git = data['git']
@ -111,6 +111,7 @@ class Student:
self.grade = data['grade'] self.grade = data['grade']
self.completed = data['completed'] self.completed = data['completed']
self.user = data['user'] self.user = data['user']
self.password = password
# classes in id form (Example: 4,5) # classes in id form (Example: 4,5)
# storing actual classes # storing actual classes
cid = data['classes'].split(",") cid = data['classes'].split(",")
@ -125,7 +126,7 @@ class Student:
classes = [] classes = []
for c in cid: for c in cid:
url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/"
classes.append(getDB(url)) classes.append(getDB(self.username, self.password,url))
self.classes = classes self.classes = classes
self.sclass = str(data['classes']) self.sclass = str(data['classes'])
@ -143,7 +144,7 @@ class Student:
nclasses = [] nclasses = []
for c in nid: for c in nid:
url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/" url = "http://127.0.0.1:8000/api/classes/" + str(c) + "/"
nclasses.append(getDB(url)) nclasses.append(getDB(self.username, self.password,url))
self.new = nclasses self.new = nclasses
self.snew = str(data['added_to']) self.snew = str(data['added_to'])
@ -170,7 +171,7 @@ class Student:
data = { data = {
'repo': self.repo 'repo': self.repo
} }
print(patchDB(data, self.url)) print(patchDB(self.username, self.password,data, self.url))
print("Synced to " + self.username) print("Synced to " + self.username)
def getClasses(self): def getClasses(self):
@ -185,7 +186,7 @@ class Student:
print(c['name']) print(c['name'])
alist = c['assignments'] alist = c['assignments']
for a in alist: for a in alist:
ass = getDB("http://127.0.0.1:8000/api/assignments/" + a) ass = getDB(self.username, self.password,"http://127.0.0.1:8000/api/assignments/" + a)
now = datetime.datetime.now() now = datetime.datetime.now()
try: try:
due = ass['due_date'].replace("T", " ").replace("Z", "") due = ass['due_date'].replace("T", " ").replace("Z", "")
@ -207,7 +208,7 @@ class Student:
command("git checkout master") command("git checkout master")
for c in self.classes: for c in self.classes:
print("UPDATING CLASS: " + str(c['name'])) print("UPDATING CLASS: " + str(c['name']))
data = getDB("http://127.0.0.1:8000/api/classes/" + str(c['name'])) data = getDB(self.username, self.password,"http://127.0.0.1:8000/api/classes/" + str(c['name']))
# command("git checkout master") # command("git checkout master")
command("git checkout " + data['name']) command("git checkout " + data['name'])
command("git add .") command("git add .")
@ -240,7 +241,7 @@ class Student:
# add classes from 'new' field # add classes from 'new' field
def addClass(self, cid): def addClass(self, cid):
data = getDB('http://127.0.0.1:8000/api/classes/' + str(cid)) data = getDB(self.username, self.password,'http://127.0.0.1:8000/api/classes/' + str(cid))
if ((cid in self.snew) == False or (self.username in data['confirmed'])): if ((cid in self.snew) == False or (self.username in data['confirmed'])):
print("Already enrolled in this class.") print("Already enrolled in this class.")
return None return None
@ -251,7 +252,7 @@ class Student:
# add class teacher as cocllaborator to student repo # add class teacher as cocllaborator to student repo
print(os.getcwd()) print(os.getcwd())
pwd = input("Enter Github password: ") pwd = input("Enter Github password: ")
tgit = getDB("http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git'] tgit = getDB(self.username, self.password,"http://127.0.0.1:8000/api/teachers/" + data['teacher'] + "/")['git']
url = "curl -i -u " + self.git + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + self.username + "/collaborators/" + tgit + "'" url = "curl -i -u " + self.git + ":" + pwd + " -X PUT -d '' " + "'https://api.github.com/repos/" + self.git + "/" + self.username + "/collaborators/" + tgit + "'"
print(url) print(url)
os.system(url) os.system(url)
@ -304,7 +305,7 @@ class Student:
# recreate sclass field, using ids # recreate sclass field, using ids
for c in self.new: for c in self.new:
snew = snew + str(c['name']) + "," snew = snew + str(c['name']) + ","
new.append(getDB("http://127.0.0.1:8000/api/classes/" + str(cid))) new.append(getDB(self.username, self.password,"http://127.0.0.1:8000/api/classes/" + str(cid)))
self.snew = snew self.snew = snew
self.new = new self.new = new
break break
@ -316,7 +317,7 @@ class Student:
'classes': self.sclass 'classes': self.sclass
} }
print(self.url) print(self.url)
print(patchDB(data, self.url)) print(patchDB(self.username, self.password,data, self.url))
return data return data
def submit(self, path): def submit(self, path):
@ -406,8 +407,8 @@ class Student:
os.chdir(cdir) os.chdir(cdir)
# data = getStudent("2022rkhondak") #data = getStudent("2022rkhondak", "PWD")
# s = Student(data) #s = Student(data, "PWD")
# s.viewClass("APLit_eharris1") # s.viewClass("APLit_eharris1")
# #s.addClass("APLit_eharris1") # #s.addClass("APLit_eharris1")
# # #s.update() # # #s.update()

View File

@ -725,9 +725,9 @@ class Teacher:
print("heheheh") print("heheheh")
data = getTeacher("eharris1","hackgroup1") # data = getTeacher("eharris1","PWD")
print(data) # print(data)
t = Teacher(data, "hackgroup1") # t = Teacher(data, "PWD")
# t.makeClass("APLit_eharris1") # t.makeClass("APLit_eharris1")
# t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124') # t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124')
# ar = ['2022rkhondak','2022inafi','2023rumareti'] # ar = ['2022rkhondak','2022inafi','2023rumareti']

View File

@ -89,7 +89,7 @@ def main():
def studentCLI(user, password): def studentCLI(user, password):
from CLI import student from CLI import student
data = getUser(user, password, 'student') data = getUser(user, password, 'student')
student = student.Student(data) student = student.Student(data, password)
student.update() student.update()
EXIT = False EXIT = False
while(not EXIT): while(not EXIT):
@ -150,7 +150,7 @@ def teacherCLI(user, password):
from CLI import teacher from CLI import teacher
data = getUser(user, password, 'teacher') data = getUser(user, password, 'teacher')
print(data) print(data)
teacher = teacher.Teacher(data) teacher = teacher.Teacher(data, password)
EXIT = False EXIT = False
# 1. make a class # 1. make a class
# 2. add studeents to an existing class # 2. add studeents to an existing class
@ -230,9 +230,9 @@ def makeClassTeacher(teacher):
teacher.reqAddStudentList(students, cname) teacher.reqAddStudentList(students, cname)
return False return False
def classOptionsTeacher(teacher, course, password): def classOptionsTeacher(teacher, course):
print("Class: " + course) print("Class: " + course)
unconf = getDB("http://localhost:8000/api/classes/" + course)['unconfirmed'] unconf = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['unconfirmed']
for s in unconf: for s in unconf:
teacher.addStudent(s, course) teacher.addStudent(s, course)
options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"] options = ['1) Request Student', "2) Add assignment", "3) View student information", "4) Exit"]
@ -292,7 +292,7 @@ def addStudentsTeacher(teacher, course):
def addAssignmentTeacher(teacher, course): def addAssignmentTeacher(teacher, course):
nlist = os.listdir(teacher.username + "/" + course) nlist = os.listdir(teacher.username + "/" + course)
alist = getDB(teacher.username, "http://localhost:8000/api/classes/" + course)['assignments'] alist = getDB(teacher.username, teacher.password, "http://localhost:8000/api/classes/" + course)['assignments']
print(nlist) print(nlist)
tlist = [] tlist = []
b = True b = True
@ -341,7 +341,7 @@ def addAssignmentTeacher(teacher, course):
return False return False
def viewStudentsTeacher(teacher, course): def viewStudentsTeacher(teacher, course):
data = getDB("http://127.0.0.1:8000/api/classes/" + course) data = getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/classes/" + course)
students = data["confirmed"] students = data["confirmed"]
unconf = data['unconfirmed'] unconf = data['unconfirmed']
print("Studented in class: ") print("Studented in class: ")
@ -356,7 +356,7 @@ def viewStudentsTeacher(teacher, course):
student = input("View student ('N' to exit): ") student = input("View student ('N' to exit): ")
if student == 'N': if student == 'N':
return True return True
print(getDB("http://127.0.0.1:8000/api/students/" + student + "/")) print(getDB(teacher.username, teacher.password, "http://127.0.0.1:8000/api/students/" + student + "/"))
@ -365,9 +365,9 @@ def viewStudentsTeacher(teacher, course):
def getUser(ion_user, password, utype): def getUser(ion_user, password, utype):
if('student' in utype): if('student' in utype):
URL = "http://127.0.0.1:8000/api/students/" + USER + "/" URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
else: else:
URL = "http://127.0.0.1:8000/api/teachers/" + USER + "/" URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/"
print(URL) print(URL)
r = requests.get(url = URL, auth=(ion_user,password)) r = requests.get(url = URL, auth=(ion_user,password))
print(r.json()) print(r.json())
@ -386,7 +386,7 @@ def getUser(ion_user, password, utype):
return None return None
def patchDB(USER, PWD, url, data): def patchDB(USER, PWD, url, data):
r = requests.patch(url = url, data=data, auth=('raffukhondaker','hackgroup1')) r = requests.patch(url = url, data=data, auth=(USER,PWD))
print("PATH:" + str(r.status_code)) print("PATH:" + str(r.status_code))
return(r.json()) return(r.json())