Skip to content

Commit

Permalink
Merge 'main' into 'achievements_page'
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Nayak <[email protected]>
  • Loading branch information
nishant-nayak committed Jun 19, 2024
1 parent 1705e05 commit 8f803ca
Show file tree
Hide file tree
Showing 68 changed files with 3,558 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.7 on 2024-03-21 05:30
import datetime

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0004_alter_executivemember_date_joined"),
]

operations = [
migrations.AlterField(
model_name="executivemember",
name="date_joined",
field=models.DateTimeField(
default=datetime.datetime(
2024, 3, 21, 5, 30, 54, 960770, tzinfo=datetime.timezone.utc
),
verbose_name="Date Joined",
),
),
migrations.AlterField(
model_name="executivemember",
name="github",
field=models.CharField(
blank=True, max_length=39, null=True, verbose_name="GitHub Username"
),
),
]
5 changes: 4 additions & 1 deletion corpus/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from .validators import validate_ieee_email
Expand Down Expand Up @@ -138,7 +139,9 @@ class ExecutiveMember(models.Model):
max_length=39, blank=True, null=True, verbose_name="GitHub Username"
)
is_nep = models.BooleanField(default=False, verbose_name="Is NEP Member?")
date_joined = models.DateField(verbose_name="Date Joined")
date_joined = models.DateTimeField(
default=timezone.now(), verbose_name="Date Joined"
)

def save(self, *args, **kwargs):
self.roll_number = self.roll_number.upper()
Expand Down
22 changes: 22 additions & 0 deletions corpus/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from django.contrib.auth.views import PasswordResetCompleteView
from django.contrib.auth.views import PasswordResetConfirmView
from django.contrib.auth.views import PasswordResetDoneView
from django.contrib.auth.views import PasswordResetView
from django.urls import path

from .views import signin
Expand All @@ -8,4 +12,22 @@
path("signup/", signup, name="accounts_signup"),
path("login/", signin, name="accounts_signin"),
path("logout/", signout, name="accounts_signout"),
path(
"reset/",
PasswordResetView.as_view(
html_email_template_name="../templates/registration/password_reset_email.html" # noqa: E501
),
name="password_reset",
),
path("reset/done/", PasswordResetDoneView.as_view(), name="password_reset_done"),
path(
"reset/confirm/<uidb64>/<token>/",
PasswordResetConfirmView.as_view(),
name="password_reset_confirm",
),
path(
"reset/complete/",
PasswordResetCompleteView.as_view(),
name="password_reset_complete",
),
]
2 changes: 1 addition & 1 deletion corpus/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def signin(request):
else:
exec_member = None

if exec_member is not None:
if exec_member:
user = authenticate(
username=exec_member[0].user.email, password=password
)
Expand Down
23 changes: 23 additions & 0 deletions corpus/corpus/decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from accounts.models import ExecutiveMember
from config.models import ModuleConfiguration
from django.contrib import messages
from django.shortcuts import redirect
Expand Down Expand Up @@ -53,3 +54,25 @@ def wrapper(request, *args, **kwargs):
return wrapper

return decorator


def ensure_exec_membership():
def decorator(view_func):
def wrapper(request, *args, **kwargs):
try:
exec_member = ExecutiveMember.objects.get(user=request.user.id)
request.exec_member = exec_member
return view_func(request, *args, **kwargs)
except ExecutiveMember.DoesNotExist:
messages.error(
request,
"""
Permission denied.
Please contact the administrators if you think there is an issue.
""",
)
return redirect("index")

return wrapper

return decorator
133 changes: 129 additions & 4 deletions corpus/corpus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import os
from pathlib import Path

import sentry_sdk
from django.core.exceptions import ImproperlyConfigured

if os.getenv("LIVECYCLE"):
from dotenv import load_dotenv

Expand Down Expand Up @@ -51,6 +54,8 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"ckeditor",
"ckeditor_uploader",
"pages.apps.PagesConfig",
"config.apps.ConfigConfig",
"accounts.apps.AccountsConfig",
Expand All @@ -59,6 +64,8 @@
"electrika.apps.ElectrikaConfig",
"skyward_expedition.apps.SkywardExpeditionConfig",
"robotrix.apps.RobotrixConfig",
"farewell.apps.FarewellConfig",
"virtual_expo.apps.VirtualExpoConfig",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -164,6 +171,10 @@
AUTHENTICATION_BACKENDS = [
"accounts.backend.CorpusAuthBackend",
]

# Reset Timeout in seconds. 1 day
PASSWORD_RESET_TIMEOUT = 86400

LOGIN_URL = "/accounts/login"
LOGIN_REDIRECT_URL = "/"
LOGOUT_URL = ""
Expand All @@ -172,11 +183,125 @@
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

# Email Settings
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = os.getenv("EMAIL_HOST", "smtp.gmail.com")
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "[email protected]")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "gmailapppassword")
EMAIL_PROTOCOL = os.getenv("EMAIL_PROTOCOL", "console")

EMAIL_BACKEND = f"django.core.mail.backends.{EMAIL_PROTOCOL}.EmailBackend"
EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp.gmail.com")
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "[email protected]")
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", "gmailapppassword")
EMAIL_PORT = 465
EMAIL_USE_SSL = True

USE_TAILWIND_CDN_LINK = os.getenv("LIVECYCLE") is not None

SENTRY_DSN = os.environ.get("SENTRY_DSN")
if os.getenv("ENVIRONMENT", "PRODUCTION") == "PRODUCTION":
try:
sentry_sdk.init(
dsn=SENTRY_DSN,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
enable_tracing=True,
)
except Exception:
raise ImproperlyConfigured("Django Sentry DSN Not found!")

CKEDITOR_UPLOAD_PATH = "ckeditor_uploads/"
CKEDITOR_RESTRICT_BY_USER = True
CKEDITOR_CONFIGS = {
"default": {
"toolbar_DefaultToolbarConfig": [
{
"name": "format",
"items": [
"Format",
],
},
{
"name": "extra",
"items": [
"Link",
"Unlink",
"Blockquote",
"Image",
"Table",
"CodeSnippet",
"Mathjax",
"Embed",
],
},
{
"name": "source",
"items": [
"Maximize",
"Source",
],
},
{
"name": "basicstyles",
"items": [
"Bold",
"Italic",
"Underline",
"Strike",
"Subscript",
"Superscript",
],
},
{
"name": "clipboard",
"items": [
"Undo",
"Redo",
],
},
{
"name": "paragraph",
"items": [
"NumberedList",
"BulletedList",
"Outdent",
"Indent",
"HorizontalRule",
"JustifyLeft",
"JustifyCenter",
"JustifyRight",
"JustifyBlock",
],
},
],
"toolbar": "DefaultToolbarConfig",
"removeDialogTabs": ";".join(
[
"image:advanced",
"image:Link",
"link:upload",
"table:advanced",
"tableProperties:advanced",
]
),
"linkShowTargetTab": False,
"linkShowAdvancedTab": False,
"height": "250px",
"width": "auto",
"forcePasteAsPlainText ": True,
"mathJaxClass": "mathjax-latex",
"mathJaxLib": """
https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_SVG
""",
"extraPlugins": ",".join(
[
"mathjax",
"codesnippet",
"image2",
"embed",
"tableresize",
]
),
}
}
20 changes: 20 additions & 0 deletions corpus/corpus/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,26 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from ckeditor_uploader import views as ckeditor_views
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.urls import include
from django.urls import path
from django.views.decorators.cache import never_cache

urlpatterns = [
path(
"ckeditor/upload/",
login_required(ckeditor_views.upload),
name="ckeditor_upload",
),
path(
"ckeditor/browse/",
never_cache(login_required(ckeditor_views.browse)),
name="ckeditor_browse",
),
path("admin/", admin.site.urls),
path("accounts/", include("accounts.urls")),
path("", include("pages.urls")),
Expand All @@ -27,4 +42,9 @@
path("electrika/", include("electrika.urls")),
path("skyward_expedition/", include("skyward_expedition.urls")),
path("robotrix/", include("robotrix.urls")),
path("farewell/", include("farewell.urls")),
path("virtual_expo/", include("virtual_expo.urls")),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Empty file added corpus/farewell/__init__.py
Empty file.
Loading

0 comments on commit 8f803ca

Please sign in to comment.