Commit 3749c917 authored by David Haynes's avatar David Haynes 🙆

Fuck token auth we session auth now boyssssssssssss

parent e14d8cc3
Pipeline #3567 passed with stage
in 1 minute and 13 seconds
...@@ -16,11 +16,11 @@ const SignupSchema = Yup.object().shape({ ...@@ -16,11 +16,11 @@ const SignupSchema = Yup.object().shape({
class DebugCRUD extends React.Component { class DebugCRUD extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { AllGoLinks: "", error: null }; this.state = { AllGoLinks: [], error: null };
} }
async componentDidMount() { async componentDidMount() {
GetAllGoLinks(this.props.authToken) GetAllGoLinks()
.then(data => .then(data =>
this.setState({ this.setState({
AllGoLinks: data AllGoLinks: data
......
async function GetAllGoLinks(token) { async function GetAllGoLinks() {
let response = await fetch("/auth/token"); let response = await fetch("/api/golinks/", {
headers: {
"Content-Type": "application/json"
}
});
let data = await response.json(); let data = await response.json();
return data; return data;
} }
......
...@@ -10,57 +10,14 @@ import { ...@@ -10,57 +10,14 @@ import {
const NavBarWithRouter = withRouter(props => <NavBar {...props} />); const NavBarWithRouter = withRouter(props => <NavBar {...props} />);
class Routes extends React.Component { const Routes = () => (
constructor(props) { <div>
super(props); <NavBarWithRouter />
this.state = { <Route path="/" exact component={HomePage} />
error: null, <Route path="/dhaynes" component={DhaynesPage} />
authToken: null <Route path="/about" component={AboutPage} />
}; <Route path="/debug" component={DebugCRUD} />
} </div>
);
componentDidMount() {
fetch("/auth/token")
.then(res => res.json())
.then(
result => {
this.setState({
authToken: result.token
});
},
error => {
this.setState({
error
});
}
);
}
render() {
const { authToken } = this.state;
return (
<div>
<NavBarWithRouter />
<Route
path="/"
exact
render={props => <HomePage {...props} authToken={authToken} />}
/>
<Route
path="/dhaynes"
render={props => <DhaynesPage {...props} authToken={authToken} />}
/>
<Route
path="/about"
render={props => <AboutPage {...props} authToken={authToken} />}
/>
<Route
path="/debug"
render={props => <DebugCRUD {...props} authToken={authToken} />}
/>
</div>
);
}
}
export default Routes; export default Routes;
...@@ -34,7 +34,7 @@ class URLViewSet(viewsets.ModelViewSet): ...@@ -34,7 +34,7 @@ class URLViewSet(viewsets.ModelViewSet):
API endpoint that handles creation/read/update/deletion of URL objects. API endpoint that handles creation/read/update/deletion of URL objects.
""" """
authentication_classes = (TokenAuthentication,) authentication_classes = (TokenAuthentication, SessionAuthentication)
serializer_class = URLSerializer serializer_class = URLSerializer
permission_classes = (URLPermission, IsAuthenticated) permission_classes = (URLPermission, IsAuthenticated)
lookup_field = "short" lookup_field = "short"
......
...@@ -8,21 +8,14 @@ import os ...@@ -8,21 +8,14 @@ import os
import sys import sys
# DEV vs PROD # DEV vs PROD
if os.environ['GO_ENV'] != 'production': if os.environ["GO_ENV"] != "production":
DEBUG = True DEBUG = True
# dummy cache for development-- doesn't actually cache things # dummy cache for development-- doesn't actually cache things
CACHES = { CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
else: else:
DEBUG = False DEBUG = False
CACHES = { CACHES = {
'default': { "default": {"BACKEND": "redis_cache.RedisCache", "LOCATION": "localhost:6379"}
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
},
} }
# STANDALONE VARS # STANDALONE VARS
...@@ -32,14 +25,14 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) ...@@ -32,14 +25,14 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# You can generate a secret key from the following link: # You can generate a secret key from the following link:
# http://www.miniwebtool.com/django-secret-key-generator/ # http://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = os.environ['GO_SECRET_KEY'] SECRET_KEY = os.environ["GO_SECRET_KEY"]
# Peoplefinder API # Peoplefinder API
PF_URL = "https://api.srct.gmu.edu/peoplefinder/v1/" PF_URL = "https://api.srct.gmu.edu/peoplefinder/v1/"
# The domains this application will be deployed on # The domains this application will be deployed on
# e.g. Which domains this app should listen to requests from. # e.g. Which domains this app should listen to requests from.
ALLOWED_HOSTS = [os.environ['GO_ALLOWED_HOSTS']] ALLOWED_HOSTS = [os.environ["GO_ALLOWED_HOSTS"]]
ADMINS = () ADMINS = ()
MANAGERS = ADMINS MANAGERS = ADMINS
...@@ -47,47 +40,39 @@ MANAGERS = ADMINS ...@@ -47,47 +40,39 @@ MANAGERS = ADMINS
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/ # https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = "en-us"
TIME_ZONE = 'UTC' TIME_ZONE = "UTC"
USE_I18N = True USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = True USE_TZ = True
# MEDIA/STATIC FILE CONFIGURATION # MEDIA/STATIC FILE CONFIGURATION
MEDIA_URL = '/media/' MEDIA_URL = "/media/"
MEDIA_ROOT = '' MEDIA_ROOT = ""
MEDIAFILES_DIRS = ( MEDIAFILES_DIRS = (os.path.join(BASE_DIR, "media/"),)
os.path.join(BASE_DIR, 'media/'),
)
STATIC_URL = '/static/' STATIC_URL = "/static/"
STATIC_ROOT = '' STATIC_ROOT = ""
STATICFILES_DIRS = ( STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"), "./go/static/")
os.path.join(BASE_DIR, 'static/'),
'./go/static/'
)
STATICFILES_FINDERS = ( STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', "django.contrib.staticfiles.finders.FileSystemFinder",
'django.contrib.staticfiles.finders.AppDirectoriesFinder', "django.contrib.staticfiles.finders.AppDirectoriesFinder",
) )
# TEMPLATING # TEMPLATING
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', "BACKEND": "django.template.backends.django.DjangoTemplates",
'DIRS': [ "DIRS": [os.path.join(BASE_DIR, "templates"), "./go/go_ahead/templates/"],
os.path.join(BASE_DIR, 'templates'), "APP_DIRS": True,
'./go/go_ahead/templates/' "OPTIONS": {
], "context_processors": [
'APP_DIRS': True, "django.template.context_processors.debug",
'OPTIONS': { "django.template.context_processors.request",
'context_processors': [ "django.contrib.auth.context_processors.auth",
'django.template.context_processors.debug', "django.contrib.messages.context_processors.messages",
'django.template.context_processors.request', ]
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
}, },
} }
] ]
...@@ -95,127 +80,115 @@ TEMPLATES = [ ...@@ -95,127 +80,115 @@ TEMPLATES = [
# Use the same DB everywhere. # Use the same DB everywhere.
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = { DATABASES = {
'default': { "default": {
'ENGINE': 'django.db.backends.mysql', "ENGINE": "django.db.backends.mysql",
'NAME': os.environ['GO_DB_NAME'], "NAME": os.environ["GO_DB_NAME"],
'USER': os.environ['GO_DB_USER'], "USER": os.environ["GO_DB_USER"],
'PASSWORD': os.environ['GO_DB_PASSWORD'], "PASSWORD": os.environ["GO_DB_PASSWORD"],
'HOST': os.environ['GO_DB_HOST'], "HOST": os.environ["GO_DB_HOST"],
'PORT': os.environ['GO_DB_PORT'], "PORT": os.environ["GO_DB_PORT"],
'OPTIONS': {'charset': 'utf8mb4'} "OPTIONS": {"charset": "utf8mb4"},
} }
} }
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.common.CommonMiddleware', "django.middleware.common.CommonMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware', "django.contrib.sessions.middleware.SessionMiddleware",
'django.middleware.csrf.CsrfViewMiddleware', "django.middleware.csrf.CsrfViewMiddleware",
'django.contrib.auth.middleware.AuthenticationMiddleware', "django.contrib.auth.middleware.AuthenticationMiddleware",
'django.contrib.messages.middleware.MessageMiddleware', "django.contrib.messages.middleware.MessageMiddleware",
'cas.middleware.CASMiddleware', "cas.middleware.CASMiddleware",
] ]
ROOT_URLCONF = 'settings.urls' ROOT_URLCONF = "settings.urls"
WSGI_APPLICATION = 'settings.wsgi.application' WSGI_APPLICATION = "settings.wsgi.application"
INSTALLED_APPS = ( INSTALLED_APPS = (
# Django apps # Django apps
'django.contrib.auth', "django.contrib.auth",
'django.contrib.contenttypes', "django.contrib.contenttypes",
'django.contrib.sessions', "django.contrib.sessions",
'django.contrib.sites', "django.contrib.sites",
'django.contrib.messages', "django.contrib.messages",
'django.contrib.staticfiles', "django.contrib.staticfiles",
'django.contrib.admin', "django.contrib.admin",
'go_back', "go_back",
'go_ahead', "go_ahead",
# Third party # Third party
'crispy_forms', "crispy_forms",
'cas', "cas",
'rest_framework', "rest_framework",
'rest_framework.authtoken' "rest_framework.authtoken",
) )
CRISPY_TEMPLATE_PACK = 'bootstrap4' CRISPY_TEMPLATE_PACK = "bootstrap4"
LOGGING = { LOGGING = {
'version': 1, "version": 1,
'disable_existing_loggers': False, "disable_existing_loggers": False,
'filters': { "filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
'require_debug_false': { "handlers": {
'()': 'django.utils.log.RequireDebugFalse' "mail_admins": {
} "level": "ERROR",
}, "filters": ["require_debug_false"],
'handlers': { "class": "django.utils.log.AdminEmailHandler",
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}, },
'console': { "console": {
'level': 'INFO', "level": "INFO",
'class': 'logging.StreamHandler', "class": "logging.StreamHandler",
'stream': sys.stdout "stream": sys.stdout,
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
}, },
'django': { },
'handlers': ['console'], "loggers": {
'level': 'INFO', "django.request": {
'propogate': True "handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True,
}, },
} "django": {"handlers": ["console"], "level": "INFO", "propogate": True},
},
} }
""" """
CAS Authentication Settings CAS Authentication Settings
""" """
LOGIN_URL = '/login' LOGIN_URL = "/login"
LOGOUT_URL = '/logout' LOGOUT_URL = "/logout"
LOGIN_REDIRECT_URL = '/' LOGIN_REDIRECT_URL = "/"
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', "django.contrib.auth.backends.ModelBackend",
'cas.backends.CASBackend', "cas.backends.CASBackend",
) )
CAS_LOGOUT_COMPLETELY = True CAS_LOGOUT_COMPLETELY = True
CAS_PROVIDE_URL_TO_LOGOUT = True CAS_PROVIDE_URL_TO_LOGOUT = True
CAS_RESPONSE_CALLBACKS = ( CAS_RESPONSE_CALLBACKS = ("go_back.cas_callbacks.create_user",)
'go_back.cas_callbacks.create_user',
)
CAS_SERVER_URL = "https://login.gmu.edu" CAS_SERVER_URL = "https://login.gmu.edu"
""" """
Mail Settings Mail Settings
""" """
EMAIL_HOST = os.environ['GO_EMAIL_HOST'] EMAIL_HOST = os.environ["GO_EMAIL_HOST"]
EMAIL_PORT = os.environ['GO_EMAIL_PORT'] EMAIL_PORT = os.environ["GO_EMAIL_PORT"]
EMAIL_HOST_USER = os.environ['GO_EMAIL_HOST_USER'] EMAIL_HOST_USER = os.environ["GO_EMAIL_HOST_USER"]
EMAIL_HOST_PASSWORD = os.environ['GO_EMAIL_HOST_PASSWORD'] EMAIL_HOST_PASSWORD = os.environ["GO_EMAIL_HOST_PASSWORD"]
EMAIL_FROM = os.environ['GO_EMAIL_FROM'] EMAIL_FROM = os.environ["GO_EMAIL_FROM"]
EMAIL_TO = os.environ['GO_EMAIL_TO'] EMAIL_TO = os.environ["GO_EMAIL_TO"]
# Domain used to email to users. See implementation in views.py # Domain used to email to users. See implementation in views.py
# ie. '@gmu.edu' # ie. '@gmu.edu'
EMAIL_DOMAIN = os.environ['GO_EMAIL_DOMAIN'] EMAIL_DOMAIN = os.environ["GO_EMAIL_DOMAIN"]
""" """
Django Rest Framework Settings Django Rest Framework Settings
""" """
REST_FRAMEWORK = { REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [ "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
'rest_framework.permissions.IsAuthenticated' "DEFAULT_AUTHENTICATION_CLASSES": [
], "rest_framework.authentication.TokenAuthentication",
'DEFAULT_AUTHENTICATION_CLASSES': [ "rest_framework.authentication.SessionAuthentication",
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
], ],
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment