Flask ldap3登录问题

时间:2019-03-05 08:17:59

标签: python flask ldap ldap3

我正在使用带有Flask python的Ldap3。
尝试登录时出现错误:

  

TypeError:“属性”类型的对象不可JSON序列化

代码如下:

def ADlogin(username,password):
    server = ldap3.Server(server_uri, get_info=ldap3.ALL)
    connection = ldap3.Connection(server, user=username+base, password=password)
    if not connection.bind():
        return False
    else:
        connection.search(username+base, '(objectClass=*)', attributes=ldap3.ALL_ATTRIBUTES)
        session['username'] = username
        session['uid'] = connection.entries[0].uid
        connection.search('dc=example,dc=com', '(objectclass=posixGroup)',
                          attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES])
        for entry in connection.entries:
            if entry.cn == 'service':
                for user in entry.memberUid:
                    if user == session['uid']:
                        session['group_service'] = True
                        break
            elif entry.cn == 'management':
                for user in entry.memberUid:
                    if user == session['uid']:
                        session['group_management'] = True
                        break
        return True

和登录页面:

@app.route("/login", methods=['GET', 'POST'])
def login():
    if request.method == "POST" and request.form['submit'] == "Sign in":
        username = request.form['username']
        password = request.form['password']
        if utils.isEmpty(username) or utils.isEmpty(password):
            return render_template('login.html', status="Please Enter All Fields")

        else:
            status = ADConnect.ADlogin(username,password)
            if status:
                #return redirect(url_for('dashboard'))
                return "Success"
            else:
                return render_template('login.html', status=status)



    else:
        return render_template('login.html')

该代码在python控制台中运行正常,但是当我使用flask尝试运行时,它向我显示了该错误,我无法找到该问题的解决方案。

0 个答案:

没有答案