Skip to content

Commit

Permalink
Create new reset-password view
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Nov 21, 2024
1 parent baa67bf commit 2bd9741
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 25 deletions.
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
14 changes: 9 additions & 5 deletions src/config/settings.py
Original file line number Diff line number Diff line change
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
59 changes: 59 additions & 0 deletions src/users/jinja2/users/html/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 %}
15 changes: 15 additions & 0 deletions src/users/jinja2/users/html/password_reset_complete.jinja2
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 %}
71 changes: 71 additions & 0 deletions src/users/jinja2/users/html/password_reset_confirm.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{% extends '/core/arviewer.jinja2' %}
{% block title %} Password Reset {% endblock title%}
{% block content %}
<div class="form-content my-3 p-3">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5">
{% if validlink %}
<div class="card shadow-lg border-0 rounded-lg mt-0 mb-3">
<div class="card-header justify-content-center">
<h3 class="font-weight-light my-4 text-center">Reset Your 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_new_password1">New Password</label>
<input type="password" name="new_password1" autocomplete="new-password"
class="form-control" required id="id_new_password1"
placeholder="Enter password"/>
<span>
</span>
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-10 offset-md-1">
<div class="form-group">
<label class="small mb-1" for="id_new_password2">New Password Confirmation</label>
<input type="password" name="new_password2" autocomplete="new-password"
required id="id_new_password2" class="form-control"
placeholder="Confirm password"/>
</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" id="reset">Reset Password</button>
</div>
</div>
</div>
</form>
</div>
</div>
{% else %}
<div class="alert alert-warning">
The password reset link was invalid, possibly because it has already been used.
Please request a new password reset.
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock content %}
11 changes: 11 additions & 0 deletions src/users/jinja2/users/html/password_reset_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

To initiate the password reset process for your {{ user.email }} Django Registration/Login App Account,
click the link below:

{{ protocol }}://{{ domain }}{{ url('password_reset_confirm',args=[uid,token]) }}

If clicking the link above doesn't work, please copy and paste the URL in a new browser
window instead.

Sincerely,
Jandig Team
1 change: 1 addition & 0 deletions src/users/jinja2/users/html/password_reset_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jandig Password Reset
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
34 changes: 21 additions & 13 deletions src/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
related_content,
signup,
wrong_verification_code,
ResetPasswordView,
)

urlpatterns = [
Expand All @@ -40,22 +41,29 @@
name="login",
),
path("logout/", auth_views.LogoutView.as_view(), name="logout"),
path("recover/", recover_password, name="recover"),
path("recover-code/", recover_code, name="recover-code"),
path('reset-password/', ResetPasswordView.as_view(), name='reset-password'),
path('password-reset-confirm/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(template_name='users/html/password_reset_confirm.jinja2'),
name='password_reset_confirm'),
path('password-reset-complete/',
auth_views.PasswordResetCompleteView.as_view(template_name='users/html/password_reset_complete.jinja2'),
name='password_reset_complete'),
# path("recover/", recover_password, name="recover"),
# path("recover-code/", recover_code, name="recover-code"),
# path(
# "wrong-verification-code",
# wrong_verification_code,
# name="wrong-verification-code",
# ),
# path(
# "invalid-recovering-email",
# invalid_recovering_email_or_username,
# name="invalid_recovering_email_or_username",
# ),
# path("recover-edit-password", recover_edit_password, name="recover-edit-password"),
path("profile/", profile, name="profile"),
path("profile/edit/", edit_profile, name="edit-profile"),
path("profile/edit-password/", edit_password, name="edit-password"),
path(
"wrong-verification-code",
wrong_verification_code,
name="wrong-verification-code",
),
path(
"invalid-recovering-email",
invalid_recovering_email_or_username,
name="invalid_recovering_email_or_username",
),
path("recover-edit-password", recover_edit_password, name="recover-edit-password"),
path("markers/upload/", marker_upload, name="marker-upload"),
path("objects/upload/", object_upload, name="object-upload"),
path("element/get/", element_get, name="element-get"),
Expand Down
21 changes: 15 additions & 6 deletions src/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
UploadObjectForm,
)
from .models import Profile
from .services.email_service import EmailService
from .services.encrypt_service import EncryptService
from .services.recaptcha_service import BOT_SCORE, create_assessment
from .services.user_service import UserService
from .services import ( EmailService,EncryptService ,BOT_SCORE, create_assessment, UserService)
from django.urls import reverse_lazy
from django.contrib.auth.views import PasswordResetView
from django.contrib.messages.views import SuccessMessageMixin

log = logging.getLogger(__file__)

User = get_user_model()


def signup(request):
if request.method == "POST":
Expand Down Expand Up @@ -72,8 +74,15 @@ def signup(request):
)


User = get_user_model()

class ResetPasswordView(SuccessMessageMixin, PasswordResetView):
template_name = 'users/html/password_reset.jinja2'
email_template_name = 'users/html/password_reset_email.html'
subject_template_name = 'users/html/password_reset_subject.txt'
success_message = _("We've emailed you instructions for setting your password, " \
"if an account exists with the email you entered. You should receive them shortly." \
" If you don't receive an email, " \
"please make sure you've entered the address you registered with, and check your spam folder.")
success_url = reverse_lazy('home')

def recover_password(request):
if request.method == "POST":
Expand Down

0 comments on commit 2bd9741

Please sign in to comment.