mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-09 15:00:21 -04:00
Merge branch 'development' of https://github.com/rushilwiz/SkoolOs into development
This commit is contained in:
commit
8ae5958bbc
|
@ -66,15 +66,12 @@ class Student:
|
|||
def __init__(self, data):
|
||||
# teacher info already stored in API
|
||||
# intitialze fields after GET request
|
||||
self.first_name=data['first_name']
|
||||
self.last_name=data['last_name']
|
||||
self.git=data['git']
|
||||
self.username=data['ion_user']
|
||||
self.url= "http://127.0.0.1:8000/api/students/" + self.username + "/"
|
||||
self.email = data['email']
|
||||
self.grade = data['grade']
|
||||
self.student_id=data['student_id']
|
||||
self.completed = data['completed']
|
||||
self.user = data['user']
|
||||
#classes in id form (Example: 4,5)
|
||||
#storing actual classes
|
||||
cid=data['classes'].split(",")
|
||||
|
@ -132,15 +129,12 @@ class Student:
|
|||
os.chdir(cdir)
|
||||
self.repo = 'https://github.com/' + self.git + '/' + self.username + '.git'
|
||||
data={
|
||||
'first_name':self.first_name,
|
||||
'last_name':self.last_name,
|
||||
'user':self.user,
|
||||
'git':self.git,
|
||||
'ion_user':self.username,
|
||||
'student_id':self.student_id,
|
||||
'added_to':self.snew,
|
||||
'url':self.url,
|
||||
'classes':self.sclass,
|
||||
'email':self.email,
|
||||
'grade':self.grade,
|
||||
'completed':self.completed,
|
||||
'repo':self.repo
|
||||
|
@ -284,15 +278,13 @@ class Student:
|
|||
|
||||
#update teacher instance in db, classes field
|
||||
data={
|
||||
'first_name':self.first_name,
|
||||
'last_name':self.last_name,
|
||||
'user':self.user,
|
||||
'git':self.git,
|
||||
'ion_user':self.username,
|
||||
'student_id':self.student_id,
|
||||
'added_to':self.snew,
|
||||
'url':self.url,
|
||||
'classes':self.sclass,
|
||||
'email':self.email,
|
||||
'grade':self.grade,
|
||||
'completed':self.completed
|
||||
}
|
||||
|
@ -327,15 +319,13 @@ class Student:
|
|||
command("git push -u origin " + self.username + " --tags")
|
||||
self.completed = self.completed + "," + parts[1] + "/" + parts[2]
|
||||
data={
|
||||
'first_name':self.first_name,
|
||||
'last_name':self.last_name,
|
||||
'user':self.user,
|
||||
'git':self.git,
|
||||
'ion_user':self.username,
|
||||
'student_id':self.student_id,
|
||||
'added_to':self.snew,
|
||||
'url':self.url,
|
||||
'classes':self.sclass,
|
||||
'email':self.email,
|
||||
'grade':self.grade,
|
||||
'completed':self.completed
|
||||
}
|
||||
|
|
|
@ -66,8 +66,6 @@ class Teacher:
|
|||
def __init__(self, data):
|
||||
# teacher info already stored in API
|
||||
# intitialze fields after GET request
|
||||
self.first_name=data['first_name']
|
||||
self.last_name=data['last_name']
|
||||
self.git=data['git']
|
||||
self.username=data['ion_user']
|
||||
self.url= "http://127.0.0.1:8000/api/teachers/" + self.username + "/"
|
||||
|
@ -177,13 +175,10 @@ class Teacher:
|
|||
|
||||
#update teacher instance in db, classes field
|
||||
teacher={
|
||||
'first_name':self.first_name,
|
||||
'last_name':self.last_name,
|
||||
'git':self.git,
|
||||
'ion_user':self.username,
|
||||
'url':self.url,
|
||||
'classes':self.sclass,
|
||||
'email':self.email
|
||||
}
|
||||
putDB(teacher, self.url)
|
||||
|
||||
|
@ -250,13 +245,10 @@ class Teacher:
|
|||
s = s[:-1]
|
||||
print(s)
|
||||
data={
|
||||
'first_name':self.first_name,
|
||||
'last_name':self.last_name,
|
||||
'git':self.git,
|
||||
'ion_user':self.username,
|
||||
'url':self.url,
|
||||
'classes':s,
|
||||
'email':self.email
|
||||
}
|
||||
print(putDB(data, self.url))
|
||||
delDB("http://127.0.0.1:8000/api/classes/" + cname + "/")
|
||||
|
@ -300,14 +292,10 @@ class Teacher:
|
|||
return False
|
||||
print(student['added_to'])
|
||||
s={
|
||||
'first_name':student["first_name"],
|
||||
'last_name':student["last_name"],
|
||||
'git':student["git"],
|
||||
'ion_user':student["ion_user"],
|
||||
'student_id':student["student_id"],
|
||||
'added_to':student['added_to'],
|
||||
'classes':student["classes"],
|
||||
'email':student["email"],
|
||||
'grade':student["grade"],
|
||||
'completed':student["completed"],
|
||||
'repo':student["repo"]
|
||||
|
|
23
Website/api/migrations/0005_auto_20200615_0048.py
Normal file
23
Website/api/migrations/0005_auto_20200615_0048.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-15 00:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0004_auto_20200614_2107'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='student',
|
||||
name='id',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='ion_user',
|
||||
field=models.CharField(default='2022rkhondak', max_length=100, primary_key=True, serialize=False),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -5,6 +5,7 @@ from django.contrib.auth.models import User
|
|||
|
||||
class Student(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
ion_user = models.CharField(max_length=100)
|
||||
grade = models.IntegerField(default=0, blank=True)
|
||||
git=models.CharField(default="", max_length=100, blank=True)
|
||||
repo=models.URLField(default="", blank=True)
|
||||
|
@ -49,6 +50,15 @@ class Teacher(models.Model):
|
|||
def save(self, *args, **kwargs):
|
||||
super(Teacher, self).save(*args, **kwargs)
|
||||
|
||||
class Student(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||
grade = models.IntegerField(default=0, blank=True)
|
||||
git=models.CharField(default="", max_length=100, blank=True)
|
||||
repo=models.URLField(default="", blank=True)
|
||||
classes=models.CharField(max_length=100, default="", blank=True)
|
||||
added_to=models.CharField(max_length=100, default="", blank=True)
|
||||
completed=models.TextField(default="", blank=True)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
|
|||
return True
|
||||
|
||||
# Write permissions are only allowed to the owner of the snippet.
|
||||
return obj.owner == request.user or request.user.is_superuser
|
||||
return obj.user == request.user or request.user.is_superuser
|
||||
|
||||
class isTeacher(permissions.BasePermission):
|
||||
#only teachers can make classes and assignmenst
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from django.contrib.auth.models import User, Group
|
||||
from .models import Student, Teacher, Class, Assignment, DefFiles
|
||||
from .models import Student, Teacher, Classes, Assignment, DefFiles
|
||||
from rest_framework import serializers, permissions
|
||||
from django.contrib.auth.models import User
|
||||
from .permissions import IsOwnerOrReadOnly,isTeacher
|
||||
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
students = serializers.PrimaryKeyRelatedField(many=True, queryset=Student.objects.all())
|
||||
teachers = serializers.PrimaryKeyRelatedField(many=True, queryset=Teacher.objects.all())
|
||||
# students = serializers.PrimaryKeyRelatedField(many=True, queryset=Student.objects.all())
|
||||
# teachers = serializers.PrimaryKeyRelatedField(many=True, queryset=Teacher.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
@ -15,39 +15,40 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
|
|||
# class DefFilesSerializer(serializers.HyperlinkedModelSerializer):
|
||||
# class Meta:
|
||||
# model = DefFiles
|
||||
# fields = ['name', 'path','assignment','Class', "teacher",'url', 'id']
|
||||
# fields = ['name', 'path','assignment','classes', "teacher",'url', 'id']
|
||||
|
||||
class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
#permissions_Class = [permissions.IsAuthenticatedOrReadOnly]
|
||||
#permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||
# files = DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
||||
owner = serializers.ReadOnlyField(source='owner.username')
|
||||
|
||||
class Meta:
|
||||
model = Assignment
|
||||
# fields = ['url','name', 'due_date', 'path' , "Class","teacher",'owner']
|
||||
fields = ['name', 'due_date', 'path' , "Class","teacher",'owner']
|
||||
# fields = ['url','name', 'due_date', 'path' , "classes","teacher",'owner']
|
||||
fields = ['name', 'due_date', 'path' , "classes","teacher",'owner']
|
||||
|
||||
class ClassSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
|
||||
# assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
|
||||
# default_file=DefFilesSerializer(many=True, read_only=True,allow_null=True)
|
||||
owner = serializers.ReadOnlyField(source='owner.username')
|
||||
class Meta:
|
||||
model = Class
|
||||
model = Classes
|
||||
# fields = ['url','name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
|
||||
fields = ['name', 'repo','path', "teacher",'assignments',"default_file", 'confirmed', 'unconfirmed','owner']
|
||||
|
||||
class StudentSerializer(serializers.HyperlinkedModelSerializer):
|
||||
# Class = ClassSerializer(many=True, read_only=True,allow_null=True)
|
||||
owner = serializers.ReadOnlyField(source='owner.username')
|
||||
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
||||
class Meta:
|
||||
model = Student
|
||||
# fields = ['url','first_name', 'last_name', 'grade','email','student_id', 'git','ion_user','Class','added_to','completed', 'repo','owner']
|
||||
fields = ['grade','email','student_id', 'git','ion_user','Class','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 = ['url','grade', 'ion_user','git','user','classes','added_to','completed', 'repo']
|
||||
|
||||
class TeacherSerializer(serializers.ModelSerializer):
|
||||
# Class = ClassSerializer(many=True, read_only=True,allow_null=True)
|
||||
# classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
|
||||
owner = serializers.ReadOnlyField(source='owner.username')
|
||||
class Meta:
|
||||
model = Teacher
|
||||
# fields = ['url','first_name', 'last_name','git','ion_user', 'email','Class','owner']
|
||||
fields = ['first_name', 'last_name','git','ion_user', 'email','Class','owner']
|
||||
# fields = ['url','first_name', 'last_name','git','ion_user', 'email','classes','owner']
|
||||
fields = ['first_name', 'last_name','git','ion_user', 'email','classes','owner']
|
||||
|
||||
|
||||
|
|
|
@ -100,11 +100,9 @@ def create_account (request):
|
|||
|
||||
|
||||
if isStudent:
|
||||
profile = Student(user=user, git=git, grade=grade)
|
||||
profile = Student(user=user, git=git, grade=grade, ion_user=username)
|
||||
else:
|
||||
profile = Teacher(user=user, username=username, git=git)
|
||||
|
||||
token.delete()
|
||||
|
||||
profile.save()
|
||||
|
||||
|
|
0
bgservice/__init__.py
Normal file
0
bgservice/__init__.py
Normal file
|
@ -76,14 +76,15 @@ class EventHandler(pyinotify.ProcessEvent):
|
|||
|
||||
|
||||
NOTIFIER = None
|
||||
STDOUT = sys.stdout
|
||||
|
||||
|
||||
def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
|
||||
if not os.path.exists(logdir):
|
||||
os.makedirs(logdir)
|
||||
logfile = open(
|
||||
logdir + "skoolos_" + time.strftime("%m%d%Y-%H%M%S", time.localtime()),
|
||||
'w')
|
||||
logdir + "/skoolos_" +
|
||||
time.strftime("%m%d%Y-%H%M%S", time.localtime()), 'w')
|
||||
sys.stdout = logfile
|
||||
print("Start time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n\n")
|
||||
|
@ -99,4 +100,6 @@ def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
|
|||
def stop_watching():
|
||||
NOTIFIER.stop()
|
||||
print("End time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n\n")
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()))
|
||||
sys.stdout = STDOUT
|
||||
print("Done watching.\n")
|
183
skoolos.py
183
skoolos.py
|
@ -35,50 +35,100 @@ def main():
|
|||
print("")
|
||||
|
||||
if not os.path.exists(".profile"):
|
||||
# try:
|
||||
# URL = "http://127.0.0.1:8000/api/"
|
||||
# r = requests.get(url = URL)
|
||||
# print("Stop any processes running on http://127.0.0.1:8000/ before continuing")
|
||||
# except:
|
||||
# pass
|
||||
try:
|
||||
URL = "http://127.0.0.1:8000/api/"
|
||||
r = requests.get(url = URL)
|
||||
except:
|
||||
print("Stop any processes running on http://127.0.0.1:8000/ before continuing")
|
||||
sys.exit(0)
|
||||
|
||||
input("Welcome to SkoolOS. Press any key to create an account")
|
||||
#webbrowser.open("http://127.0.0.1:8000/login", new=2)
|
||||
authenticate()
|
||||
# else:
|
||||
# try:
|
||||
# URL = "http://127.0.0.1:8000/api/"
|
||||
# f = open('.profile','r')
|
||||
# data = json.loads(f.read())
|
||||
# f.close()
|
||||
# PWD = data['password']
|
||||
# USER = data['username']
|
||||
# r = requests.get(url = URL, auth=(USER,PWD))
|
||||
# except:
|
||||
# print("Incorrect password.")
|
||||
# sys.exit(0)
|
||||
# if(data['is_student']):
|
||||
# studentCLI()
|
||||
# else:
|
||||
# teacherCLI()
|
||||
else:
|
||||
f = open('.profile','r')
|
||||
data = json.loads(f.read())
|
||||
f.close()
|
||||
PWD = data['password']
|
||||
USER = data['username']
|
||||
print(data['username'])
|
||||
if(data['is_student']):
|
||||
studentCLI(USER, PWD)
|
||||
else:
|
||||
teacherCLI(USER, PWD)
|
||||
|
||||
|
||||
|
||||
# while True:
|
||||
# pass
|
||||
def studentCLI():
|
||||
def studentCLI(user, password):
|
||||
from CLI import student
|
||||
data = getStudent(USER)
|
||||
print(data)
|
||||
data = getUser(user, password)
|
||||
student = student.Student(data)
|
||||
print(student)
|
||||
choices = ['1) View Class','2) Exit SkoolOS']
|
||||
questions = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'choice',
|
||||
'choices':choices,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
]
|
||||
choice = prompt(questions)
|
||||
choice = int(choice['choice'].split(")")[0])
|
||||
if(choice == 1):
|
||||
carray = student.sclass.split(",")
|
||||
if(len(carray) == 1 and carray[0] == ""):
|
||||
print("No classes")
|
||||
return
|
||||
courses = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices':carray,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
]
|
||||
course = prompt(courses)
|
||||
if(choice == 2):
|
||||
student.exitCLI()
|
||||
|
||||
|
||||
def teacherCLI():
|
||||
from CLI.teacher import Teacher
|
||||
print("fail")
|
||||
def teacherCLI(user, password):
|
||||
from CLI import teacher
|
||||
data = getUser(user, password)
|
||||
teacher = teacher.Teacher(data)
|
||||
choices = ['1) View Class','2) Exit SkoolOS']
|
||||
questions = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'choice',
|
||||
'choices':choices,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
]
|
||||
choice = prompt(questions)
|
||||
choice = int(choice['choice'].split(")")[0])
|
||||
if(choice == 1):
|
||||
carray = student.sclass.split(",")
|
||||
if(len(carray) == 1 and carray[0] == ""):
|
||||
print("No classes")
|
||||
return
|
||||
courses = [
|
||||
{
|
||||
'type': 'list',
|
||||
'name': 'course',
|
||||
'choices':carray,
|
||||
'message': 'Select class: ',
|
||||
},
|
||||
]
|
||||
course = prompt(courses)
|
||||
if(choice == 2):
|
||||
student.exitCLI()
|
||||
|
||||
def getStudent(ion_user):
|
||||
def getUser(ion_user, password):
|
||||
URL = "http://127.0.0.1:8000/api/students/" + ion_user + "/"
|
||||
r = requests.get(url = URL, auth=('raffukhondaker','hackgroup1'))
|
||||
r = requests.get(url = URL, auth=(ion_user,password))
|
||||
if(r.status_code == 200):
|
||||
data = r.json()
|
||||
return data
|
||||
|
@ -210,55 +260,40 @@ def authenticate():
|
|||
pwd = data['pwd']
|
||||
user = data['username']
|
||||
print(r.status_code)
|
||||
r = requests.get(url = "http://localhost:8000/students/" + user + "/", auth=(user,pwd))
|
||||
r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd))
|
||||
is_student = False
|
||||
if(r.status_code == 200):
|
||||
is_student = True
|
||||
print("Welcome, student " + user)
|
||||
r = requests.get(url = "http://localhost:8000/api/students/" + user + "/", auth=(user,pwd))
|
||||
profile = r.json()
|
||||
username = profile['ion_user']
|
||||
grade = profile['grade']
|
||||
profile = {
|
||||
'username':username,
|
||||
'grade':grade,
|
||||
'is_student':is_student,
|
||||
'password':pwd,
|
||||
}
|
||||
profileFile = open(".profile", "w")
|
||||
profileFile.write(json.dumps(profile))
|
||||
profileFile.close()
|
||||
|
||||
else:
|
||||
print("Welcome, teacher " + user)
|
||||
|
||||
#print(code)
|
||||
print(state)
|
||||
|
||||
payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id,
|
||||
'client_secret': client_secret, 'csrfmiddlewaretoken': state}
|
||||
token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json()
|
||||
#print(token)
|
||||
headers = {'Authorization': f"Bearer {token['access_token']}"}
|
||||
|
||||
# And finally get the user's profile!
|
||||
profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json()
|
||||
|
||||
#pprint.pprint(profile)
|
||||
username = profile['ion_username']
|
||||
email = profile['tj_email']
|
||||
first_name = profile['first_name']
|
||||
last_name = profile['last_name']
|
||||
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(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()
|
||||
r = requests.get(url = "http://localhost:8000/api/teachers/" + user + "/", auth=(user,pwd))
|
||||
profile = r.json()
|
||||
username = profile['ion_user']
|
||||
grade = profile['grade']
|
||||
profile = {
|
||||
'username':username,
|
||||
'grade':grade,
|
||||
'is_student':is_student,
|
||||
'password':pwd,
|
||||
}
|
||||
profileFile = open(".profile", "w")
|
||||
profileFile.write(json.dumps(profile))
|
||||
profileFile.close()
|
||||
|
||||
sys.exit
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user