Merge with Bryce commit
This commit is contained in:
commit
7686092293
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
from random import randint
|
||||||
|
|
||||||
class Translations(object):
|
class Translations(object):
|
||||||
|
|
||||||
@ -40,3 +40,27 @@ class Translations(object):
|
|||||||
def strip_accents(s):
|
def strip_accents(s):
|
||||||
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
|
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
|
||||||
#end def
|
#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
|
||||||
|
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from tg.decorators import expose
|
from tg.decorators import expose
|
||||||
from tg.controllers import redirect
|
from tg.controllers import redirect
|
||||||
|
|
||||||
from brie.config import ldap_config, groups_enum
|
from brie.config import ldap_config, groups_enum
|
||||||
from brie.lib.ldap_helper import *
|
from brie.lib.ldap_helper import *
|
||||||
from brie.lib.aurore_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 *
|
||||||
|
|
||||||
from brie.model.ldap import Wifi as WifiModel
|
from brie.model.ldap import Wifi as WifiModel
|
||||||
|
|
||||||
from brie.controllers import auth
|
from brie.controllers import auth
|
||||||
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
||||||
|
import smtplib
|
||||||
|
|
||||||
|
|
||||||
class Wifi:
|
class Wifi:
|
||||||
@ -50,7 +52,7 @@ class DirectController(AuthenticatedRestController):
|
|||||||
|
|
||||||
|
|
||||||
@expose("")
|
@expose("")
|
||||||
def post(self, residence, member_uid, password):
|
def post(self, residence, member_uid):
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
member = Member.get_by_uid(self.user, residence_dn, member_uid)
|
member = Member.get_by_uid(self.user, residence_dn, member_uid)
|
||||||
if member is None:
|
if member is None:
|
||||||
@ -58,6 +60,7 @@ class DirectController(AuthenticatedRestController):
|
|||||||
|
|
||||||
|
|
||||||
wifi = WifiModel.get_by_member_dn(self.user, member.dn)
|
wifi = WifiModel.get_by_member_dn(self.user, member.dn)
|
||||||
|
password = Passwords.generate_password_wifi()
|
||||||
|
|
||||||
if wifi is None:
|
if wifi is None:
|
||||||
wifi_dn = "cn=wifi," + member.dn
|
wifi_dn = "cn=wifi," + member.dn
|
||||||
@ -66,7 +69,26 @@ class DirectController(AuthenticatedRestController):
|
|||||||
else:
|
else:
|
||||||
wifi.userPassword.replace(wifi.userPassword.first(), password)
|
wifi.userPassword.replace(wifi.userPassword.first(), password)
|
||||||
self.user.ldap_bind.save(wifi)
|
self.user.ldap_bind.save(wifi)
|
||||||
#end
|
#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)
|
redirect("/show/member/" + residence + "/" + member_uid)
|
||||||
#end def
|
#end def
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
<input type="hidden" name="residence" value="${residence}" />
|
<input type="hidden" name="residence" value="${residence}" />
|
||||||
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
|
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
|
||||||
<span class="item_name">Nouveau mot de passe</span>
|
<span class="item_name">Nouveau mot de passe</span>
|
||||||
<input type="password" name="password" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="item_name"></span>
|
<span class="item_name"></span>
|
||||||
<input type="submit" value="ENREGISTRER" class="button"/>
|
<input type="submit" value="GENERATE PASSWORD" class="button"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<link href="/css/bootstrap.css" rel="stylesheet"/>
|
<link href="/css/bootstrap.css" rel="stylesheet"/>
|
||||||
<link href="/css/form-signin.css" rel="stylesheet"/>
|
<link href="/css/form-signin.css" rel="stylesheet"/>
|
||||||
<link href="/css/bootstrap-responsive.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 -->
|
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
|
Loading…
Reference in New Issue
Block a user