コード例 #1
0
ファイル: auth.py プロジェクト: alexkn/LXC-Web-Panel
def login():
    if request.method == 'POST':
        request_username = request.form['username']
        request_passwd = request.form['password']

        current_url = request.form['url']

        if AUTH == 'ldap':
            try:
                l = ldap.initialize('ldap://%s:%d' % (LDAP_HOST, LDAP_PORT))
                l.set_option(ldap.OPT_REFERRALS, 0)
                l.protocol_version = 3
                l.simple_bind(LDAP_BIND_DN, LDAP_PASS)
                q = l.search_s(LDAP_BASE, ldap.SCOPE_SUBTREE, '(&(objectClass=' + OBJECT_CLASS + ')(' + ID_MAPPING + '=' + request_username + '))', [])[0]
                l.bind_s(q[0], request_passwd, ldap.AUTH_SIMPLE)
                #set the parameters for user by ldap objectClass
                user = {
                    'username': q[1][ID_MAPPING][0].decode('utf8'),
                    'name': q[1][DISPLAY_MAPPING][0].decode('utf8'),
                    'su': 'Yes'
                }
            except Exception, e:
                print(str(e))
                user = None
        elif AUTH == 'htpasswd':
            from lwp.utils import check_htpasswd
            user = None
            if check_htpasswd(HTPASSWD_FILE, request_username, request_passwd):
                user = {
                    'username': request_username,
                    'name': request_username,
                    'su': 'Yes'
                }
        elif AUTH == 'pam':
            user = None
            p = pam.pam()
            if p.authenticate(request_username, request_passwd, service=PAM_SERVICE):
                user = {
                    'username': request_username,
                    'name': request_username,
                    'su': 'Yes'
                }
        else:
            request_passwd = hash_passwd(request_passwd)
            user = query_db('select name, username, su from users where username=? and password=?', [request_username, request_passwd], one=True)

        if user:
            session['logged_in'] = True
            session['token'] = get_token()
            session['last_activity'] = int(time.time())
            session['username'] = user['username']
            session['name'] = user['name']
            session['su'] = user['su']
            flash(u'You are logged in!', 'success')

            if current_url == url_for('auth.login'):
                return redirect(url_for('main.home'))
            return redirect(current_url)

        flash(u'Invalid username or password!', 'error')
コード例 #2
0
def login():
    if request.method == 'POST':
        request_username = request.form['username']
        request_passwd = request.form['password']

        current_url = request.form['url']

        if AUTH == 'ldap':
            try:
                l = ldap.initialize('ldap://%s:%d' % (LDAP_HOST, LDAP_PORT))
                l.set_option(ldap.OPT_REFERRALS, 0)
                l.protocol_version = 3
                l.simple_bind(LDAP_BIND_DN, LDAP_PASS)
                q = l.search_s(LDAP_BASE, ldap.SCOPE_SUBTREE, '(&(objectClass=' + OBJECT_CLASS + ')(' + ID_MAPPING + '=' + request_username + '))', [])[0]
                l.bind_s(q[0], request_passwd, ldap.AUTH_SIMPLE)
                #set the parameters for user by ldap objectClass
                user = {
                    'username': q[1][ID_MAPPING][0].decode('utf8'),
                    'name': q[1][DISPLAY_MAPPING][0].decode('utf8'),
                    'su': 'Yes'
                }
            except Exception, e:
                print(str(e))
                user = None
        elif AUTH == 'htpasswd':
            from lwp.utils import check_htpasswd
            user = None
            if check_htpasswd(HTPASSWD_FILE, request_username, request_passwd):
                user = {
                    'username': request_username,
                    'name': request_username,
                    'su': 'Yes'
                }
        else:
            request_passwd = hash_passwd(request_passwd)
            user = query_db('select name, username, su from users where username=? and password=?', [request_username, request_passwd], one=True)

        if user:
            session['logged_in'] = True
            session['token'] = get_token()
            session['last_activity'] = int(time.time())
            session['username'] = user['username']
            session['name'] = user['name']
            session['su'] = user['su']
            flash(u'You are logged in!', 'success')

            if current_url == url_for('auth.login'):
                return redirect(url_for('main.home'))
            return redirect(current_url)

        flash(u'Invalid username or password!', 'error')
コード例 #3
0
ファイル: auth.py プロジェクト: 62William/LXC-Web-Panel
def login():
    if request.method == 'POST':
        request_username = request.form['username']
        request_passwd = request.form['password']

        current_url = request.form['url']

        user = AUTH_INSTANCE.authenticate(request_username, request_passwd)

        if user:
            session['logged_in'] = True
            session['token'] = get_token()
            session['last_activity'] = int(time.time())
            session['username'] = user['username']
            session['name'] = user['name']
            session['su'] = user['su']
            flash(u'You are logged in!', 'success')

            if current_url == url_for('auth.login'):
                return redirect(url_for('main.home'))
            return redirect(current_url)

        flash(u'Invalid username or password!', 'error')
    return render_template('login.html', auth=AUTH)
コード例 #4
0
def login():
    if request.method == 'POST':
        request_username = request.form['username']
        request_passwd = request.form['password']

        current_url = request.form['url']

        user = AUTH_INSTANCE.authenticate(request_username, request_passwd)

        if user:
            session['logged_in'] = True
            session['token'] = get_token()
            session['last_activity'] = int(time.time())
            session['username'] = user.username
            session['name'] = user.name
            session['su'] = user.su
            flash(u'You are logged in!', 'success')

            if current_url == url_for('auth.login'):
                return redirect(url_for('main.home'))
            return redirect(current_url)

        flash(u'Invalid username or password!', 'error')
    return render_template('login.html', auth=AUTH)