fixed imports, bugfix that accLifetime will load from config file
This commit is contained in:
parent
754f373cb0
commit
29f20b2327
|
@ -1,10 +1,17 @@
|
|||
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 geruecht.model import BAR, MONEY
|
||||
|
||||
baruser = Blueprint("baruser", __name__)
|
||||
|
||||
ldap= lc.LDAPController(gc.ldapConfig['URL'], gc.ldapConfig['dn'])
|
||||
accesTokenController = ac.AccesTokenController()
|
||||
userController = uc.UserController()
|
||||
|
||||
@baruser.route("/bar")
|
||||
def _bar():
|
||||
""" Main function for Baruser
|
||||
|
|
|
@ -34,7 +34,7 @@ class ConifgParser():
|
|||
self.ldap = self.config['LDAP']
|
||||
LOGGER.info("Set LDAPconfig: {}".format(self.ldap))
|
||||
if 'AccessTokenLifeTime' in self.config:
|
||||
self.accessTokenLifeTime = self.config['AccessTokenLifeTime']
|
||||
self.accessTokenLifeTime = int(self.config['AccessTokenLifeTime'])
|
||||
LOGGER.info("Set AccessTokenLifeTime: {}".format(self.accessTokenLifeTime))
|
||||
else:
|
||||
self.accessTokenLifeTime = default['AccessTokenLifeTime']
|
||||
|
|
|
@ -15,35 +15,7 @@ class Singleton(type):
|
|||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||
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()
|
||||
ldapConfig = config.getLDAP()
|
||||
accConfig = config.getAccessToken()
|
||||
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)
|
|
@ -1,11 +1,13 @@
|
|||
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.controller import LOGGER
|
||||
from datetime import datetime, timedelta
|
||||
import hashlib
|
||||
from . import Singleton
|
||||
|
||||
userController = uc.UserController()
|
||||
|
||||
class AccesTokenController(metaclass=Singleton):
|
||||
""" Control all createt AccesToken
|
||||
|
@ -25,15 +27,15 @@ class AccesTokenController(metaclass=Singleton):
|
|||
Initialize Thread and set tokenList empty.
|
||||
"""
|
||||
LOGGER.info("Initialize AccessTokenController")
|
||||
self.lifetime = lifetime
|
||||
self.lifetime = gc.accConfig
|
||||
|
||||
self.tokenList = []
|
||||
|
||||
#def checkBar(self, user):
|
||||
# if (userController.checkBarUser(user)):
|
||||
# user.group.append(BAR)
|
||||
# elif BAR in user.group:
|
||||
# user.group.remove(BAR)
|
||||
def checkBar(self, user):
|
||||
if (userController.checkBarUser(user)):
|
||||
user.group.append(BAR)
|
||||
elif BAR in user.group:
|
||||
user.group.remove(BAR)
|
||||
|
||||
def validateAccessToken(self, token, group):
|
||||
""" Verify Accestoken
|
||||
|
|
|
@ -189,7 +189,7 @@ class DatabaseController(metaclass=Singleton):
|
|||
self.db.close()
|
||||
except Exception as 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):
|
||||
self.connect()
|
||||
|
|
|
@ -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.exceptions import PermissionDenied
|
||||
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):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -71,7 +78,11 @@ class UserController(metaclass=Singleton):
|
|||
|
||||
def checkBarUser(self, user):
|
||||
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)
|
||||
result = False
|
||||
if date >= startdatetime and date < enddatetime:
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
from flask import Blueprint, request, jsonify
|
||||
from geruecht.finanzer import LOGGER
|
||||
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
|
||||
|
||||
finanzer = Blueprint("finanzer", __name__)
|
||||
|
||||
accesTokenController = ac.AccesTokenController()
|
||||
userController = uc.UserController()
|
||||
|
||||
@finanzer.route("/getFinanzerMain")
|
||||
def _getFinanzer():
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
from geruecht import app, LOGGER
|
||||
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 flask import request, jsonify
|
||||
|
||||
accesTokenController = ac.AccesTokenController()
|
||||
userController = uc.UserController()
|
||||
|
||||
def login(user, password):
|
||||
return user.login(password)
|
||||
|
@ -48,7 +51,7 @@ def _login():
|
|||
user = userController.loginUser(username, password)
|
||||
user.password = password
|
||||
token = accesTokenController.createAccesToken(user)
|
||||
dic = user.toJSON()
|
||||
dic = accesTokenController.validateAccessToken(token, [USER]).user.toJSON()
|
||||
dic["token"] = token
|
||||
dic["accessToken"] = token
|
||||
LOGGER.info("User {} success login.".format(username))
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
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 datetime import datetime
|
||||
|
||||
user = Blueprint("user", __name__)
|
||||
|
||||
accesTokenController = ac.AccesTokenController()
|
||||
userController = uc.UserController()
|
||||
|
||||
@user.route("/user/main")
|
||||
def _main():
|
||||
|
||||
|
|
Loading…
Reference in New Issue