Esempio n. 1
0
    def create_account(self, username, password, meta={}):
        if self.account_exists(username):
            raise AuthError("Account Exists")

        dn = current_app.config['LDAP_NEW_USER_DN_TEMPLATE'].format(username)
        print meta
        meta = map_attrs(meta, reverse=True)
        print meta
        current_app.logger.debug("Trying to create user {} with metadata {}".format(
                username, meta))
        meta.update(parse_fullname(meta['displayName']))
        self.con.add_s(dn, 
                  eval(current_app.config['LDAP_NEW_USER_ATTR_TEMPLATE'].format(**meta)))
        
        # See if the account should get admin privs
        # plugins = []
        # for plugin in current_app.config['AUTHORIZATION_PLUGIN_ORDER']:
        #     plugins.append(eval(plugin)())
        # if any([plugin.is_superuser(username) for plugin in plugins]):
        #     self.promote_superuser(username)
        self.change_password(username, password)
        current_app.logger.info("Created user {} in {} backend".format(username, self))
        current_app.logger.debug("New {} metadata for user {}: {}".format(
                self, username, self.get_meta(username)))
        return True
Esempio n. 2
0
def user_as_meta(user):
    meta = {'username': user.username,
            'permission_level': user.permission_level,
            'email': user.email,
            'emerg': user.emerg,
            'name': user.name}
    meta.update(parse_fullname(user.username))
    return meta