password creaetion

This commit is contained in:
Raffu Khondaker 2020-06-14 18:37:15 -04:00
parent e699db749b
commit 6b93058113
4 changed files with 127 additions and 22 deletions

View File

@ -14,7 +14,7 @@
</head> </head>
<body> <body>
<div class="d-flex align-items-center justify-content-center" style="height: 100vh"> <div class="d-flex align-items-center justify-content-center" style="height: 100vh">
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback%2F&scope=read&state=HqMEAtGHTvAVR63VJrwdrIawpSvXGk" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;"> <a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback%2F&scope=read&state=yPblNZvC39bYCruLcVibEUzLjXkwaJ" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
<img src="https://ion.tjhsst.edu/static/img/favicon.png"> <img src="https://ion.tjhsst.edu/static/img/favicon.png">
Sign in with Ion Sign in with Ion
</a> </a>

View File

@ -386,10 +386,17 @@ class Student:
command('git checkout master') command('git checkout master')
os.chdir(cdir) os.chdir(cdir)
data = getStudent("2022rkhondak") # data = getStudent("2022rkhondak")
s = Student(data) # s = Student(data)
#s.viewClass("APLit_eharris1") # #s.viewClass("APLit_eharris1")
#s.updateClass("APLit_eharris1") # #s.updateClass("APLit_eharris1")
#s.update() # #s.update()
s.exitCLI() # s.exitCLI()
def main():
print("noooo")
pass
if __name__ == "__main__":
# stuff only to run when not called via 'import' here
main()

View File

@ -659,8 +659,8 @@ t = Teacher(data)
#ar = ['2022rkhondak','2022inafi','2023rumareti'] #ar = ['2022rkhondak','2022inafi','2023rumareti']
#extra = t.reqAddStudentList(ar, "APLit_eharris1") #extra = t.reqAddStudentList(ar, "APLit_eharris1")
#print(extra) #print(extra)
t.getStudents('2022rkhondak') # t.getStudents('2022rkhondak')
t.getChanges('2022rkhondak','APLit_eharris1', 10) # t.getChanges('2022rkhondak','APLit_eharris1', 10)
''' '''
TO-DO TO-DO

View File

@ -14,14 +14,14 @@ from PyInquirer import prompt, print_json
import json import json
import os import os
import argparse import argparse
from cryptography.fernet import Fernet
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY'
redirect_uri = 'http://localhost:8000/callback/' redirect_uri = 'http://localhost:8000/callback/'
token_url = 'https://ion.tjhsst.edu/oauth/token/' token_url = 'https://ion.tjhsst.edu/oauth/token/'
scope = ["read"] scope = ["read"]
USER = ""
PWD = ""
def main(): def main():
print("") print("")
@ -34,20 +34,109 @@ def main():
print("") print("")
if not os.path.exists(".profile"): 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") input("Welcome to SkoolOS. Press any key to create an account")
authenticate() authenticate()
else: else:
file = open('key.key', 'rb') try:
key = file.read() # The key will be type bytes URL = "http://127.0.0.1:8000/api/"
file.close() r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
f = Fernet(key) except:
file = open('.profile', 'rb') print("Start Django server first")
p = file.read() # The key will be type bytes sys.exit(0)
file.close() 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: # while True:
# pass # 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(): def authenticate():
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
@ -115,24 +204,33 @@ def authenticate():
email = profile['tj_email'] email = profile['tj_email']
first_name = profile['first_name'] first_name = profile['first_name']
last_name = profile['last_name'] last_name = profile['last_name']
password = input("Enter SkoolOS password: ") is_student = profile['is_student']
password = ""
#password creation
profile = { profile = {
'username':username, 'username':username,
'email':email, 'email':email,
'first_name':first_name, 'first_name':first_name,
'last_name':last_name, 'last_name':last_name,
'is_student':is_student,
'password':password, 'password':password,
} }
os.chdir(cdir) os.chdir(cdir)
profileFile = open(".profile", "w") profileFile = open(".profile", "w")
#profileFile.write(profile.text()) profileFile.write(json.dumps(profile))
profileFile.write(str(profile)) profileFile.close()
#try to make password
password = makePass()
profile['password'] = password
profileFile = open(".profile", "w")
profileFile.write(json.dumps(profile))
profileFile.close() profileFile.close()
sys.exit sys.exit
def create_server(): def create_server():
port = 8000 port = 8000
handler = http.server.SimpleHTTPRequestHandler handler = http.server.SimpleHTTPRequestHandler