flaschengeist/geruecht/controller/userController.py

56 lines
1.7 KiB
Python

from . import LOGGER, Singleton, db, ldapController as ldap
from geruecht.model.user import User
from geruecht.exceptions import PermissionDenied
class UserController(metaclass=Singleton):
def __init__(self):
pass
def updateConfig(self, username, data):
user = self.getUser(username)
user.updateData(data)
db.updateUser(user)
return self.getUser(username)
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:
user = User(user_data)
db.insertUser(user)
else:
user.updateData(user_data)
db.updateUser(user)
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