Пример #1
0
    def update(self, account):
        update_items = (
            'cn', 'uidNumber', 'mail',
            'loginShell', 'title', 'manager',
            'departmentNumber', 'roomNumber',
            'deploycode', 'orgchartmanager', 'utilityaccount')

        dh = DirectoryHelper(
            directoryCN, directoryPassword, directoryDomain)

        updates = {}
        groups = [v for k,v in request.params.items() if k == 'group']
        for item in update_items:
            if item in request.params:
                if item == 'cn':
                    updates['cn'] = request.params[item]
                    updates['gecos'] = request.params[item]
                    splitname = request.params[item].split()
                    updates['givenName'] = splitname[0]
                    if len(splitname) > 1:
                        updates['sn'] = splitname[1]
                updates[item] = request.params[item]

        # for key in updates, update ldap and ad
        for k, v in updates.iteritems():
            dh.update_attribute(account, k, v)
        # for group in groups, update ldap groups
        dh.set_groups(account, groups)

        session['flash'] = 'Successfully updated %s' % account
        session.save()

        updates['account'] = account
        ae = ActivityEngine(Session, session['active_user']['user_id'])
        ae.update('user', None, updates)

        return redirect(url(controller='users', action='edit', account=account))
Пример #2
0
    def create(self):
        hash_params = ('username', 'name', 'mail',
                       'loginShell', 'title', 'manager',
                       'departmentNumber', 'roomNumber',
                       'orgchartmanager', 'utilityaccount', 'deploycode')
        dh = DirectoryHelper(
                directoryCN, directoryPassword, directoryDomain)

        data_map = {}
        groups = []
        for k,v in request.params.items():
            if k in hash_params:
                data_map[k] = v
            elif k == 'group':
                groups.append(v)

        data_map['username'] = data_map['username'].lower()

        dh.ldap.create(data_map['username'], data_map['name'],
                       data_map['mail'], data_map['loginShell'],
                       data_map['title'], data_map['manager'],
                       data_map['departmentNumber'], data_map['roomNumber'],
                       data_map['deploycode'], data_map['orgchartmanager'],
                       data_map['utilityaccount'] )

        dh.set_groups(data_map['username'], groups)

        session['flash'] = 'Successfully created %s' % data_map['username']
        session.save()

        data_map['account'] = data_map['username']
        ae = ActivityEngine(Session, session['active_user']['user_id'])
        ae.create('user', data_map)

        return redirect(url(
                controller='users', action='edit',
                account=data_map['username']))