dump_creds reset les mdp

This commit is contained in:
Daniel STAN 2014-09-20 15:15:16 +02:00
parent 8a5822d4df
commit 6173bc8e89
3 changed files with 55 additions and 25 deletions

27
client.py Executable file → Normal file
View file

@ -5,6 +5,10 @@ from __future__ import print_function
from gestion import secrets_new as secrets
import pika
import json
import random
import datetime
import string
from lc_ldap import crans_utils
CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
@ -14,6 +18,13 @@ rabbit_c = pika.BlockingConnection(PARAMS)
ch = rabbit_c.channel()
ch.queue_declare('CransTicket')
def gen_password():
"""Génère un mot de passe aléatoire"""
random.seed(datetime.datetime.now().microsecond)
chars = string.letters + string.digits + '/=+*'
length = 10
return ''.join([random.choice(chars) for _ in xrange(length)])
class Ticket(object):
data = []
@ -35,7 +46,21 @@ class Ticket(object):
todo['type'] = 'wifi'
self.add_entry(todo)
def reset_password(self, adh):
login = adh['uid'][0].value
try:
value = gen_password()
adh['userPassword'] = [crans_utils.hash_password(value).decode('ascii')]
except EnvironmentError:
print("Impossible de changer le mot de passe de %s" % login)
exit(2)
self.add_account(login, value)
def print(self):
ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(self.data))
if not self.data:
print("Nothing to print !")
return
ch.basic_publish(exchange='', routing_key='CransTicket',
body=json.dumps(self.data))
print("Un nouveau ticket est en cours d'impression ...")