Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dde8974
commit e3c1adf
Showing
39,074 changed files
with
3,228,831 additions
and
2 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Submodule api
deleted from
8b0a51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "/home/adefemigreat/.virtualenvs/chatapp_env/bin/python" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: '3' | ||
|
||
services: | ||
postgres: | ||
container_name: postgres_container | ||
image: postgres | ||
environment: | ||
POSTGRES_USER: "postgres" | ||
POSTGRES_PASSWORD: "admin123" | ||
PGDATA: /data/postgres | ||
volumes: | ||
- postgres:/data/postgres | ||
ports: | ||
- "5432:5432" | ||
networks: | ||
- postgres | ||
restart: unless-stopped | ||
|
||
networks: | ||
postgres: | ||
driver: bridge | ||
|
||
volumes: | ||
postgres: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3.6 | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN mkdir /chatapi | ||
|
||
WORKDIR /chatapi | ||
|
||
COPY . /chatapi/ | ||
|
||
RUN pip install --upgrade pip && pip install pip-tools && pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This is a simple chat api to with socket.io |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for chatapi 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/3.1/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatapi.settings') | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from rest_framework.permissions import BasePermission, SAFE_METHODS | ||
from django.utils import timezone | ||
from rest_framework.views import exception_handler | ||
from rest_framework.response import Response | ||
from django.contrib.auth import authenticate | ||
|
||
|
||
class IsAuthenticatedCustom(BasePermission): | ||
|
||
def has_permission(self, request, view): | ||
from user_control.views import decodeJWT | ||
user = decodeJWT(request.META['HTTP_AUTHORIZATION']) | ||
if not user: | ||
return False | ||
request.user = user | ||
if request.user and request.user.is_authenticated: | ||
from user_control.models import CustomUser | ||
CustomUser.objects.filter(id=request.user.id).update( | ||
is_online=timezone.now()) | ||
return True | ||
return False | ||
|
||
|
||
class IsAuthenticatedOrReadCustom(BasePermission): | ||
def has_permission(self, request, view): | ||
if request.method in SAFE_METHODS: | ||
return True | ||
|
||
if request.user and request.user.is_authenticated: | ||
from user_control.models import CustomUser | ||
CustomUser.objects.filter(id=request.user.id).update( | ||
is_online=timezone.now()) | ||
return True | ||
return False | ||
|
||
|
||
def custom_exception_handler(exc, context): | ||
|
||
response = exception_handler(exc, context) | ||
|
||
if response is not None: | ||
return response | ||
|
||
exc_list = str(exc).split("DETAIL: ") | ||
|
||
return Response({"error": exc_list[-1]}, status=403) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
""" | ||
Django settings for chatapi project. | ||
Generated by 'django-admin startproject' using Django 3.1. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/3.1/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/3.1/ref/settings/ | ||
""" | ||
|
||
from pathlib import Path | ||
import os | ||
from decouple import config | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '10y83$&yi^2_g_y*r^eeabge40t&0ioyd9=m-4h-sc!0aq4rjm' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
AUTH_USER_MODEL = "user_control.CustomUser" | ||
|
||
REST_FRAMEWORK = { | ||
'EXCEPTION_HANDLER': 'chatapi.custom_methods.custom_exception_handler', | ||
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", | ||
"PAGE_SIZE": 20, | ||
} | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'rest_framework', | ||
'user_control', | ||
'message_control', | ||
'chatapi', | ||
'corsheaders', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'corsheaders.middleware.CorsMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'chatapi.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 = 'chatapi.wsgi.application' | ||
|
||
CORS_ORIGIN_ALLOW_ALL = True | ||
CORS_ALLOW_HEADERS = ( | ||
'x-requested-with', | ||
'content-type', | ||
'accept', | ||
'origin', | ||
'authorization', | ||
'accept-encoding', | ||
'x-csrftoken', | ||
'access-control-allow-origin', | ||
'content-disposition' | ||
) | ||
CORS_ALLOW_CREDENTIALS = False | ||
CORS_ALLOW_METHODS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS') | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases | ||
|
||
DB_NAME = config("DB_NAME") | ||
DB_USER = config("DB_USER") | ||
DB_PASSWORD = config("DB_PASSWORD") | ||
DB_HOST = config("DB_HOST") | ||
DB_PORT = config("DB_PORT") | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
'NAME': DB_NAME, | ||
'USER': DB_USER, | ||
'PASSWORD': DB_PASSWORD, | ||
'HOST': DB_HOST, | ||
'PORT': DB_PORT, | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/3.1/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/3.1/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/3.1/howto/static-files/ | ||
|
||
|
||
S3_BUCKET_URL = config('S3_BUCKET_URL') | ||
STATIC_ROOT = 'staticfiles' | ||
|
||
AWS_ACCESS_KEY_ID = config('AWS_S3_ACCESS_KEY_ID') | ||
AWS_SECRET_ACCESS_KEY = config('AWS_S3_SECRET_ACCESS_KEY') | ||
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME') | ||
AWS_HOST_REGION = config('AWS_HOST_REGION') | ||
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME | ||
AWS_DEFAULT_ACL = None | ||
|
||
AWS_LOCATION = 'static' | ||
|
||
MEDIA_URL = '/media/' | ||
|
||
|
||
STATICFILES_DIRS = [ | ||
os.path.join(BASE_DIR, 'chatapi/static'), | ||
] | ||
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION) | ||
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' | ||
|
||
|
||
AWS_S3_OBJECT_PARAMETERS = { | ||
'CacheControl': 'max-age=86400', | ||
} | ||
|
||
|
||
DEFAULT_FILE_STORAGE = 'chatapi.storage_backends.MediaStorage' | ||
|
||
SOCKET_SERVER = config("SOCKET_SERVER") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from storages.backends.s3boto3 import S3Boto3Storage | ||
|
||
|
||
class MediaStorage(S3Boto3Storage): | ||
location = 'media' | ||
file_overwrite = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
from django.contrib import admin | ||
from django.urls import path, include | ||
from django.conf.urls.static import static | ||
from django.conf import settings | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('user/', include('user_control.urls')), | ||
path('message/', include('message_control.urls')) | ||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for chatapi 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/3.1/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatapi.settings') | ||
|
||
application = get_wsgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "3" | ||
|
||
services: | ||
api: | ||
build: . | ||
command: bash -c "python manage.py runserver 0.0.0.0:8000" | ||
container_name: chatapi | ||
restart: unless-stopped | ||
volumes: | ||
- .:/chatapi | ||
ports: | ||
- "8000:8000" | ||
networks: | ||
- postgres | ||
|
||
networks: | ||
postgres: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatapi.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class MessageControlConfig(AppConfig): | ||
name = 'message_control' |
Oops, something went wrong.