From f6ef88f0d988ddd7b51b1b5fe1f7cae90e473131 Mon Sep 17 00:00:00 2001 From: Romain Beuque Date: Sun, 31 Aug 2014 23:53:48 +0200 Subject: [PATCH] generate password pour le WiFi + changement lien CSS Bootstrap --- Brie/brie/lib/name_translation_helpers.py | 26 +++++++++++++++++++- Brie/brie/plugins/wifi/controller.py | 28 +++++++++++++++++++--- Brie/brie/plugins/wifi/edit.html | 3 +-- Brie/brie/templates/common-css-header.html | 2 +- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Brie/brie/lib/name_translation_helpers.py b/Brie/brie/lib/name_translation_helpers.py index 317db5d..3e01fb0 100644 --- a/Brie/brie/lib/name_translation_helpers.py +++ b/Brie/brie/lib/name_translation_helpers.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import unicodedata - +from random import randint class Translations(object): @@ -40,3 +40,27 @@ class Translations(object): def strip_accents(s): return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')) #end def + +class Passwords(object): + + @staticmethod + def generate_password_wifi(): + + password = "" + + for i in range(8): + nb_chosen = randint(0,35) + if nb_chosen > 25: + password = password + str(nb_chosen - 26) + else: + if randint(0,1) is 1: + password = password + chr(ord('A') + nb_chosen) + else: + password = password + chr(ord('a') + nb_chosen) + #end if + #end if + #end for + return password + #end def +#end class + diff --git a/Brie/brie/plugins/wifi/controller.py b/Brie/brie/plugins/wifi/controller.py index a7c0627..58cfb82 100644 --- a/Brie/brie/plugins/wifi/controller.py +++ b/Brie/brie/plugins/wifi/controller.py @@ -1,16 +1,18 @@ +# -*- coding: utf-8 -*- from tg.decorators import expose from tg.controllers import redirect from brie.config import ldap_config, groups_enum from brie.lib.ldap_helper import * from brie.lib.aurore_helper import * +from brie.lib.name_translation_helpers import Passwords from brie.model.ldap import * from brie.model.ldap import Wifi as WifiModel from brie.controllers import auth from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController - +import smtplib class Wifi: @@ -50,7 +52,7 @@ class DirectController(AuthenticatedRestController): @expose("") - def post(self, residence, member_uid, password): + def post(self, residence, member_uid): residence_dn = Residences.get_dn_by_name(self.user, residence) member = Member.get_by_uid(self.user, residence_dn, member_uid) if member is None: @@ -58,6 +60,7 @@ class DirectController(AuthenticatedRestController): wifi = WifiModel.get_by_member_dn(self.user, member.dn) + password = Passwords.generate_password_wifi() if wifi is None: wifi_dn = "cn=wifi," + member.dn @@ -66,7 +69,26 @@ class DirectController(AuthenticatedRestController): else: wifi.userPassword.replace(wifi.userPassword.first(), password) self.user.ldap_bind.save(wifi) - #end + #end + + sender = "noreply@fede-aurore.net" + receivers = [member.mail.first()] + + message = """From: Federation Aurore +To: """ + member.cn.first().decode("utf-8").encode("ascii", "ignore") + """ <""" + member.mail.first().decode("utf-8").encode("ascii", "ignore") + """> +Subject: Votre mot de passe WiFi : residence universitaire + + Bienvenue dans votre residence etudiante de Paris Sud + Votre mot de passe WiFi est : """ + password + + message = message.encode("utf-8") + + try: + smtpObj = smtplib.SMTP('smtp.u-psud.fr') + smtpObj.sendmail(sender, receivers, message) + print "Successfully sent email" + except SMTPException: + print "Error: unable to send email" redirect("/show/member/" + residence + "/" + member_uid) #end def diff --git a/Brie/brie/plugins/wifi/edit.html b/Brie/brie/plugins/wifi/edit.html index 8fee369..e40c5d7 100644 --- a/Brie/brie/plugins/wifi/edit.html +++ b/Brie/brie/plugins/wifi/edit.html @@ -19,12 +19,11 @@ Nouveau mot de passe -
- +
diff --git a/Brie/brie/templates/common-css-header.html b/Brie/brie/templates/common-css-header.html index ae928b8..b1df315 100644 --- a/Brie/brie/templates/common-css-header.html +++ b/Brie/brie/templates/common-css-header.html @@ -6,7 +6,7 @@ - +