diff --git a/CLI/oauth/index.html b/CLI/oauth/index.html index 1209807..9ffd6ef 100644 --- a/CLI/oauth/index.html +++ b/CLI/oauth/index.html @@ -14,7 +14,7 @@
- + Sign in with Ion diff --git a/CLI/s-git.py b/CLI/student.py similarity index 97% rename from CLI/s-git.py rename to CLI/student.py index 4a007af..711c99e 100644 --- a/CLI/s-git.py +++ b/CLI/student.py @@ -386,10 +386,17 @@ class Student: command('git checkout master') os.chdir(cdir) -data = getStudent("2022rkhondak") -s = Student(data) -#s.viewClass("APLit_eharris1") -#s.updateClass("APLit_eharris1") -#s.update() -s.exitCLI() +# data = getStudent("2022rkhondak") +# s = Student(data) +# #s.viewClass("APLit_eharris1") +# #s.updateClass("APLit_eharris1") +# #s.update() +# s.exitCLI() +def main(): + print("noooo") + pass + +if __name__ == "__main__": + # stuff only to run when not called via 'import' here + main() diff --git a/CLI/t-git.py b/CLI/teacher.py similarity index 99% rename from CLI/t-git.py rename to CLI/teacher.py index 4e81255..d34ae79 100644 --- a/CLI/t-git.py +++ b/CLI/teacher.py @@ -659,8 +659,8 @@ t = Teacher(data) #ar = ['2022rkhondak','2022inafi','2023rumareti'] #extra = t.reqAddStudentList(ar, "APLit_eharris1") #print(extra) -t.getStudents('2022rkhondak') -t.getChanges('2022rkhondak','APLit_eharris1', 10) +# t.getStudents('2022rkhondak') +# t.getChanges('2022rkhondak','APLit_eharris1', 10) ''' TO-DO diff --git a/skoolos.py b/skoolos.py index 43e3e42..f95da87 100644 --- a/skoolos.py +++ b/skoolos.py @@ -14,14 +14,14 @@ from PyInquirer import prompt, print_json import json import os import argparse -from cryptography.fernet import Fernet client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' redirect_uri = 'http://localhost:8000/callback/' token_url = 'https://ion.tjhsst.edu/oauth/token/' scope = ["read"] - +USER = "" +PWD = "" def main(): print("") @@ -34,20 +34,109 @@ def main(): print("") if not os.path.exists(".profile"): + try: + URL = "http://127.0.0.1:8000/api/" + r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) + print("End service at http://127.0.0.1:8000/ before continuing.") + sys.exit(0) + except: + pass input("Welcome to SkoolOS. Press any key to create an account") authenticate() else: - file = open('key.key', 'rb') - key = file.read() # The key will be type bytes - file.close() - f = Fernet(key) - file = open('.profile', 'rb') - p = file.read() # The key will be type bytes - file.close() + try: + URL = "http://127.0.0.1:8000/api/" + r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) + except: + print("Start Django server first") + sys.exit(0) + f = open('.profile','r') + data = json.loads(f.read()) + f.close() + PWD = data['password'] + USER = data['username'] + if(data['is_student']): + studentCLI() + else: + teacherCLI() + # while True: # pass +def studentCLI(): + from CLI import student + data = getStudent(USER) + print(data) + student = student.Student(data) + print(student) + +def teacherCLI(): + from CLI.teacher import Teacher + print("fail") + +def getStudent(ion_user): + URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/" + r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) + if(r.status_code == 200): + data = r.json() + return data + elif(r.status_code == 404): + return None + print("Make new account!") + elif(r.status_code == 403): + return None + print("Invalid username/password") + else: + return None + print(r.status_code) + +def getDB(url): + r = requests.get(url = url, auth=('raffukhondaker','hackgroup1')) + print("GET:" + str(r.status_code)) + return(r.json()) + +def postDB(data, url): + r = requests.post(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + print("POST:" + str(r.status_code)) + return(r.json()) + +def putDB(data, url): + r = requests.put(url = url, data=data, auth=('raffukhondaker','hackgroup1')) + print("PUT:" + str(r.status_code)) + return(r.json()) + +def delDB(url): + r = requests.delete(url = url, auth=('raffukhondaker','hackgroup1')) + print("DELETE:" + str(r.status_code)) + return None + +def makePass(): + questions = [ + { + 'type': 'password', + 'name': 'pwd', + 'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ', + }, + ] + pwd = prompt(questions)['pwd'] + while(len(pwd) < 7): + print("Password too short (Must be over 6 characters)") + pwd = prompt(questions)['pwd'] + conf = [ + { + 'type': 'password', + 'name': 'pwd', + 'message': 'Re-enter password: ', + }, + ] + pwd2 = prompt(conf)['pwd'] + while(not pwd == pwd2): + print("Passwords do not match.") + pwd2 = prompt(conf)['pwd'] + else: + print("PASSWORD SAVED") + return pwd def authenticate(): oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) @@ -115,24 +204,33 @@ def authenticate(): email = profile['tj_email'] first_name = profile['first_name'] last_name = profile['last_name'] - password = input("Enter SkoolOS password: ") + is_student = profile['is_student'] + password = "" + #password creation + profile = { 'username':username, 'email':email, 'first_name':first_name, 'last_name':last_name, + 'is_student':is_student, 'password':password, } os.chdir(cdir) profileFile = open(".profile", "w") - #profileFile.write(profile.text()) - profileFile.write(str(profile)) + profileFile.write(json.dumps(profile)) + profileFile.close() + + #try to make password + password = makePass() + profile['password'] = password + profileFile = open(".profile", "w") + profileFile.write(json.dumps(profile)) profileFile.close() sys.exit - def create_server(): port = 8000 handler = http.server.SimpleHTTPRequestHandler