Merge with Bryce commit

This commit is contained in:
Romain Beuque 2014-08-31 23:54:33 +02:00
commit 7686092293
4 changed files with 52 additions and 7 deletions

View File

@ -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

View File

@ -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
@ -68,6 +71,25 @@ class DirectController(AuthenticatedRestController):
self.user.ldap_bind.save(wifi)
#end
sender = "noreply@fede-aurore.net"
receivers = [member.mail.first()]
message = """From: Federation Aurore <noreply@fede-aurore.net>
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
#end class

View File

@ -19,12 +19,11 @@
<input type="hidden" name="residence" value="${residence}" />
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
<span class="item_name">Nouveau mot de passe</span>
<input type="password" name="password" />
</div>
</div>
<div>
<span class="item_name"></span>
<input type="submit" value="ENREGISTRER" class="button"/>
<input type="submit" value="GENERATE PASSWORD" class="button"/>
</div>
</form>
</div>

View File

@ -6,7 +6,7 @@
<link href="/css/bootstrap.css" rel="stylesheet"/>
<link href="/css/form-signin.css" rel="stylesheet"/>
<link href="/css/bootstrap-responsive.css" rel="stylesheet" />
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet" />
<link href="/css/font-awesome.css" rel="stylesheet" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>