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>
<body>
<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">
Sign in with Ion
</a>

View File

@ -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()

View File

@ -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

View File

@ -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