diff --git a/dal/templates/landing.html b/dal/templates/landing.html
index 741fd74..71c4b75 100644
--- a/dal/templates/landing.html
+++ b/dal/templates/landing.html
@@ -1,6 +1,10 @@
{% extends "base_short.html" %}
{% load i18n staticfiles bootstrap3 %}
+{% block title %}
+
@@ -17,7 +21,7 @@
{% endfor %}
{{form.non_field_errors|striptags}}
-
diff --git a/dal/templates/loginfailed.html b/dal/templates/loginfailed.html
index 9dcf74f..59d829c 100644
--- a/dal/templates/loginfailed.html
+++ b/dal/templates/loginfailed.html
@@ -1,11 +1,29 @@
-
Login failed!
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
Sorry, but your login has failed
-
This service runs for our LDAP users, so maybe you don't already have an LDAP account with us? If so, please register one.
-
-
-
+{% block title %}
+
Login failed!
+{% endblock %}
+
+
+{% block content %}
+
+
+
+
+
+
{% trans " Sorry, but your login has failed. " %}
+
+
+
+
+
+
+
+{% endblock %}
diff --git a/dal/templates/mustbeloggedin.html b/dal/templates/mustbeloggedin.html
index d70cd21..7b69aee 100644
--- a/dal/templates/mustbeloggedin.html
+++ b/dal/templates/mustbeloggedin.html
@@ -1,7 +1,29 @@
-
You must be logged in to access this page
-
You must be logged in to access this page
-
-
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
+
+{% block title %}
+
You must be logged in to access this page
+{% endblock %}
+
+
+
+{% block content %}
+
+
+
+
+
+
{% trans " You need to login to access " %}
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/dal/templates/registeruser.html b/dal/templates/registeruser.html
index db923b4..3743d9e 100644
--- a/dal/templates/registeruser.html
+++ b/dal/templates/registeruser.html
@@ -1,27 +1,60 @@
-
Register an user at ungleich
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
Register an user at ungleich
-
-
-
-To register yourself an user, please fill out the fields below:
-
-
+{% block title %}
+
Register an user at ungleich
+{% endblock %}
+
+{% block content %}
+
+
+
+
+
+
{% trans "Sign Up" %}
+ {% include 'includes/_messages.html' %}
+
+
+
+
+
+
+{% endblock %}
diff --git a/dal/templates/resetpassword.html b/dal/templates/resetpassword.html
index e55e4e8..3d32001 100644
--- a/dal/templates/resetpassword.html
+++ b/dal/templates/resetpassword.html
@@ -1,13 +1,34 @@
-
Password reset
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
Password reset
-
-To reset your password, please enter your username below. You will get an email with a link to change your password.
-
-
+{% block title %}
+
Password reset
+{% endblock %}
+
+
+
+{% block content %}
+
+
+
+
+
+
{% trans " Password Reset " %}
+
{% trans "Please enter your username below. You will get an email with a link to change your password." %}
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/dal/templates/resetpasswordnew.html b/dal/templates/resetpasswordnew.html
index 133c94f..adf1d0b 100644
--- a/dal/templates/resetpasswordnew.html
+++ b/dal/templates/resetpasswordnew.html
@@ -1,14 +1,66 @@
-
Set new password for {{user}}
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
Please set new password for {{user}}
-
-
+{% block title %}
+
Set new password for {{user}}
+{% endblock %}
+
+
+{% block content %}
+
+
+
+
+
+
{% trans "Please set new password for {{user}} " %}
+ {% include 'includes/_messages.html' %}
+
+
+
+
+
+{% endblock %}
+
+
+
+
+
+
+
+
+
+{##}
+{##}
+{##}
+{#
#}
+{##}
+{#
#}
+{#
#}
+{#
#}
diff --git a/dal/templates/send_resetrequest.html b/dal/templates/send_resetrequest.html
index 1a54e99..e88d443 100644
--- a/dal/templates/send_resetrequest.html
+++ b/dal/templates/send_resetrequest.html
@@ -1,10 +1,29 @@
-
Reset request processed and confirmation email sent
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
Reset request processed and confirmation email sent
-
-You will shortly get the confirmation email to confirm that you wish to reset the password for {{user}}.
-Please follow the link in the email to reset your password.
-
-
+{% block title %}
+
Reset request processed and confirmation email sent
+{% endblock %}
+
+
+
+{% block content %}
+
+
+
+
+
+
{% trans " Reset request processed " %}
+
{% trans "You will shortly get the confirmation email. Please follow the instructions sent to reset your password." %}
+
+
+
+
+
+{% endblock %}
diff --git a/dal/templates/usercreated.html b/dal/templates/usercreated.html
index a428109..2fdcd40 100644
--- a/dal/templates/usercreated.html
+++ b/dal/templates/usercreated.html
@@ -1,7 +1,29 @@
-
User {{ user }} created.
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
User {{ user }} was successfully created.
-
-
+{% block title %}
+
User {{ user }} created.
+{% endblock %}
+
+
+
+{% block content %}
+
+
+
+
+
+
{% trans " Success " %}
+
{% trans "User was successfully created." %}
+
+
+
+
+
+{% endblock %}
diff --git a/dal/templates/useroptions.html b/dal/templates/useroptions.html
index 085fbe3..1e9c568 100644
--- a/dal/templates/useroptions.html
+++ b/dal/templates/useroptions.html
@@ -1,24 +1,30 @@
-
Options for {{user}}
+{% extends "base_short.html" %}
+{% load i18n staticfiles bootstrap3 %}
-
Welcome, {{user}}
-
-You have the following options:
-
-
-
-
-
-
-
-
-
+{% block title %}
+
Options for {{user}}
+{% endblock %}
+
+
+{% block content %}
+
+
+
+
+
+
{% trans "Welcome," %} {{user}}
+
+
+
+
+
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/dal/urls.py b/dal/urls.py
index b5f4a3a..1dab47a 100644
--- a/dal/urls.py
+++ b/dal/urls.py
@@ -4,10 +4,21 @@ from django.conf.urls import url
from django.contrib import admin
# Import the classes for the views
-from .views import Register, ChangeData, ChangePassword, ResetPassword, DeleteAccount, Index, LogOut, ResetRequest
+from .views import (
+ Register,
+ ChangeData,
+ ChangePassword,
+ ResetPassword,
+ DeleteAccount,
+ Index,
+ LogOut,
+ ResetRequest,
+ UserCreateAPI
+)
urlpatterns = [
path('register/', Register.as_view(), name="register"),
+ path('create/', UserCreateAPI.as_view(), name="create"),
path('changedata/', ChangeData.as_view(), name="change_data"),
path('resetpassword/', ResetPassword.as_view(), name="reset_password"),
path('changepassword/', ChangePassword.as_view(), name="change_password"),
diff --git a/dal/views.py b/dal/views.py
index 5d643d2..893997b 100644
--- a/dal/views.py
+++ b/dal/views.py
@@ -2,12 +2,15 @@
from django.shortcuts import render
from django.views.generic import View, FormView
from django.contrib.auth import authenticate, login, logout
+from django.contrib.auth.models import User
from django.http import HttpResponse
from django.core.validators import validate_email, ValidationError
from django.urls import reverse_lazy
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.core.mail import EmailMessage
from django.views.decorators.cache import cache_control
+from rest_framework.views import APIView
+from rest_framework.response import Response
from .models import ResetToken
from .forms import LoginForm
from .ungleich_ldap import LdapManager
@@ -93,7 +96,25 @@ class Register(View):
return render(request, 'error.html', { 'urlname': urlname,
'service': service,
'error': e } )
-
+ # Finally, we send the send user credentials via email
+ creationtime = int(datetime.utcnow().timestamp())
+ # Construct the data for the email
+ email_from = settings.EMAIL_FROM_ADDRESS
+ to = ['%s <%s>' % (username, email)]
+ subject = '{}, Welcome to datacenterlight'.format(firstname)
+ body = 'The username {} was successfully created.\n'.format(username)
+ # Build the email
+ mail = EmailMessage(
+ subject=subject,
+ body=body,
+ from_email=email_from,
+ to=to
+ )
+ try:
+ mail.send()
+ except Exception as e:
+ print(e)
+ pass
return render(request, 'usercreated.html', { 'user': username } )
class ChangeData(LoginRequiredMixin, View):
@@ -459,3 +480,57 @@ class PseudoUser():
# random alphanumeric strings for primary key and password, just used for token generation
pk = ''.join(choice(string.ascii_letters + string.digits) for _ in range(20))
password = ''.join(choice(string.ascii_letters + string.digits) for _ in range(30))
+
+class UserCreateAPI(APIView):
+
+ def post(self, request):
+ print(request.data)
+ print(request.POST)
+
+ username = request.POST.get('username')
+ email = request.POST.get('email')
+ firstname = request.POST.get('firstname')
+ lastname = request.POST.get('lastname')
+
+ if username == "" or not username:
+ return Response('Please supply a username.', 400)
+ try:
+ validate_email(email)
+ except ValidationError:
+ return Response('Email is not valid.', 400)
+ if not firstname or not lastname:
+ return Response('Please provide firstname and lastname', 400)
+
+ pwd = r'%s' % User.objects.make_random_password()
+
+ try:
+ ldap_manager = LdapManager()
+ ldap_manager.create_user(
+ username, pwd, firstname, lastname, email
+ )
+ except Exception as e:
+ return Response('While trying to create the user, an error was encountered: %s' % e, 400)
+
+ # send user credentials via email
+ creationtime = int(datetime.utcnow().timestamp())
+ # Construct the data for the email
+ email_from = settings.EMAIL_FROM_ADDRESS
+ to = ['%s <%s>' % (username, email)]
+ subject = 'Your datacenterlight credentials'
+ body = 'Your user was successfully created.\n'
+ body += 'Your credentials are:\n'
+ body += 'Username: %s\n\n' % username
+ body += 'Password: %s\n\n' % pwd
+ body += 'We strongly recommend you to after log in change your password.\n'
+ # Build the email
+ mail = EmailMessage(
+ subject=subject,
+ body=body,
+ from_email=email_from,
+ to=to
+ )
+ try:
+ mail.send()
+ except:
+ return Response('User was created, but failed to send the email', 201)
+ return Response('User successfully created', 200)
diff --git a/requirements.txt b/requirements.txt
index c68b636..ba3e644 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,3 +5,4 @@ django-bootstrap3
django-filter==2.1.0
python-decouple
ldap3
+djangorestframework
\ No newline at end of file