Skip to content

Commit 0e6f08c

Browse files
committed
chat-app
1 parent 8e09ca6 commit 0e6f08c

File tree

84 files changed

+8670
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+8670
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from __future__ import absolute_import
2+
from .celery import app as celery_app
3+
4+
__all__ = ('celery_app',)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
from channels.routing import ProtocolTypeRouter, URLRouter
3+
from django.core.asgi import get_asgi_application
4+
from channels.security.websocket import AllowedHostsOriginValidator
5+
from channels.auth import AuthMiddlewareStack
6+
from chat_app.routing import websocket_urlpatterns
7+
8+
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ChatApp.settings')
10+
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
11+
12+
application = ProtocolTypeRouter({
13+
"http": get_asgi_application(),
14+
"websocket": AllowedHostsOriginValidator(
15+
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
16+
),
17+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
from celery import Celery
3+
4+
# Set the default Django settings module for the 'celery' program.
5+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ChatApp.settings')
6+
7+
app = Celery('ChatApp')
8+
9+
# Using a string here means the worker doesn't have to serialize
10+
# the configuration object to child processes.
11+
# - namespace='CELERY' means all celery-related configuration keys
12+
# should have a `CELERY_` prefix.
13+
app.config_from_object('django.conf:settings', namespace='CELERY')
14+
15+
# Load task modules from all registered Django apps.
16+
app.autodiscover_tasks()
17+
18+
19+
@app.task(bind=True, ignore_result=True)
20+
def debug_task(self):
21+
print(f'Request: {self.request!r}')
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
from pathlib import Path
2+
import os
3+
4+
5+
BASE_DIR = Path(__file__).resolve().parent.parent
6+
7+
SECRET_KEY = 'django-insecure-o+f#qyg$c$m=fk=j1+05vn@_m&tyy&++ea#ak(!!g(ek*#$y0!'
8+
9+
DEBUG = True
10+
11+
ALLOWED_HOSTS = []
12+
13+
INSTALLED_APPS = [
14+
'daphne',
15+
'channels',
16+
'django.contrib.admin',
17+
'django.contrib.auth',
18+
'django.contrib.contenttypes',
19+
'django.contrib.sessions',
20+
'django.contrib.messages',
21+
'django.contrib.staticfiles',
22+
'django.contrib.sites',
23+
'rest_framework',
24+
'django_cleanup',
25+
'allauth',
26+
'allauth.account',
27+
'allauth.socialaccount',
28+
'allauth.socialaccount.providers.google',
29+
# My Apps
30+
'chat_app.apps.ChatAppConfig',
31+
'account_app.apps.AccountAppConfig',
32+
]
33+
34+
MIDDLEWARE = [
35+
'django.middleware.security.SecurityMiddleware',
36+
'django.contrib.sessions.middleware.SessionMiddleware',
37+
'django.middleware.common.CommonMiddleware',
38+
'django.middleware.csrf.CsrfViewMiddleware',
39+
'django.contrib.auth.middleware.AuthenticationMiddleware',
40+
'django.contrib.messages.middleware.MessageMiddleware',
41+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
42+
]
43+
44+
ROOT_URLCONF = 'ChatApp.urls'
45+
46+
TEMPLATES = [
47+
{
48+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
49+
'DIRS': [BASE_DIR, 'templates'],
50+
'APP_DIRS': True,
51+
'OPTIONS': {
52+
'context_processors': [
53+
'django.template.context_processors.debug',
54+
'django.template.context_processors.request',
55+
'django.contrib.auth.context_processors.auth',
56+
'django.contrib.messages.context_processors.messages',
57+
],
58+
},
59+
},
60+
]
61+
62+
WSGI_APPLICATION = 'ChatApp.wsgi.application'
63+
ASGI_APPLICATION = 'ChatApp.asgi.application'
64+
65+
DATABASES = {
66+
'default': {
67+
'ENGINE': 'django.db.backends.sqlite3',
68+
'NAME': BASE_DIR / 'db.sqlite3',
69+
}
70+
}
71+
72+
AUTH_PASSWORD_VALIDATORS = [
73+
{
74+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
75+
},
76+
{
77+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
78+
},
79+
{
80+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
81+
},
82+
{
83+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
84+
},
85+
]
86+
87+
AUTH_USER_MODEL = "account_app.User"
88+
89+
LANGUAGE_CODE = 'en-us'
90+
TIME_ZONE = 'Asia/Tehran'
91+
USE_I18N = True
92+
USE_TZ = True
93+
94+
STATIC_URL = 'static/'
95+
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets')]
96+
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
97+
MEDIA_URL = 'media/'
98+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
99+
100+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
101+
102+
# Email Configs---------------------------------------------
103+
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
104+
EMAIL_HOST = 'smtp.gmail.com'
105+
EMAIL_USE_TLS = True
106+
EMAIL_PORT = 587
107+
EMAIL_HOST_USER = ''
108+
EMAIL_HOST_PASSWORD = ''
109+
110+
CHANNEL_LAYERS = {
111+
"default": {
112+
"BACKEND": "channels_redis.core.RedisChannelLayer",
113+
"CONFIG": {
114+
"hosts": [("localhost", 6379)],
115+
},
116+
},
117+
}
118+
119+
AUTHENTICATION_BACKENDS = [
120+
'django.contrib.auth.backends.ModelBackend',
121+
'allauth.account.auth_backends.AuthenticationBackend'
122+
]
123+
124+
SOCIALACCOUNT_PROVIDERS = {
125+
'google': {
126+
'SCOPE': [
127+
'profile',
128+
'email',
129+
],
130+
'AUTH_PARAMS': {
131+
'access_type': 'online',
132+
}
133+
}
134+
}
135+
136+
SITE_ID = 1
137+
LOGIN_REDIRECT_URL = '/'
138+
139+
# Additional configuration settings
140+
SOCIALACCOUNT_QUERY_EMAIL = True
141+
ACCOUNT_LOGOUT_ON_GET = True
142+
ACCOUNT_UNIQUE_EMAIL = True
143+
ACCOUNT_EMAIL_REQUIRED = True
144+
145+
146+
# Celery Configuration
147+
CELERY_TIMEZONE = "Asia/Tehran"
148+
CELERY_ENABLE_UTC = True
149+
CELERY_BROKER_URL = 'pyamqp://guest@localhost:5672'
150+
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django.contrib import admin
2+
from django.urls import path, include
3+
from .views import redirector
4+
from django.conf.urls.static import static
5+
from ChatApp import settings
6+
from chat_app import views as chat_views
7+
8+
9+
urlpatterns = [
10+
path('', redirector),
11+
path('admin/', admin.site.urls),
12+
path('chat/', include('chat_app.urls')),
13+
path('account/', include('account_app.urls')),
14+
path('accounts/', include('allauth.urls')),
15+
path('video-call/<slug:room_slug>', chat_views.video_call, name='video_call'),
16+
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
17+
urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.shortcuts import redirect
2+
3+
4+
def redirector(request):
5+
if request.user.is_authenticated:
6+
return redirect('chat:lobby')
7+
else:
8+
return redirect('account:login')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
from django.core.wsgi import get_wsgi_application
3+
4+
5+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ChatApp.settings')
6+
application = get_wsgi_application()

django-chat-application/account_app/__init__.py

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from django.contrib import admin
2+
from django.contrib.auth.admin import UserAdmin
3+
from .forms import CustomUserCreationForm, CustomUserChangeForm
4+
from .models import User, Otp
5+
from django.db import models
6+
from django import forms
7+
8+
9+
class CustomUserAdmin(UserAdmin):
10+
add_form = CustomUserCreationForm
11+
form = CustomUserChangeForm
12+
model = User
13+
list_display = ('username', "first_name", 'last_name', 'email', "is_staff", "is_active", "is_superuser")
14+
list_filter = ("is_staff", "is_active", "is_superuser", "date_joined", "last_login")
15+
readonly_fields = ('date_joined', 'last_login')
16+
search_fields = ("email", "first_name", "last_name")
17+
ordering = ("-date_joined",)
18+
formfield_overrides = {
19+
models.PositiveIntegerField: {'widget': forms.NumberInput(attrs={'size': '15'})},
20+
}
21+
22+
fieldsets = (
23+
(None, {"fields": ("password",)}),
24+
('personal info', {"fields": (
25+
'username',
26+
'first_name',
27+
'last_name',
28+
'email',
29+
'last_login', 'date_joined',
30+
)}),
31+
("permissions", {"fields": ("is_superuser", "is_staff", "is_active", "groups", "user_permissions")}),
32+
)
33+
add_fieldsets = (
34+
(None, {
35+
"classes": ("wide",),
36+
"fields": (
37+
"username",
38+
"email",
39+
"first_name",
40+
"last_name",
41+
"password1", "password2", "is_superuser", "is_staff",
42+
"is_active", "groups", "user_permissions"
43+
)}
44+
),
45+
)
46+
47+
48+
admin.site.register(User, CustomUserAdmin)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountAppConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'account_app'

0 commit comments

Comments
 (0)