Merge branch 'development' of github.com:Rushilwiz/SkoolOS into development

This commit is contained in:
Nathaniel Kenschaft 2020-06-14 22:55:35 -04:00
commit b0254f9b46
3 changed files with 81 additions and 73 deletions

View File

@ -1,23 +0,0 @@
<html>
<head>
<title>Sign into Ion</title>
<style>
body {
background: #5ac8fb;
background: -webkit-linear-gradient(to left, #52edc7, #5ac8fb);
background: linear-gradient(to left, #52edc7, #5ac8fb);
}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</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=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>
</div>
</body>
</html>

View File

@ -42,7 +42,7 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Student model = Student
# fields = ['url','first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed', 'repo','owner'] # fields = ['url','first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed', 'repo','owner']
fields = ['first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','classes','added_to','completed', 'repo','owner'] fields = ['grade','email','student_id', 'git','ion_user','classes','added_to','completed', 'repo','owner']
class TeacherSerializer(serializers.ModelSerializer): class TeacherSerializer(serializers.ModelSerializer):
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True) # classes = ClassesSerializer(many=True, read_only=True,allow_null=True)

View File

@ -14,6 +14,7 @@ from PyInquirer import prompt, print_json
import json import json
import os import os
import argparse import argparse
import webbrowser
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY'
@ -34,31 +35,31 @@ def main():
print("") print("")
if not os.path.exists(".profile"): if not os.path.exists(".profile"):
try: # try:
URL = "http://127.0.0.1:8000/api/" # URL = "http://127.0.0.1:8000/api/"
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) # r = requests.get(url = URL)
print("End service at http://127.0.0.1:8000/ before continuing.") # print("Stop any processes running on http://127.0.0.1:8000/ before continuing")
sys.exit(0) # except:
except: # pass
pass
input("Welcome to SkoolOS. Press any key to create an account") input("Welcome to SkoolOS. Press any key to create an account")
#webbrowser.open("http://127.0.0.1:8000/login", new=2)
authenticate() authenticate()
else: # else:
try: # try:
URL = "http://127.0.0.1:8000/api/" # URL = "http://127.0.0.1:8000/api/"
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1')) # f = open('.profile','r')
except: # data = json.loads(f.read())
print("Start Django server first") # f.close()
sys.exit(0) # PWD = data['password']
f = open('.profile','r') # USER = data['username']
data = json.loads(f.read()) # r = requests.get(url = URL, auth=(USER,PWD))
f.close() # except:
PWD = data['password'] # print("Incorrect password.")
USER = data['username'] # sys.exit(0)
if(data['is_student']): # if(data['is_student']):
studentCLI() # studentCLI()
else: # else:
teacherCLI() # teacherCLI()
@ -152,40 +153,70 @@ def authenticate():
path = os.path.join(os.getcwd(), 'chromedriver-mac') path = os.path.join(os.getcwd(), 'chromedriver-mac')
browser = webdriver.Chrome(path) browser = webdriver.Chrome(path)
web_dir = os.path.join(os.getcwd(), 'CLI', 'oauth') # web_dir = os.path.join(os.getcwd(), 'CLI', 'oauth')
print(web_dir) # print(web_dir)
os.chdir(web_dir) # os.chdir(web_dir)
if os.path.exists("index.html"): # if os.path.exists("index.html"):
os.remove("index.html") # os.remove("index.html")
template = open("template.html", "r") # template = open("template.html", "r")
index = open("index.html", "w") # index = open("index.html", "w")
for line in template: # for line in template:
index.write(line.replace('AUTH_URL', authorization_url)) # index.write(line.replace('AUTH_URL', authorization_url))
template.close() # template.close()
index.close() # index.close()
server = Thread(target=create_server) # server = Thread(target=create_server)
server.daemon = True # server.daemon = True
server.start() # server.start()
browser.get("localhost:8000/") browser.get("localhost:8000/login")
while "http://localhost:8000/callback/?code" not in browser.current_url: # while "http://localhost:8000/callback/?code" not in browser.current_url:
# time.sleep(0.25)
url = browser.current_url
gets = url_decode(url.replace("http://localhost:8000/login/?", ""))
while "http://localhost:8000/login/?username=" not in browser.current_url and (not browser.current_url == "http://localhost:8000/"): #http://localhost:8000/
time.sleep(0.25) time.sleep(0.25)
url = browser.current_url url = browser.current_url
gets = url_decode(url.replace("http://localhost:8000/callback/?", "")) gets = url_decode(url.replace("http://localhost:8000/login/?username=", ""))
while "http://localhost:8000/callback/?code" not in browser.current_url: # code = gets.get("code")
time.sleep(0.25) # if state == gets.get("state"):
# state = gets.get("state")
url = browser.current_url # print("states good")
gets = url_decode(url.replace("http://localhost:8000/callback/?", ""))
code = gets.get("code")
if state == gets.get("state"):
state = gets.get("state")
print("states good")
browser.quit() browser.quit()
questions = [
{
'type': 'input',
'name': 'username',
'message': 'Enter SkoolOS Username (Same as ION Username): ',
},
{
'type': 'password',
'name': 'pwd',
'message': 'Enter SkoolOS Password (NOT ION PASSWORD): ',
},
]
data =prompt(questions)
pwd = data['pwd']
user = data['username']
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
while(r.status_code != 200):
print("INCORRECT LOGIN CREDENTIALS")
r = requests.get(url = "http://localhost:8000/api/", auth=(user,pwd))
data =prompt(questions)
pwd = data['pwd']
user = data['username']
print(r.status_code)
r = requests.get(url = "http://localhost:8000/students/" + user + "/", auth=(user,pwd))
is_student = False
if(r.status_code == 200):
is_student = True
print("Welcome, student " + user)
else:
print("Welcome, teacher " + user)
#print(code) #print(code)
print(state) print(state)