Compare commits
2 Commits
32be1999e9
...
2b40104180
Author | SHA1 | Date |
---|---|---|
Cayo Puigdefabregas | 2b40104180 | |
Cayo Puigdefabregas | 1bf2c1558d |
|
@ -1,3 +1,4 @@
|
|||
from smtplib import SMTPException
|
||||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -9,6 +10,7 @@ from django.views.generic.edit import (
|
|||
)
|
||||
from dashboard.mixins import DashboardView, Http403
|
||||
from user.models import User, Institution
|
||||
from admin.email import NotifyActivateUserByEmail
|
||||
|
||||
|
||||
class AdminView(DashboardView):
|
||||
|
@ -42,7 +44,7 @@ class UsersView(AdminView, TemplateView):
|
|||
return context
|
||||
|
||||
|
||||
class CreateUserView(AdminView, CreateView):
|
||||
class CreateUserView(AdminView, NotifyActivateUserByEmail, CreateView):
|
||||
template_name = "user.html"
|
||||
title = _("User")
|
||||
breadcrumb = _("admin / User") + " /"
|
||||
|
@ -58,6 +60,12 @@ class CreateUserView(AdminView, CreateView):
|
|||
form.instance.institution = self.request.user.institution
|
||||
form.instance.set_password(form.instance.password)
|
||||
response = super().form_valid(form)
|
||||
|
||||
try:
|
||||
self.send_email(form.instance)
|
||||
except SMTPException as e:
|
||||
messages.error(self.request, e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
|
23
api/views.py
23
api/views.py
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -69,9 +70,29 @@ def NewSnapshot(request):
|
|||
except Exception:
|
||||
return JsonResponse({'status': 'fail'}, status=200)
|
||||
|
||||
return JsonResponse({'status': 'success'}, status=200)
|
||||
annotation = Annotation.objects.filter(
|
||||
uuid=data['uuid'],
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key="hidalgo1",
|
||||
owner=tk.owner.institution
|
||||
).first()
|
||||
|
||||
|
||||
if not annotation:
|
||||
return JsonResponse({'status': 'fail'}, status=200)
|
||||
|
||||
url = "{}://{}{}".format(
|
||||
request.scheme,
|
||||
settings.DOMAIN,
|
||||
reverse_lazy("device:details", args=(annotation.value,))
|
||||
)
|
||||
response = {
|
||||
"status": "success",
|
||||
"dhid": annotation.value[:5].upper(),
|
||||
"url": url,
|
||||
"public_url": url
|
||||
}
|
||||
return JsonResponse(response, status=200)
|
||||
|
||||
|
||||
class TokenView(DashboardView, SingleTableView):
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{% trans 'Documents' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{# url 'idhub:admin_people_activate' object.id #}" type="button" class="btn btn-green-admin">
|
||||
<a href="{# url 'dashboard:exports' object.id #}" type="button" class="btn btn-green-admin">
|
||||
<i class="bi bi-reply"></i>
|
||||
{% trans 'Exports' %}
|
||||
</a>
|
||||
|
|
|
@ -27,7 +27,7 @@ class Device:
|
|||
# the id is the chid of the device
|
||||
self.id = kwargs["id"]
|
||||
self.pk = self.id
|
||||
self.shortid = self.pk[:6]
|
||||
self.shortid = self.pk[:6].upper()
|
||||
self.algorithm = None
|
||||
self.owner = None
|
||||
self.annotations = []
|
||||
|
|
|
@ -39,6 +39,30 @@ assert DOMAIN in ALLOWED_HOSTS, "DOMAIN is not ALLOWED_HOST"
|
|||
|
||||
CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default=f'https://{DOMAIN}', cast=Csv())
|
||||
|
||||
|
||||
INITIAL_ADMIN_EMAIL = config("INITIAL_ADMIN_EMAIL", default='admin@example.org')
|
||||
INITIAL_ADMIN_PASSWORD = config("INITIAL_ADMIN_PASSWORD", default='1234')
|
||||
|
||||
DEFAULT_FROM_EMAIL = config(
|
||||
'DEFAULT_FROM_EMAIL', default='webmaster@localhost')
|
||||
|
||||
EMAIL_HOST = config('EMAIL_HOST', default='localhost')
|
||||
|
||||
EMAIL_HOST_USER = config('EMAIL_HOST_USER', default='')
|
||||
|
||||
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD', default='')
|
||||
|
||||
EMAIL_PORT = config('EMAIL_PORT', default=25, cast=int)
|
||||
|
||||
EMAIL_USE_TLS = config('EMAIL_USE_TLS', default=False, cast=bool)
|
||||
|
||||
EMAIL_BACKEND = config('EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
|
||||
|
||||
EMAIL_FILE_PATH = config('EMAIL_FILE_PATH', default='/tmp/app-messages')
|
||||
|
||||
ENABLE_EMAIL = config("ENABLE_EMAIL", default=True, cast=bool)
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
{% load i18n %}{% autoescape off %}
|
||||
{% trans "DeviceHub" as site %}
|
||||
<p>
|
||||
{% blocktrans %}You're receiving this email because your user account at {{site}} has been activated.{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% trans "Your username is:" %} {{ user.username }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% trans "Please go to the following page and choose a password:" %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% block reset_link %}
|
||||
<a href="{{ protocol }}://{{ domain }}{% url 'login:password_reset_confirm' uidb64=uid token=token %}">
|
||||
{{ protocol }}://{{ domain }}{% url 'login:password_reset_confirm' uidb64=uid token=token %}
|
||||
</a>
|
||||
{% endblock %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% trans "Thanks for using our site!" %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{% blocktrans %}The {{site}} team{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
{% endautoescape %}
|
|
@ -0,0 +1,19 @@
|
|||
{% load i18n %}{% autoescape off %}
|
||||
|
||||
{% trans "DeviceHub" as site %}
|
||||
|
||||
{% blocktrans %}You're receiving this email because your user account at {{site}} has been activated.{% endblocktrans %}
|
||||
|
||||
{% trans "Your username is:" %} {{ user.username }}
|
||||
|
||||
{% trans "Please go to the following page and choose a password:" %}
|
||||
{% block reset_link %}
|
||||
{{ protocol }}://{{ domain }}{% url 'login:password_reset_confirm' uidb64=uid token=token %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% trans "Thanks for using our site!" %}
|
||||
|
||||
{% blocktrans %}The {{site}} team{% endblocktrans %}
|
||||
|
||||
{% endautoescape %}
|
|
@ -0,0 +1,4 @@
|
|||
{% load i18n %}{% autoescape off %}
|
||||
{% trans "IdHub" as site %}
|
||||
{% blocktrans %}User activation on {{site}}{% endblocktrans %}
|
||||
{% endautoescape %}
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
<p>
|
||||
{% block reset_link %}
|
||||
<a href="{{ protocol }}://{{ domain }}{% url 'idhub:password_reset_confirm' uidb64=uid token=token %}">
|
||||
{{ protocol }}://{{ domain }}{% url 'idhub:password_reset_confirm' uidb64=uid token=token %}
|
||||
<a href="{{ protocol }}://{{ domain }}{% url 'login:password_reset_confirm' uidb64=uid token=token %}">
|
||||
{{ protocol }}://{{ domain }}{% url 'login:password_reset_confirm' uidb64=uid token=token %}
|
||||
</a>
|
||||
{% endblock %}
|
||||
</p>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{% trans "Please go to the following page and choose a new password:" %}
|
||||
{% block reset_link %}
|
||||
{{ protocol }}://{{ domain }}{% url 'idhub:password_reset_confirm' uidb64=uid token=token %}
|
||||
{{ protocol }}://{{ domain }}{% url 'login:password_reset_confirm' uidb64=uid token=token %}
|
||||
{% endblock %}
|
||||
{% trans "Your username, in case you've forgotten:" %} {{ user.username }}
|
||||
|
||||
|
|
|
@ -65,8 +65,10 @@ class PasswordResetView(auth_views.PasswordResetView):
|
|||
success_url = reverse_lazy('login:password_reset_done')
|
||||
|
||||
def form_valid(self, form):
|
||||
import pdb; pdb.set_trace()
|
||||
try:
|
||||
return super().form_valid(form)
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
except Exception as err:
|
||||
logger.error(err)
|
||||
return HttpResponseRedirect(self.success_url)
|
||||
|
|
Loading…
Reference in New Issue