1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-26 01:50:31 +00:00

Moving import LDAP

Correct optional-requirements-ldap.txt spelling
This commit is contained in:
Krakinou 2019-01-13 11:02:03 +01:00
parent 82e4f11334
commit 7ccc40cf5b
3 changed files with 3 additions and 2 deletions

View File

@ -14,7 +14,6 @@ import json
import datetime import datetime
from binascii import hexlify from binascii import hexlify
import cli import cli
import ldap
engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False) engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False)
Base = declarative_base() Base = declarative_base()
@ -802,6 +801,7 @@ else:
#get LDAP connection #get LDAP connection
def get_ldap_connection(): def get_ldap_connection():
import ldap
conn = ldap.initialize('ldap://{}'.format(config.config_ldap_provider_url)) conn = ldap.initialize('ldap://{}'.format(config.config_ldap_provider_url))
return conn return conn

View File

@ -57,7 +57,6 @@ from redirect import redirect_back
import time import time
import server import server
from reverseproxy import ReverseProxied from reverseproxy import ReverseProxied
import ldap
try: try:
from googleapiclient.errors import HttpError from googleapiclient.errors import HttpError
@ -2344,6 +2343,7 @@ def login():
form = request.form.to_dict() form = request.form.to_dict()
user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()).first() user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == form['username'].strip().lower()).first()
if config.config_use_ldap and user: if config.config_use_ldap and user:
import ldap
try: try:
ub.User.try_login(form['username'], form['password']) ub.User.try_login(form['username'], form['password'])
login_user(user, remember=True) login_user(user, remember=True)
@ -2352,6 +2352,7 @@ def login():
except ldap.INVALID_CREDENTIALS: except ldap.INVALID_CREDENTIALS:
ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr) ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr)
app.logger.info('LDAP Login failed for user "' + form['username'] + '" IP-adress: ' + ipAdress) app.logger.info('LDAP Login failed for user "' + form['username'] + '" IP-adress: ' + ipAdress)
flash(_(u"Wrong Username or Password"), category="error")
elif user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest" and not user.is_authenticated: elif user and check_password_hash(user.password, form['password']) and user.nickname is not "Guest" and not user.is_authenticated:
login_user(user, remember=True) login_user(user, remember=True)
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success")