Skip to content
Snippets Groups Projects
Commit 856631cd authored by Christian Dresen's avatar Christian Dresen
Browse files

[Security] Added password change notifications

parent 1150646e
No related branches found
No related tags found
No related merge requests found
from django.utils.translation import ugettext as _
from warpzone.util import send_email
pages = {'pages': [ pages = {'pages': [
{"link": "pizza", "name": "PizzaSheet"}, {"link": "pizza", "name": "PizzaSheet"},
{"link": "about", "name": "About"}, {"link": "about", "name": "About"},
]} ]}
def send_password_change_notification(user):
send_email(user.email, _("Your password was changed"),_("Password changed recently"))
...@@ -90,6 +90,7 @@ def change_password(request): ...@@ -90,6 +90,7 @@ def change_password(request):
if ret == -1: if ret == -1:
pages["error_passwd"] = "Old password did not match" pages["error_passwd"] = "Old password did not match"
else: else:
send_password_change_notification(request.user.ldap_user)
pages["success_passwd"] = True pages["success_passwd"] = True
pages['ldap_groups'] = request.user.ldap_user.group_names pages['ldap_groups'] = request.user.ldap_user.group_names
pages['ldap_user_form'] = LdapUserForm(instance=LdapUser.objects.get(uid=str(request.user))) pages['ldap_user_form'] = LdapUserForm(instance=LdapUser.objects.get(uid=str(request.user)))
......
...@@ -3,11 +3,13 @@ import hashlib ...@@ -3,11 +3,13 @@ import hashlib
import logging import logging
import datetime import datetime
from django.utils.translation import ugettext as _
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from warpauth.ldap_connector import LDAPConnector from warpauth.ldap_connector import LDAPConnector
from warpzone.utils import send_email from warpzone.util import send_email
from warpauth.util import * from warpauth.util import *
from warpauth.models import PasswordResetToken, LdapUser from warpauth.models import PasswordResetToken, LdapUser
...@@ -16,8 +18,6 @@ from warpzone.settings import PW_RESET_TOKEN_LIFETIME ...@@ -16,8 +18,6 @@ from warpzone.settings import PW_RESET_TOKEN_LIFETIME
# #
# Function to generate a password reset Token # Function to generate a password reset Token
# ToDo: Implement Email with Token
# ToDo: Remove Debug outputs
# #
def gen_token(request): def gen_token(request):
...@@ -32,7 +32,8 @@ def gen_token(request): ...@@ -32,7 +32,8 @@ def gen_token(request):
p.email = usr.email p.email = usr.email
p.hash = hashlib.sha1(os.urandom(128)).hexdigest() p.hash = hashlib.sha1(os.urandom(128)).hexdigest()
p.save() p.save()
ret = send_email(p.email, "Requested Password Reset", "http://localhost/reset_password/%s" % p.hash) email_content = _("https://infra.warpzone.ms/reset_password/%(hash)s") % {'hash': p.hash}
ret = send_email(p.email, "Requested Password Reset", email_content )
if not ret: if not ret:
pages["error"] = "Error while sending the email. Please contact the administrator." pages["error"] = "Error while sending the email. Please contact the administrator."
logger.info("Success for %s", usr.uid) logger.info("Success for %s", usr.uid)
...@@ -65,6 +66,7 @@ def change_password(request, reset_hash=None): ...@@ -65,6 +66,7 @@ def change_password(request, reset_hash=None):
ldap_connector = LDAPConnector() ldap_connector = LDAPConnector()
ldap_connector.change_user_password(user.build_dn(), None, request.POST["password"], True) ldap_connector.change_user_password(user.build_dn(), None, request.POST["password"], True)
pw_reset_token.delete() pw_reset_token.delete()
send_password_change_notification(user)
else: else:
pages["username"] = pw_reset_token.user pages["username"] = pw_reset_token.user
......
...@@ -14,4 +14,6 @@ def send_email(to_address, subject, content): ...@@ -14,4 +14,6 @@ def send_email(to_address, subject, content):
except Exception as e: except Exception as e:
print(e) print(e)
return False return False
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment