diff --git a/.gitignore b/.gitignore index e67073c..a70aeeb 100644 --- a/.gitignore +++ b/.gitignore @@ -246,6 +246,9 @@ Control.ca-bundle Control.system-ca-bundle GitHub.sublime-settings +#SkoolOS +*.profile + # Visual Studio Code # .vscode/* !.vscode/settings.json diff --git a/CLI/.profile b/CLI/.profile new file mode 100644 index 0000000..ca78410 --- /dev/null +++ b/CLI/.profile @@ -0,0 +1 @@ +{'id': 1000417, 'ion_username': '2023rumareti', 'sex': 'Male', 'title': None, 'display_name': 'Rushil Umaretiya', 'full_name': 'Rushil Umaretiya', 'short_name': 'Rushil', 'first_name': 'Rushil', 'middle_name': 'Haresh', 'last_name': 'Umaretiya', 'nickname': None, 'tj_email': '2023rumareti@tjhsst.edu', 'emails': ['rushilwiz@gmail.com', 'r@crucialnet.org'], 'grade': {'number': 9, 'name': 'freshman'}, 'graduation_year': 2023, 'user_type': 'student', 'phones': ['Mobile Phone: 7034570803'], 'websites': ['http://crucialnet.org'], 'counselor': {'id': 115, 'url': 'https://ion.tjhsst.edu/api/profile/115', 'user_type': 'counselor', 'username': 'kchamblin', 'full_name': 'Kerry Hamblin', 'first_name': 'Kerry', 'last_name': 'Hamblin'}, 'address': None, 'picture': 'https://ion.tjhsst.edu/api/profile/1000417/picture', 'is_eighth_admin': False, 'is_announcements_admin': False, 'is_teacher': False, 'is_student': True, 'absences': 1} diff --git a/CLI/oauth/index.html b/CLI/oauth/index.html index 1c8f1f3..3598c6d 100644 --- a/CLI/oauth/index.html +++ b/CLI/oauth/index.html @@ -14,10 +14,10 @@ </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%2F&scope=read&state=YXN4dnhwLXE7gx6Xq0vwPdvr3z0YSn" 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> \ No newline at end of file +</html> diff --git a/CLI/skoolos.py b/CLI/skoolos.py index e818d3a..e318c72 100644 --- a/CLI/skoolos.py +++ b/CLI/skoolos.py @@ -17,7 +17,7 @@ import argparse client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' -redirect_uri = 'http://localhost:8000/' +redirect_uri = 'http://localhost:8000/callback/' token_url = 'https://ion.tjhsst.edu/oauth/token/' scope = ["read"] @@ -49,10 +49,7 @@ def authenticate(): #Linux: chromdriver-linux #Macos: chromdriver-mac #Windows: chromdriver.exe - path = os.path.join(cdir, "chromedriver-mac") - print(path) - browser = webdriver.Chrome(path) - #browser = webdriver.Safari() + web_dir = os.path.join(os.path.dirname(__file__), 'oauth') os.chdir(web_dir) @@ -72,11 +69,11 @@ def authenticate(): browser.get("localhost:8000/") - while "http://localhost:8000/?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/?", "")) + gets = url_decode(url.replace("http://localhost:8000/callback/?", "")) code = gets.get("code") if state == gets.get("state"): state = gets.get("state") diff --git a/Website/api/admin.py b/Website/api/admin.py index 8c38f3f..8446cf4 100644 --- a/Website/api/admin.py +++ b/Website/api/admin.py @@ -1,3 +1,16 @@ from django.contrib import admin +from .models import ( + DefFiles, + Assignment, + Classes, + Teacher, + Student +) # Register your models here. + +admin.site.register(Teacher) +admin.site.register(Student) +admin.site.register(DefFiles) +admin.site.register(Assignment) +admin.site.register(Classes) diff --git a/Website/api/models.py b/Website/api/models.py index 5659835..3df2268 100644 --- a/Website/api/models.py +++ b/Website/api/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.contrib.auth.models import User class DefFiles(models.Model): name=models.CharField(max_length=100) @@ -21,7 +22,7 @@ class Assignment(models.Model): return '%s' % (self.name) class Classes(models.Model): - owner = models.ForeignKey('auth.User', related_name='classes', on_delete=models.CASCADE) + user = models.OneToOneField(User, on_delete=models.CASCADE) name = models.CharField(primary_key=True, max_length=100) repo=models.URLField(default="", blank=True) @@ -50,14 +51,8 @@ class Teacher(models.Model): email=models.CharField(max_length=100, default="", blank=True) class Student(models.Model): - owner = models.ForeignKey('auth.User', related_name='students', on_delete=models.CASCADE) - - created = models.DateTimeField(auto_now_add=True) - first_name = models.CharField(max_length=100) - last_name = models.CharField(max_length=100) + user = models.OneToOneField(User, on_delete=models.CASCADE) student_id = models.IntegerField() - ion_user=models.CharField(primary_key=True, max_length=100) - email=models.CharField(max_length=100, default="", blank=True) grade = models.IntegerField() git=models.CharField(max_length=100) repo=models.URLField(default="", blank=True) diff --git a/Website/api/signals.py b/Website/api/signals.py new file mode 100644 index 0000000..1ec0946 --- /dev/null +++ b/Website/api/signals.py @@ -0,0 +1,8 @@ +from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver +from .models import Student, Teacher + +@receiver(post_save, sender=User) +def save_profile(sender, instance, **kwargs): + instance.profile.save() diff --git a/Website/users/views.py b/Website/users/views.py index 3e01426..3078208 100644 --- a/Website/users/views.py +++ b/Website/users/views.py @@ -7,6 +7,8 @@ from requests_oauthlib import OAuth2Session from django.contrib import messages from .models import Token +from api.models import Student, Teacher + from .forms import UserCreationForm from django.contrib.auth import authenticate @@ -125,5 +127,5 @@ def create_account (request): @login_required def logout(request): auth_logout(request) - messages.success(request, "You've been logged out! Have a good rest of your day!") + messages.success(request, "You've been logged out!") return redirect(request, "/login/")