Only staff can access this site. Please login with Ion to proceed.
++ + Log In with Ion + +
diff --git a/hoco/__init__.py b/hoco/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hoco/apps/content/__init__.py b/hoco/apps/content/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hoco/apps/content/admin.py b/hoco/apps/content/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/hoco/apps/content/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/hoco/apps/content/apps.py b/hoco/apps/content/apps.py new file mode 100644 index 0000000..3a9bd48 --- /dev/null +++ b/hoco/apps/content/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ContentConfig(AppConfig): + name = 'content' diff --git a/hoco/apps/content/migrations/__init__.py b/hoco/apps/content/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hoco/apps/content/models.py b/hoco/apps/content/models.py new file mode 100644 index 0000000..137941f --- /dev/null +++ b/hoco/apps/content/models.py @@ -0,0 +1 @@ +from django.db import models diff --git a/hoco/apps/content/tests.py b/hoco/apps/content/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/hoco/apps/content/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/hoco/apps/content/views.py b/hoco/apps/content/views.py new file mode 100644 index 0000000..cec87dd --- /dev/null +++ b/hoco/apps/content/views.py @@ -0,0 +1,10 @@ +from django.shortcuts import render, redirect +from django.urls import reverse + +# Create your views here. +def index(request): + if "admin" in request.session and request.session["admin"] == True: + return render(request, "index.html") + else: + request.session.flush() + return render(request, "fail.html") \ No newline at end of file diff --git a/hoco/apps/oauth/__init__.py b/hoco/apps/oauth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hoco/apps/oauth/admin.py b/hoco/apps/oauth/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/hoco/apps/oauth/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/hoco/apps/oauth/apps.py b/hoco/apps/oauth/apps.py new file mode 100644 index 0000000..17fcea2 --- /dev/null +++ b/hoco/apps/oauth/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class OauthConfig(AppConfig): + name = 'oauth' diff --git a/hoco/apps/oauth/migrations/__init__.py b/hoco/apps/oauth/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hoco/apps/oauth/models.py b/hoco/apps/oauth/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/hoco/apps/oauth/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/hoco/apps/oauth/tests.py b/hoco/apps/oauth/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/hoco/apps/oauth/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/hoco/apps/oauth/views.py b/hoco/apps/oauth/views.py new file mode 100644 index 0000000..ee89056 --- /dev/null +++ b/hoco/apps/oauth/views.py @@ -0,0 +1,33 @@ +import json + +from oauthlib.oauth2.rfc6749.errors import InvalidGrantError +from requests_oauthlib import OAuth2Session + +from django.conf import settings +from django.shortcuts import redirect, render +from django.urls import reverse + +# Create your views here. +def login(request): + oauth = OAuth2Session(settings.CLIENT_ID, redirect_uri=settings.REDIRECT_URI, scope=["read"]) + if "error" in request.GET: + return redirect(reverse("login")) + if "code" not in request.GET: + authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/") + return redirect(authorization_url) + try: + oauth.fetch_token("https://ion.tjhsst.edu/oauth/token/", code=request.GET["code"], client_secret=settings.CLIENT_SECRET) + profile = oauth.get("https://ion.tjhsst.edu/api/profile") + user_data = json.loads(profile.content.decode()) + + authorized_user = False + authorized_users = ["2021abhave", "2020rranjan"] + for user in authorized_users: + if user == user_data["ion_username"]: + authorized_user = True + + request.session["user"] = user_data["ion_username"] + request.session["admin"] = user_data["is_teacher"] or user_data["is_eighth_admin"] or authorized_user + return redirect(reverse("index")) + except InvalidGrantError: + return redirect(reverse("login")) \ No newline at end of file diff --git a/hoco/settings.py b/hoco/settings.py new file mode 100644 index 0000000..5d2c30f --- /dev/null +++ b/hoco/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for hoco project. + +Generated by 'django-admin startproject' using Django 2.2.5. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '-lq2h6ax-h-r94p213v-f@1pj*!8^yf!!w%l^p@o&gie%#8xr0' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + +CLIENT_ID = "0QfO8ZlP7naRYdNLOxpMWayzm2Mlc25FUyeCihGN" +CLIENT_SECRET = "gPfDm2CvNbTnUyj7IG2rCeEBhMaiqicGjLr4xhSO8rDGqTxLVIENX2mWdWNPhg4sSsp48UjILkZCDG83SC3IMnPOSDYj8KnY4bNGJiMjmmPK6d9BZi42ittI4oa62z3j" +REDIRECT_URI = "http://hoco.sites.tjhsst.edu/login" + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'hoco.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(BASE_DIR, "hoco/templates") + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'hoco.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/hoco/templates/base.html b/hoco/templates/base.html new file mode 100644 index 0000000..11a3a93 --- /dev/null +++ b/hoco/templates/base.html @@ -0,0 +1,23 @@ + +{% load static %} + + +
+ + +Only staff can access this site. Please login with Ion to proceed.
+