Allow CID users to request details by email
This commit is contained in:
+15
-1
@@ -1,4 +1,5 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from typing import Tuple
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
@@ -544,6 +545,10 @@ class CidUser(models.Model):
|
|||||||
html_msg = f""""""
|
html_msg = f""""""
|
||||||
|
|
||||||
def email_results(self, resend=False, additional_emails=[]):
|
def email_results(self, resend=False, additional_emails=[]):
|
||||||
|
"""Emails a CID candidate results (internal candidates)
|
||||||
|
|
||||||
|
***DEPRECATED***
|
||||||
|
"""
|
||||||
if not self.internal_candidate:
|
if not self.internal_candidate:
|
||||||
return False, "Not internal candidate."
|
return False, "Not internal candidate."
|
||||||
|
|
||||||
@@ -574,12 +579,21 @@ class CidUser(models.Model):
|
|||||||
self.save()
|
self.save()
|
||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
def email_details(self, resend=False):
|
def email_details(self, resend: bool=False) -> Tuple[bool, str]:
|
||||||
|
"""Email candidate details to the CID user
|
||||||
|
|
||||||
|
Args:
|
||||||
|
resend (bool, optional): Force sending details (even if sent previously). Defaults to False.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[bool, str]: Tuple containing the email status and any error message
|
||||||
|
"""
|
||||||
if self.login_email_sent and not resend:
|
if self.login_email_sent and not resend:
|
||||||
return False, "Already sent."
|
return False, "Already sent."
|
||||||
|
|
||||||
login_url = reverse("cid_selector")
|
login_url = reverse("cid_selector")
|
||||||
|
|
||||||
|
|
||||||
msg = f"""
|
msg = f"""
|
||||||
See below for your details for: {self.group}
|
See below for your details for: {self.group}
|
||||||
|
|
||||||
|
|||||||
@@ -2227,6 +2227,7 @@ class CidUserView(CidManagerRequiredMixin, SingleTableMixin, FilterView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_is_cid_user_manager
|
@user_is_cid_user_manager
|
||||||
def cid_group_view(request):
|
def cid_group_view(request):
|
||||||
groups = CidUserGroup.objects.filter(archive=False)
|
groups = CidUserGroup.objects.filter(archive=False)
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ urlpatterns = [
|
|||||||
path("cid/<int:cid>/", views.cid_scores_admin, name="cid_scores_admin"),
|
path("cid/<int:cid>/", views.cid_scores_admin, name="cid_scores_admin"),
|
||||||
path("user/scores", views.user_scores, name="user_scores"),
|
path("user/scores", views.user_scores, name="user_scores"),
|
||||||
path("cid/", views.cid_selector, name="cid_selector"),
|
path("cid/", views.cid_selector, name="cid_selector"),
|
||||||
|
path("cid/request_cid_details/", views.request_cid_details, name="request_cid_details"),
|
||||||
# Global url that registers RTS compatible exams
|
# Global url that registers RTS compatible exams
|
||||||
path("exam/json/", views.active_exams, name="active_exams"),
|
path("exam/json/", views.active_exams, name="active_exams"),
|
||||||
path(
|
path(
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ from django.shortcuts import render, get_object_or_404, redirect
|
|||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.validators import validate_email
|
||||||
|
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
|
||||||
# from django.contrib.auth.models import User
|
# from django.contrib.auth.models import User
|
||||||
@@ -724,3 +727,20 @@ def accounts_bulk_create(request):
|
|||||||
return render(request, "accounts_bulk_create.html", context)
|
return render(request, "accounts_bulk_create.html", context)
|
||||||
else:
|
else:
|
||||||
return render(request, "accounts_bulk_create.html", {})
|
return render(request, "accounts_bulk_create.html", {})
|
||||||
|
|
||||||
|
|
||||||
|
def request_cid_details(request):
|
||||||
|
email = request.POST.get("email")
|
||||||
|
try:
|
||||||
|
validate_email(email)
|
||||||
|
except ValidationError as e:
|
||||||
|
return HttpResponse("Invalid email.")
|
||||||
|
|
||||||
|
cid_users = CidUser.objects.filter(email=email)
|
||||||
|
|
||||||
|
for cid_user in cid_users:
|
||||||
|
cid_user.email_details(resend=True)
|
||||||
|
cid_user.email_details()
|
||||||
|
|
||||||
|
|
||||||
|
return HttpResponse("Candidate details will be sent to the requested email (if it is found in the system).")
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
|
||||||
<div class="main-nav-header">
|
<div class="main-nav-header">
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<span id="logout-link" class="top-bar-link">
|
<span id="logout-link" class="top-bar-link">
|
||||||
|
|||||||
@@ -4,10 +4,18 @@
|
|||||||
<div class="">
|
<div class="">
|
||||||
<h2>Exam / Results checker</h2>
|
<h2>Exam / Results checker</h2>
|
||||||
<p>Please enter your CID and passcode</p>
|
<p>Please enter your CID and passcode</p>
|
||||||
<p>CID: <input type="text" name="cid" id="cid-box"></p>
|
<p>CID: <input type="text" name="cid" id="cid-box" autofocus></p>
|
||||||
<p>Passcode: <input id="passcode-box" type="text" value="Passcode"></p>
|
<p>Passcode: <input id="passcode-box" type="text" value="Passcode"></p>
|
||||||
<button id="cid-selector-go-button">Go...</button>
|
<button id="cid-selector-go-button">Go...</button>
|
||||||
</div>
|
</div>
|
||||||
|
<details>
|
||||||
|
<summary>What is my CID?</summary>
|
||||||
|
If you do not have you CID details please the email you signed up with here.
|
||||||
|
<form>
|
||||||
|
<input type="text" name="email" id="email-box">
|
||||||
|
<button id="email-cid-details-button" hx-post="request_cid_details/" hx-swap="outerHTML">Email details</button>
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
window.location.search.substr(1).split("&").forEach((item) =>
|
window.location.search.substr(1).split("&").forEach((item) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user