flaschengeist/geruecht/controller/userController.py

47 lines
1.4 KiB
Python

from . import LOGGER, Singleton, db, ldapController as ldap
from geruecht.exceptions import PermissionDenied
class UserController(metaclass=Singleton):
def __init__(self):
pass
def addAmount(self, username, amount, year, month):
user = self.getUser(username)
user.addAmount(amount, year=year, month=month)
creditLists = user.updateGeruecht()
for creditList in creditLists:
db.updateCreditList(creditList)
return user.getGeruecht(year)
def addCredit(self, username, credit, year, month):
user = self.getUser(username)
user.addCredit(credit, year=year, month=month)
creditLists = user.updateGeruecht()
for creditList in creditLists:
db.updateCreditList(creditList)
return user.getGeruecht(year)
def getAllUsersfromDB(self):
return db.getAllUser()
def getUser(self, username):
user = db.getUser(username)
groups = ldap.getGroup(username)
user_data = ldap.getUserData(username)
user_data['group'] = groups
if user is None:
db.insertUser(user_data)
else:
db.updateUser(user_data)
user = db.getUser(username)
return user
def loginUser(self, username, password):
try:
user = self.getUser(username)
ldap.login(username, password)
return user
except PermissionDenied as err:
raise err