fixed imports, bugfix that accLifetime will load from config file

This commit is contained in:
Tim Gröger 2020-01-19 00:37:40 +01:00
parent 754f373cb0
commit 29f20b2327
9 changed files with 47 additions and 44 deletions

View File

@ -1,10 +1,17 @@
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
from geruecht.controller import ldapController as ldap, accesTokenController, userController import geruecht.controller as gc
import geruecht.controller.ldapController as lc
import geruecht.controller.accesTokenController as ac
import geruecht.controller.userController as uc
from datetime import datetime from datetime import datetime
from geruecht.model import BAR, MONEY from geruecht.model import BAR, MONEY
baruser = Blueprint("baruser", __name__) baruser = Blueprint("baruser", __name__)
ldap= lc.LDAPController(gc.ldapConfig['URL'], gc.ldapConfig['dn'])
accesTokenController = ac.AccesTokenController()
userController = uc.UserController()
@baruser.route("/bar") @baruser.route("/bar")
def _bar(): def _bar():
""" Main function for Baruser """ Main function for Baruser

View File

@ -34,7 +34,7 @@ class ConifgParser():
self.ldap = self.config['LDAP'] self.ldap = self.config['LDAP']
LOGGER.info("Set LDAPconfig: {}".format(self.ldap)) LOGGER.info("Set LDAPconfig: {}".format(self.ldap))
if 'AccessTokenLifeTime' in self.config: if 'AccessTokenLifeTime' in self.config:
self.accessTokenLifeTime = self.config['AccessTokenLifeTime'] self.accessTokenLifeTime = int(self.config['AccessTokenLifeTime'])
LOGGER.info("Set AccessTokenLifeTime: {}".format(self.accessTokenLifeTime)) LOGGER.info("Set AccessTokenLifeTime: {}".format(self.accessTokenLifeTime))
else: else:
self.accessTokenLifeTime = default['AccessTokenLifeTime'] self.accessTokenLifeTime = default['AccessTokenLifeTime']

View File

@ -15,35 +15,7 @@ class Singleton(type):
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls] return cls._instances[cls]
from .databaseController import DatabaseController
def getDatabesController():
if db is not None:
return db
else:
return DatabaseController(dbConfig['URL'], dbConfig['user'], dbConfig['passwd'], dbConfig['database'])
from .ldapController import LDAPController
def getLDAPController():
if ldapController is not None:
return ldapController
else:
return LDAPController(ldapConfig['URL'], ldapConfig['dn'])
from .accesTokenController import AccesTokenController
dbConfig = config.getDatabase() dbConfig = config.getDatabase()
ldapConfig = config.getLDAP() ldapConfig = config.getLDAP()
accConfig = config.getAccessToken() accConfig = config.getAccessToken()
mailConfig = config.getMail() mailConfig = config.getMail()
db = DatabaseController(dbConfig['URL'], dbConfig['user'], dbConfig['passwd'], dbConfig['database'])
ldapController = LDAPController(ldapConfig['URL'], ldapConfig['dn'])
from . emailController import EmailController
emailController = EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['port'], mailConfig['email'])
from . userController import UserController
def getUserController():
if userController is not None:
return userController
else:
return UserController()
userController = UserController()
accesTokenController = AccesTokenController(accConfig)

View File

@ -1,11 +1,13 @@
from geruecht.model.accessToken import AccessToken from geruecht.model.accessToken import AccessToken
#import geruecht.controller.userController as userController import geruecht.controller as gc
import geruecht.controller.userController as uc
from geruecht.model import BAR from geruecht.model import BAR
from geruecht.controller import LOGGER from geruecht.controller import LOGGER
from datetime import datetime, timedelta from datetime import datetime, timedelta
import hashlib import hashlib
from . import Singleton from . import Singleton
userController = uc.UserController()
class AccesTokenController(metaclass=Singleton): class AccesTokenController(metaclass=Singleton):
""" Control all createt AccesToken """ Control all createt AccesToken
@ -25,15 +27,15 @@ class AccesTokenController(metaclass=Singleton):
Initialize Thread and set tokenList empty. Initialize Thread and set tokenList empty.
""" """
LOGGER.info("Initialize AccessTokenController") LOGGER.info("Initialize AccessTokenController")
self.lifetime = lifetime self.lifetime = gc.accConfig
self.tokenList = [] self.tokenList = []
#def checkBar(self, user): def checkBar(self, user):
# if (userController.checkBarUser(user)): if (userController.checkBarUser(user)):
# user.group.append(BAR) user.group.append(BAR)
# elif BAR in user.group: elif BAR in user.group:
# user.group.remove(BAR) user.group.remove(BAR)
def validateAccessToken(self, token, group): def validateAccessToken(self, token, group):
""" Verify Accestoken """ Verify Accestoken

View File

@ -189,7 +189,7 @@ class DatabaseController(metaclass=Singleton):
self.db.close() self.db.close()
except Exception as err: except Exception as err:
raise err raise err
return {"user": user, "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime']} return {"user": user, "startdatetime": data['startdatetime'], "enddatetime": data['enddatetime']} if data else None
def getWorkers(self, date): def getWorkers(self, date):
self.connect() self.connect()

View File

@ -1,8 +1,15 @@
from . import LOGGER, Singleton, db, ldapController as ldap, emailController from . import LOGGER, Singleton, ldapConfig, dbConfig, mailConfig
import geruecht.controller.databaseController as dc
import geruecht.controller.ldapController as lc
import geruecht.controller.emailController as ec
from geruecht.model.user import User from geruecht.model.user import User
from geruecht.exceptions import PermissionDenied from geruecht.exceptions import PermissionDenied
from datetime import datetime, timedelta from datetime import datetime, timedelta
db = dc.DatabaseController(dbConfig['URL'], dbConfig['user'], dbConfig['passwd'], dbConfig['database'])
ldap = lc.LDAPController(ldapConfig['URL'], ldapConfig['dn'])
emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['port'], mailConfig['email'])
class UserController(metaclass=Singleton): class UserController(metaclass=Singleton):
def __init__(self): def __init__(self):
@ -71,7 +78,11 @@ class UserController(metaclass=Singleton):
def checkBarUser(self, user): def checkBarUser(self, user):
date = datetime.now() date = datetime.now()
startdatetime = date.replace(hour=11, minute=0, microsecond=0) zero = date.replace(hour=0, minute=0, second=0, microsecond=0)
end = zero + timedelta(hours=11)
startdatetime = date.replace(hour=11, minute=0, second=0, microsecond=0)
if date > zero and end > date:
startdatetime = startdatetime - timedelta(days=1)
enddatetime = startdatetime + timedelta(days=1) enddatetime = startdatetime + timedelta(days=1)
result = False result = False
if date >= startdatetime and date < enddatetime: if date >= startdatetime and date < enddatetime:

View File

@ -1,11 +1,14 @@
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
from geruecht.finanzer import LOGGER from geruecht.finanzer import LOGGER
from datetime import datetime from datetime import datetime
from geruecht.controller import accesTokenController, userController import geruecht.controller.userController as uc
import geruecht.controller.accesTokenController as ac
from geruecht.model import MONEY from geruecht.model import MONEY
finanzer = Blueprint("finanzer", __name__) finanzer = Blueprint("finanzer", __name__)
accesTokenController = ac.AccesTokenController()
userController = uc.UserController()
@finanzer.route("/getFinanzerMain") @finanzer.route("/getFinanzerMain")
def _getFinanzer(): def _getFinanzer():

View File

@ -1,9 +1,12 @@
from geruecht import app, LOGGER from geruecht import app, LOGGER
from geruecht.exceptions import PermissionDenied from geruecht.exceptions import PermissionDenied
from geruecht.controller import accesTokenController, userController import geruecht.controller.accesTokenController as ac
import geruecht.controller.userController as uc
from geruecht.model import MONEY, BAR, USER, GASTRO from geruecht.model import MONEY, BAR, USER, GASTRO
from flask import request, jsonify from flask import request, jsonify
accesTokenController = ac.AccesTokenController()
userController = uc.UserController()
def login(user, password): def login(user, password):
return user.login(password) return user.login(password)
@ -48,7 +51,7 @@ def _login():
user = userController.loginUser(username, password) user = userController.loginUser(username, password)
user.password = password user.password = password
token = accesTokenController.createAccesToken(user) token = accesTokenController.createAccesToken(user)
dic = user.toJSON() dic = accesTokenController.validateAccessToken(token, [USER]).user.toJSON()
dic["token"] = token dic["token"] = token
dic["accessToken"] = token dic["accessToken"] = token
LOGGER.info("User {} success login.".format(username)) LOGGER.info("User {} success login.".format(username))

View File

@ -1,10 +1,15 @@
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
from geruecht.controller import userController, accesTokenController import geruecht.controller as gc
import geruecht.controller.userController as uc
import geruecht.controller.accesTokenController as ac
from geruecht.model import USER from geruecht.model import USER
from datetime import datetime from datetime import datetime
user = Blueprint("user", __name__) user = Blueprint("user", __name__)
accesTokenController = ac.AccesTokenController()
userController = uc.UserController()
@user.route("/user/main") @user.route("/user/main")
def _main(): def _main():