Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor reset password to use default django auth process #584

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .envs/.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ POSTGRES_PASSWORD=secret
# Email server variables
SMTP_SERVER=mailpit
SMTP_PORT=1025
SMTP_USE_TLS=False
SMTP_USE_SSL=False
SMTP_USER=
SMTP_PASSWORD=
SMTP_SENDER_MAIL="[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion etc/scripts/compilemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
"""
# Walk entire tree, looking for locale directories
basedirs = ["locale"]
for dirpath, dirnames, filenames in os.walk(".", topdown=True):
for dirpath, dirnames, filenames in os.walk("/jandig/locale", topdown=True):
for dirname in dirnames:
if dirname == "locale":
basedirs.append(os.path.join(dirpath, dirname))
Expand Down
16 changes: 10 additions & 6 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils.translation import gettext_lazy as _
from sentry_sdk.integrations.django import DjangoIntegration

from .storage_settings import * # noqa F403 F401
from .storage_settings import * # noqa F403 F401

ROOT_DIR = environ.Path("/jandig/")
BASE_DIR = "/jandig/src"
Expand Down Expand Up @@ -194,11 +194,15 @@ def debug(request):
# Sphinx docs
DOCS_ROOT = "/jandig/build/"

SMTP_SERVER = env("SMTP_SERVER", default="mailpit")
SMTP_PORT = env("SMTP_PORT", default=1025)
SMTP_USER = env("SMTP_USER", default="[email protected]")
SMTP_PASSWORD = env("SMTP_PASSWORD", default="password")
SMTP_SENDER_MAIL = env("SMTP_SENDER_MAIL", default="[email protected]")

DEFAULT_FROM_EMAIL = env("SMTP_SENDER_MAIL", default="[email protected]")
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = env("SMTP_SERVER", default="mailpit")
EMAIL_USE_TLS = env("SMTP_USE_TLS", default=False)
EMAIL_PORT = env("SMTP_PORT", default=1025)
EMAIL_HOST_USER = env("SMTP_USER", default="[email protected]")
EMAIL_HOST_PASSWORD = env("SMTP_PASSWORD", default="password")
EMAIL_USE_SSL = False

# Recaptcha
RECAPTCHA_ENABLED = env("RECAPTCHA_ENABLED", default=False)
Expand Down
8 changes: 6 additions & 2 deletions src/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.urls import include, path
from django.urls import include, path, re_path
from rest_framework_nested.routers import DefaultRouter

from core.views.artworks import ArtworkViewset
Expand Down Expand Up @@ -47,7 +47,11 @@
path("manifest.json", manifest, name="manifest"),
path("upload", upload_image, name="upload-image"),
path("i18n/", include("django.conf.urls.i18n")),
path("see_all/", see_all, name="see_all"),
re_path(
r"^see_all(?:/(?P<which>[a-zA-Z]+))?(?:/(?P<page>\d+))?/$",
see_all,
name="see_all",
),
path("robots.txt", robots_txt),
path("favicon.ico", favicon),
path(settings.HEALTH_CHECK_URL, health_check),
Expand Down
23 changes: 17 additions & 6 deletions src/core/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ def collection(request):

@cache_page(60 * 2)
@require_http_methods(["GET"])
def see_all(request):
request_type = request.GET.get("which")
def see_all(request, which="", page=1):
request_type = request.GET.get("which", which)
if request_type not in ["objects", "markers", "artworks", "exhibits"]:
# Invalid request type, return to collection
return redirect("collection")
ctx = {}
per_page = 20
per_page = 3
page = request.GET.get("page", 1)

try:
# Bots insert random strings in the page parameter
page = int(page)
except ValueError:
page = 1

data_types = {
"objects": Object.objects.all().order_by("uploaded_at"),
"markers": Marker.objects.all().order_by("uploaded_at"),
Expand All @@ -67,10 +76,12 @@ def see_all(request):
data = data_types.get(request_type)
if data:
paginator = Paginator(data, per_page)
data = paginator.get_page(page)
data.adjusted_elided_pages = paginator.get_elided_page_range(page)
if page > paginator.num_pages:
return redirect("see_all", request_type, paginator.num_pages)
paginated_data = paginator.get_page(page)
paginated_data.adjusted_elided_pages = paginator.get_elided_page_range(page)
ctx = {
request_type: data,
request_type: paginated_data,
"seeall": True,
}

Expand Down
8 changes: 0 additions & 8 deletions src/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ def clean(self):
return cleaned_data


class RecoverPasswordForm(forms.Form):
username_or_email = forms.CharField(label="username / email", max_length="50")


class RecoverPasswordCodeForm(forms.Form):
verification_code = forms.CharField(label="Verification code", max_length="200")


class UploadMarkerForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(UploadMarkerForm, self).__init__(*args, **kwargs)
Expand Down
22 changes: 0 additions & 22 deletions src/users/jinja2/users/invalid-recovering-email.jinja2

This file was deleted.

2 changes: 1 addition & 1 deletion src/users/jinja2/users/login.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<input class="submit-btn" type="submit" value="{{ _('Submit') }}"/>
</form>
<div class="modalMenu recover-password">
<a href="{{url('recover')}}">{{ _('Recover password') }}</a>
<a href="{{url('reset-password')}}">{{ _('Recover password') }}</a>
</div>
</div>
</div>
Expand Down
31 changes: 0 additions & 31 deletions src/users/jinja2/users/recover-edit-password.jinja2

This file was deleted.

31 changes: 0 additions & 31 deletions src/users/jinja2/users/recover-password-code.jinja2

This file was deleted.

46 changes: 0 additions & 46 deletions src/users/jinja2/users/recover-password.jinja2

This file was deleted.

59 changes: 59 additions & 0 deletions src/users/jinja2/users/reset-password/password_reset.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{% extends '/core/arviewer.jinja2' %}
{% block content %}
<div class="form-content my-3 p-3">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5">
<div class="card shadow-lg border-0 rounded-lg mt-0 mb-3">
<div class="card-header justify-content-center">
<div id="error_div"></div>
<h3 class="font-weight-light my-4 text-center">Forgot Password?</h3>
</div>
{% if form.errors %}
<div class="alert alert-danger alert-dismissible" role="alert">
<div id="form_errors">
{% for key, value in form.errors.items %}
<strong>{{ value }}</strong>
{% endfor %}
</div>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endif %}
<div class="card-body">
<form method="POST">
{{ csrf_input }}
<div class="form-row">
<div class="col-md-10 offset-md-1">
<div class="form-group">
<label class="small mb-1" for="id_email">Email</label>
<input type="email" name="email" class="form-control"
autocomplete="email" maxlength="254" required id="id_email"
placeholder="Enter email">
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-10 offset-md-1">
<div class="form-group mt-0 mb-1">
<button type="submit" class="col-md-12 btn btn-dark">Submit
</button>
</div>
</div>
</div>
</form>
</div>
<div class="card-footer text-center">
<div class="small">
<a href="{{ url('signup') }}">Create A New Account</a><br><br>
<a href="{{ url('login') }}">Back To Login</a><br>
</div>
</div>
</div>
</div>
</div>
</div>

</div>
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends '/core/arviewer.jinja2' %}
{% block title %} Password Reset {% endblock title%}
{% block content %}
<div class="container my-3 p-3">
<div class="row justify-content-center">
<div class="col-lg-5">
<div class="card shadow-lg border-0 rounded-lg mt-0 mb-3">
<div class="alert alert-info">
Your password has been set. You may go ahead and <a href="{{ url('login') }}">Login Here</a>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
Loading
Loading