cco.member: Python3 fixes

This commit is contained in:
Helmut Merz 2024-09-30 11:00:12 +02:00
parent c9d4f525e9
commit ee29ae7f9e
5 changed files with 24 additions and 60 deletions

View file

@ -1,6 +1,6 @@
# Introduction # Introduction
This is the main part of the code of the semantic This project contains extension packages for the
web application platform *loops*, based on web application platform *loops*, based on
Zope 3 / bluebream. Zope 3 / bluebream.

View file

@ -1,35 +1,17 @@
# # cco.member.auth
# Copyright (c) 2023 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Specialized authentication components.
Specialized authentication components.
""" """
import hashlib import hashlib
import logging import logging
import random import random
from datetime import datetime, timedelta from datetime import datetime, timedelta
from email.MIMEText import MIMEText from email.mime.text import MIMEText
from urllib import urlencode from urllib.parse import urlencode
import requests import requests
from zope.app.component import hooks from zope.component import hooks
from zope.interface import Interface, implements
from zope import component from zope import component
from zope.pluggableauth.interfaces import IAuthenticatedPrincipalFactory from zope.pluggableauth.interfaces import IAuthenticatedPrincipalFactory
from zope.pluggableauth.plugins.session import SessionCredentialsPlugin \ from zope.pluggableauth.plugins.session import SessionCredentialsPlugin \
@ -88,14 +70,13 @@ class TwoFactorSessionCredentials(SessionCredentials):
self.password = password self.password = password
self.tan = random.randint(100000, 999999) self.tan = random.randint(100000, 999999)
self.timestamp = datetime.now() self.timestamp = datetime.now()
rng = range(len(str(self.tan))) rng = list(range(len(str(self.tan))))
t1 = random.choice(rng) t1 = random.choice(rng)
rng.remove(t1) rng.remove(t1)
t2 = random.choice(rng) t2 = random.choice(rng)
self.tanA, self.tanB = sorted((t1, t2)) self.tanA, self.tanB = sorted((t1, t2))
self.hash = (hashlib. credstr = '%s:%s:%s' % (login, password, self.tan)
sha224("%s:%s:%s" % (login, password, self.tan)). self.hash = hashlib.sha224(credstr.encode('UTF-8')).hexdigest()
hexdigest())
self.validated = False self.validated = False
@ -233,7 +214,7 @@ class SessionCredentialsPlugin(BaseSessionCredentialsPlugin):
credentials = sessionData.get('credentials') credentials = sessionData.get('credentials')
if not credentials: if not credentials:
msg = 'Missing credentials' msg = 'Missing credentials'
return log.warn(msg) return log.warning(msg)
log.info("Processing phase 2, TAN: %s. " % credentials.tan) log.info("Processing phase 2, TAN: %s. " % credentials.tan)
if credentials.hash != hash: if credentials.hash != hash:
msg = 'Illegal hash.' msg = 'Illegal hash.'

View file

@ -1,23 +1,6 @@
# # cco.member.browser
# Copyright (c) 2016 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Login, logout, unauthorized stuff.
Login, logout, unauthorized stuff.
""" """
try: try:
@ -26,18 +9,18 @@ try:
except ImportError: except ImportError:
pass pass
from datetime import timedelta from datetime import timedelta
from email.MIMEText import MIMEText from email.mime.text import MIMEText
import logging import logging
from zope.app.exception.browser.unauthorized import Unauthorized as DefaultUnauth from zope.authentication.interfaces import IAuthentication
from zope.app.pagetemplate import ViewPageTemplateFile from zope.authentication.interfaces import ILogout, IUnauthenticatedPrincipal
from zope.app.security.interfaces import IAuthentication from zope.browserpage import ViewPageTemplateFile
from zope.app.security.interfaces import ILogout, IUnauthenticatedPrincipal
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope import component from zope import component
from zope.i18n import translate from zope.i18n import translate
from zope.i18nmessageid import MessageFactory from zope.i18nmessageid import MessageFactory
from zope.interface import implements from zope.interface import implementer
from zope.publisher.interfaces.http import IHTTPRequest from zope.publisher.interfaces.http import IHTTPRequest
from zope.security.interfaces import Unauthorized as DefaultUnauth
from zope.sendmail.interfaces import IMailDelivery from zope.sendmail.interfaces import IMailDelivery
from cco.member.auth import getCredentials, getPrincipalFromCredentials,\ from cco.member.auth import getCredentials, getPrincipalFromCredentials,\
@ -149,10 +132,9 @@ class TanForm(LoginForm):
return recipient return recipient
@implementer(ILogout)
class Logout(object): class Logout(object):
implements(ILogout)
def __init__(self, context, request): def __init__(self, context, request):
self.context = context self.context = context
self.request = request self.request = request

View file

@ -1,6 +1,4 @@
#
# cco.member.webapi # cco.member.webapi
#
from cco.webapi.server import TypeHandler from cco.webapi.server import TypeHandler
@ -9,6 +7,6 @@ class Users(TypeHandler):
def create(self): def create(self):
data = self.getInputData() data = self.getInputData()
print '***', data print('***', data)
#create_or_update_object(self.loopsRoot, 'person', data) #create_or_update_object(self.loopsRoot, 'person', data)
return self.success() return self.success()

View file

@ -12,11 +12,14 @@ keywords = ["loops"]
authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}] authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}]
dependencies = [ dependencies = [
"loops" "loops",
"requests",
] ]
[project.optional-dependencies] [project.optional-dependencies]
jwt = ["python_jwt", "jwcrypto"]
test = ["zope.testrunner"] test = ["zope.testrunner"]
[tool.setuptools] [tool.setuptools]