moulinette/lib/yunohost_user.py

39 lines
921 B
Python
Raw Normal View History

2012-10-06 17:10:19 +02:00
# -*- coding: utf-8 -*-
2012-10-07 17:57:57 +02:00
import sys
2012-10-06 17:57:08 +02:00
import ldap
import ldap.modlist as modlist
2012-10-07 16:20:20 +02:00
import yunohost_ldap
2012-10-07 17:57:57 +02:00
import yunohost_messages as msg
import getpass
2012-10-07 16:20:20 +02:00
# Initialize LDAP
yldap = yunohost_ldap.YunoHostLDAP()
2012-10-06 17:57:08 +02:00
2012-10-07 17:57:57 +02:00
def user_list(args): # TODO : fix
result = yldap.search()
2012-10-07 16:20:20 +02:00
print(result)
2012-10-07 17:57:57 +02:00
def user_add(args):
required_args = ['username', 'mail', 'firstname', 'lastname']
try:
for arg in required_args:
if not args[arg]:
args[arg] = raw_input(arg.capitalize()+': ')
if not args['password']:
args['password'] = getpass.getpass()
pwd2 = getpass.getpass('Retype password:')
if args['password'] != pwd2:
print(msg.error + _("Passwords doesn't match"))
sys.exit(1)
except KeyboardInterrupt, EOFError:
print("\n" + msg.interrupt + _("User not created"))
sys.exit(1)
print(args)