aboutsummaryrefslogtreecommitdiff
path: root/newspipe
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2023-06-27 23:07:01 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2023-06-27 23:07:01 +0200
commit7a2cd5baed73e1634b83ce8d627ef275c993df7a (patch)
treeb3f27d46f4b01cab3f2444e695408041e965ac74 /newspipe
parent[PATCH] ldap-auth (diff)
downloadnewspipe-7a2cd5baed73e1634b83ce8d627ef275c993df7a.tar.gz
newspipe-7a2cd5baed73e1634b83ce8d627ef275c993df7a.tar.bz2
newspipe-7a2cd5baed73e1634b83ce8d627ef275c993df7a.zip
chg: [flake8] Adresses some flake8 warnings.
Diffstat (limited to 'newspipe')
-rw-r--r--newspipe/controllers/__init__.py1
-rw-r--r--newspipe/controllers/user.py17
-rw-r--r--newspipe/web/forms.py5
-rw-r--r--newspipe/web/views/user.py1
4 files changed, 15 insertions, 9 deletions
diff --git a/newspipe/controllers/__init__.py b/newspipe/controllers/__init__.py
index 449d93e9..ffe066b9 100644
--- a/newspipe/controllers/__init__.py
+++ b/newspipe/controllers/__init__.py
@@ -12,6 +12,7 @@ __all__ = [
"CategoryController",
"ArticleController",
"UserController",
+ "LdapuserController",
"IconController",
"BookmarkController",
"BookmarkTagController",
diff --git a/newspipe/controllers/user.py b/newspipe/controllers/user.py
index e259940e..2aaded64 100644
--- a/newspipe/controllers/user.py
+++ b/newspipe/controllers/user.py
@@ -1,18 +1,20 @@
import logging
from urllib.parse import urlparse
+import ldap3
+from ldap3.core.exceptions import LDAPBindError
from werkzeug.security import check_password_hash
from werkzeug.security import generate_password_hash
from .abstract import AbstractController
from newspipe.models import User
-logger = logging.getLogger(__name__)
+# from ldap3.core.exceptions import LDAPPasswordIsMandatoryError
# FOR LDAP
# Reference: session_app
-import ldap3
-from ldap3.core.exceptions import LDAPBindError, LDAPPasswordIsMandatoryError
+
+logger = logging.getLogger(__name__)
class UserController(AbstractController):
@@ -53,7 +55,8 @@ class LdapuserController:
# list_matching_users always returns list, so if it contains <> 1 we are in trouble
if len(this_user) != 1:
print(
- f"WARNING: cannot determine unique user for {config['LDAP_USER_MATCH_ATTRIB']}={user} which returned {this_user}"
+ f"WARNING: cannot determine unique user for"
+ f" {config['LDAP_USER_MATCH_ATTRIB']}={user} which returned {this_user}"
)
return False
# logger does not work here+flask for some reason. Very sad!
@@ -128,14 +131,16 @@ class LdapuserController:
try:
import dns
import dns.resolver
- except:
+ except Exception:
print("Need python3-dns or dnspython installed for dns lookups.")
return [domain]
namelist = []
try:
query = dns.resolver.query(f"_ldap._tcp.{domain}", "SRV")
except dns.resolver.NXDOMAIN:
- # no records exist that match the request, so we were probably given a specific hostname, and an empty query will trigger the logic below that will add the original domain to the list.
+ # no records exist that match the request, so we were probably
+ # given a specific hostname, and an empty query will trigger
+ # the logic below that will add the original domain to the list.
query = []
for i in query:
namelist.append(i.target.to_text().rstrip("."))
diff --git a/newspipe/web/forms.py b/newspipe/web/forms.py
index dba2e1b8..3eac8e6b 100644
--- a/newspipe/web/forms.py
+++ b/newspipe/web/forms.py
@@ -185,7 +185,7 @@ class SigninForm(RedirectForm):
if user:
validated = True
self.user = user
- except:
+ except Exception:
self.nickmane.errors.append(
f"Unable to provision user for valid ldap user {self.nickmane.data}"
)
@@ -200,7 +200,8 @@ class SigninForm(RedirectForm):
# must short-circuit the password check for ldap users
if not ldapuser:
try:
- # with an external_auth user but external auth disabled in config now, the empty password on the user in the database will fail
+ # with an external_auth user but external auth disabled in config now,
+ # the empty password on the user in the database will fail
if not ucontr.check_password(user, self.password.data):
self.password.errors.append("Wrong password")
validated = False
diff --git a/newspipe/web/views/user.py b/newspipe/web/views/user.py
index 1945be89..00615ba8 100644
--- a/newspipe/web/views/user.py
+++ b/newspipe/web/views/user.py
@@ -9,7 +9,6 @@ from flask_login import current_user
from flask_login import login_required
from flask_paginate import get_page_args
from flask_paginate import Pagination
-from werkzeug.exceptions import BadRequest
from newspipe.bootstrap import application
from newspipe.controllers import ArticleController
bgstack15