changes 1
This commit is contained in:
parent
695962d225
commit
06a9bbe343
|
@ -0,0 +1 @@
|
|||
__pycache__
|
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.mkShell {
|
||||
# nativeBuildInputs is usually what you want -- tools you need to run
|
||||
nativeBuildInputs = with pkgs; [
|
||||
buildPackages.python311Packages.django
|
||||
buildPackages.python311Packages.requests
|
||||
];
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
db.sqlite3
|
||||
manage.py
|
|
@ -0,0 +1 @@
|
|||
migrations
|
|
@ -0,0 +1,10 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Organization, Group
|
||||
|
||||
@admin.register(Organization)
|
||||
class OrganizationAdmin(admin.ModelAdmin):
|
||||
exclude = ('_sender_url', '_receiver_url')
|
||||
readonly_fields = ('add_sending_group', 'add_receiving_group', )
|
||||
|
||||
admin.site.register(Group)
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
class BridgeConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'bridge'
|
|
@ -0,0 +1,36 @@
|
|||
from django.db import models
|
||||
import uuid
|
||||
|
||||
def get_uuid():
|
||||
return uuid.uuid4().hex
|
||||
|
||||
class Organization(models.Model):
|
||||
name = models.CharField(
|
||||
max_length=256,
|
||||
)
|
||||
_sender_url = models.CharField(
|
||||
max_length=256,
|
||||
default = get_uuid
|
||||
)
|
||||
_receiver_url = models.CharField(
|
||||
max_length=256,
|
||||
default = get_uuid
|
||||
)
|
||||
|
||||
@property
|
||||
def add_sending_group(self):
|
||||
return "https://tfb.beepboop.systems/groupme/add/send/{}".format(
|
||||
self._sender_url
|
||||
)
|
||||
@property
|
||||
def add_receiving_group(self):
|
||||
return "https://tfb.beepboop.systems/groupme/add/recv/{}".format(
|
||||
self._receiver_url
|
||||
)
|
||||
|
||||
class Group(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
group_id = models.CharField(max_length=256)
|
||||
bot_id = models.CharField(max_length=256)
|
||||
can_send_notices = models.BooleanField()
|
||||
belongs_to = models.ForeignKey(Organization, on_delete=models.SET_NULL, null=True)
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,8 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("oauth_callback", views.handle_oauth, name="handle_oauth"),
|
||||
path("add/send/<str:url_id>", views.add_sending_group, name="add_sending_group"),
|
||||
]
|
|
@ -0,0 +1,35 @@
|
|||
from django.http import HttpResponse, HttpResponseBadRequest
|
||||
from django.shortcuts import redirect
|
||||
from .models import Organization
|
||||
import requests
|
||||
|
||||
auth_link = "https://oauth.groupme.com/oauth/authorize?client_id=qAAAc8GSUlTA8C3Ypo9CMiFQwQCQnU8zPU5KGEtz3FYHDqP5"
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("Hello, world. You're at the polls index.")
|
||||
|
||||
def handle_send_requests(token, org_id):
|
||||
# firstly, check what organization the org_id belongs to
|
||||
matching = Organization.objects.filter(_sender_url = org_id)
|
||||
if matching == []:
|
||||
return HttpResponseBadRequest # this is a fake org_id
|
||||
|
||||
def handle_oauth(request):
|
||||
token = request.GET.get('access_token')
|
||||
try:
|
||||
request_type = request.session["type"]
|
||||
organization_id = request.session["id"]
|
||||
except KeyError:
|
||||
return HttpResponseBadRequest
|
||||
|
||||
if request_type == "send":
|
||||
return handle_send_requests(token, organization_id)
|
||||
|
||||
return HttpResponse(token)
|
||||
|
||||
def add_sending_group(request, url_id):
|
||||
# first part -- authenticate with the GroupMe api
|
||||
request.session['type'] = "send"
|
||||
request.session['id'] = url_id
|
||||
|
||||
return redirect(auth_link)
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
ASGI config for tfb project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tfb.settings')
|
||||
|
||||
application = get_asgi_application()
|
|
@ -0,0 +1,125 @@
|
|||
"""
|
||||
Django settings for tfb project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.16.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-%4qs)a3%&$ykwuu5d$0%^=8u1)b=t=t+vgo!rxvrq1z9+7)w1z'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["10.100.0.2"]
|
||||
CSRF_TRUSTED_ORIGINS = ["https://tfb.beepboop.systems"]
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"bridge.apps.BridgeConfig",
|
||||
'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 = 'tfb.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'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 = 'tfb.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.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/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'groupme/static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
@ -0,0 +1,7 @@
|
|||
from django.contrib import admin
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path('groupme/', include('bridge.urls')),
|
||||
path('groupme/admin/', admin.site.urls),
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for tfb project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tfb.settings')
|
||||
|
||||
application = get_wsgi_application()
|
Loading…
Reference in New Issue