From 9fefe43da6dd3730d1b09f1b13287c105662c049 Mon Sep 17 00:00:00 2001 From: Raffu Khondaker <2022rkhondak@tjhsst.edu> Date: Tue, 16 Jun 2020 18:15:32 -0400 Subject: [PATCH] unique auth login --- CLI/student.py | 25 +++++++++++++------------ CLI/teacher.py | 6 +++--- skoolos.py | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CLI/student.py b/CLI/student.py index c503dfe..ae61396 100644 --- a/CLI/student.py +++ b/CLI/student.py @@ -102,7 +102,7 @@ def command(command): # public methods: deleteClass, makeClass, update class Student: - def __init__(self, data): + def __init__(self, data, password): # teacher info already stored in API # intitialze fields after GET request self.git = data['git'] @@ -111,6 +111,7 @@ class Student: self.grade = data['grade'] self.completed = data['completed'] self.user = data['user'] + self.password = password # classes in id form (Example: 4,5) # storing actual classes cid = data['classes'].split(",") @@ -125,7 +126,7 @@ class Student: classes = [] for c in cid: 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.sclass = str(data['classes']) @@ -143,7 +144,7 @@ class Student: nclasses = [] for c in nid: 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.snew = str(data['added_to']) @@ -170,7 +171,7 @@ class Student: data = { 'repo': self.repo } - print(patchDB(data, self.url)) + print(patchDB(self.username, self.password,data, self.url)) print("Synced to " + self.username) def getClasses(self): @@ -185,7 +186,7 @@ class Student: print(c['name']) alist = c['assignments'] 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() try: due = ass['due_date'].replace("T", " ").replace("Z", "") @@ -207,7 +208,7 @@ class Student: command("git checkout master") for c in self.classes: 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 " + data['name']) command("git add .") @@ -240,7 +241,7 @@ class Student: # add classes from 'new' field 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'])): print("Already enrolled in this class.") return None @@ -251,7 +252,7 @@ class Student: # add class teacher as cocllaborator to student repo print(os.getcwd()) 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 + "'" print(url) os.system(url) @@ -304,7 +305,7 @@ class Student: # recreate sclass field, using ids for c in self.new: 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.new = new break @@ -316,7 +317,7 @@ class Student: 'classes': self.sclass } print(self.url) - print(patchDB(data, self.url)) + print(patchDB(self.username, self.password,data, self.url)) return data def submit(self, path): @@ -406,8 +407,8 @@ class Student: os.chdir(cdir) -# data = getStudent("2022rkhondak") -# s = Student(data) +#data = getStudent("2022rkhondak", "PWD") +#s = Student(data, "PWD") # s.viewClass("APLit_eharris1") # #s.addClass("APLit_eharris1") # # #s.update() diff --git a/CLI/teacher.py b/CLI/teacher.py index fd58dfd..363d80c 100644 --- a/CLI/teacher.py +++ b/CLI/teacher.py @@ -725,9 +725,9 @@ class Teacher: print("heheheh") -data = getTeacher("eharris1","hackgroup1") -print(data) -t = Teacher(data, "hackgroup1") +# data = getTeacher("eharris1","PWD") +# print(data) +# t = Teacher(data, "PWD") # t.makeClass("APLit_eharris1") # t.updateAssignment("eharris1/APLit_eharris1/BookReport", "APLit_eharris1", '2020-08-11 16:58:33.383124') # ar = ['2022rkhondak','2022inafi','2023rumareti'] diff --git a/skoolos.py b/skoolos.py index 4041980..3bc163b 100644 --- a/skoolos.py +++ b/skoolos.py @@ -89,7 +89,7 @@ def main(): def studentCLI(user, password): from CLI import student data = getUser(user, password, 'student') - student = student.Student(data) + student = student.Student(data, password) student.update() EXIT = False while(not EXIT): @@ -150,7 +150,7 @@ def teacherCLI(user, password): from CLI import teacher data = getUser(user, password, 'teacher') print(data) - teacher = teacher.Teacher(data) + teacher = teacher.Teacher(data, password) EXIT = False # 1. make a class # 2. add studeents to an existing class @@ -230,9 +230,9 @@ def makeClassTeacher(teacher): teacher.reqAddStudentList(students, cname) return False -def classOptionsTeacher(teacher, course, password): +def classOptionsTeacher(teacher, 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: teacher.addStudent(s, course) 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): 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) tlist = [] b = True @@ -341,7 +341,7 @@ def addAssignmentTeacher(teacher, course): return False 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"] unconf = data['unconfirmed'] print("Studented in class: ") @@ -356,7 +356,7 @@ def viewStudentsTeacher(teacher, course): student = input("View student ('N' to exit): ") if student == 'N': 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): 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: - URL = "http://127.0.0.1:8000/api/teachers/" + USER + "/" + URL = "http://127.0.0.1:8000/api/teachers/" + ion_user + "/" print(URL) r = requests.get(url = URL, auth=(ion_user,password)) print(r.json()) @@ -386,7 +386,7 @@ def getUser(ion_user, password, utype): return None 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)) return(r.json())