Compare commits

..

2 Commits

2 changed files with 11 additions and 9 deletions

View File

@ -92,15 +92,15 @@ class DoorHandle:
if self.nfc_sock is not None:
self.nfc_sock.send(b'rld\n')
def open_door(self):
def open_door(self, user=b''):
if self.nfc_sock is not None:
self.nfc_sock.send(b'open\n')
self.nfc_sock.send(b'open ' + user + b'\n')
else:
raise Exception("No connection to NFC socket. Cannot close door!")
def close_door(self):
def close_door(self, user=b''):
if self.nfc_sock is not None:
self.nfc_sock.send(b'close\n')
self.nfc_sock.send(b'close ' + user + b'\n')
else:
raise Exception("No connection to NFC socket. Cannot close door!")

View File

@ -207,18 +207,19 @@ def create_application(config):
new_user_data['password'] = hash_password(password)
new_user_data['roles'] = []
lock_permission = con.search('ou=Users,dc=imaginaerraum,dc=de',
f'(&(uid={username})(memberof=cn=Members,ou=Groups,dc=imaginaerraum,dc=de))',
f'(&(uid={username})(memberof=cn=Keyholders,ou=Groups,dc=imaginaerraum,dc=de))',
attributes=ldap3.ALL_ATTRIBUTES)
authorized = True
if lock_permission:
new_user_data['email'] = con.entries[0].mail.value
else:
new_user_data['email'] = None
authorized = False
token_granting_permission = con.search('ou=Users,dc=imaginaerraum,dc=de',
f'(&(uid={username})(memberof=cn=Vorstand,ou=Groups,dc=imaginaerraum,dc=de))')
if token_granting_permission:
new_user_data['roles'].append('admin')
return True, new_user_data
return authorized, new_user_data
class ExtendedLoginForm(LoginForm):
email = StringField('Benutzername oder E-Mail', [Required()])
@ -677,8 +678,9 @@ def create_application(config):
@app.route('/open')
@auth_required()
def open_door():
try:
door.open_door()
door.open_door(user=current_user.username)
logger.info(f"Door opened by admin user {current_user.username}")
except Exception as e:
flash(f'Could not open door. Exception: {e}')
@ -689,7 +691,7 @@ def create_application(config):
@auth_required()
def close_door():
try:
door.close_door()
door.close_door(user=current_user.username)
logger.info(f"Door closed by admin user {current_user.username}")
except Exception as e:
flash(f'Could not close door. Exception: {e}')