Пример #1
0
def login():
    global ldapConn
    global ldapHost
    global search_filter
    global base_dn

    if request.method == 'POST':
        #search ldap for the username
        if ldapConn == None:
            print ldapConn
            initLDAP()
        ldapuser = ldapwrap.getUser(ldapConn, base_dn, search_filter, request.form['user'])
        if ldapuser != None:
            #found the user, try binding with that dn and supplied password
            #TODO: should just be able to auth against the password attrib?

            tmpConn = ldapwrap.connect(ldapHost)
            if ldapwrap.bind(tmpConn, ldapuser['dn'], request.form['pass']):
                #succesfully bound, good password!
                tmpConn.unbind()
                #Create the flask-login user object and log the user in
                UserObj = User(ldapuser['cn'][0], ldapuser['uid'][0], active=True)
                login_user(UserObj)

                next = request.args.get('next', '')
                if next:
                    return redirect(next)
                else:
                    return redirect('/paste/')
            else:
                return 'Bad password'
        else:
            return 'User not found'
    return render_template('login.html')
Пример #2
0
def load_user(userid):
    #get from ldap!
    global ldapConn
    global search_filter
    global base_dn
    if ldapConn != None:
        initLDAP()
    ldapuser = ldapwrap.getUser(ldapConn, base_dn, search_filter, userid)
    if ldapuser != None:
        return User(ldapuser['cn'][0], ldapuser['uid'][0], active=True)
    else:
        return None