mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-10-31 22:47:05 +01:00
pydoorlock: Extract WebApp pt. 1
Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
parent
d1855bf77d
commit
aaaad9b6ef
30
doorlockd
30
doorlockd
@ -34,6 +34,7 @@ from wtforms import PasswordField, StringField, SubmitField
|
||||
from wtforms.validators import DataRequired, Length
|
||||
|
||||
from pydoorlock.Authenticator import Authenticator, AuthMethod, AuthenticationResult
|
||||
from pydoorlock.WebApp import AuthenticationForm
|
||||
from pydoorlock.Door import DoorState
|
||||
|
||||
SYSCONFDIR = '.'
|
||||
@ -308,35 +309,6 @@ class Logic:
|
||||
return self.door_handler.state
|
||||
|
||||
|
||||
class AuthenticationForm(FlaskForm):
|
||||
username = StringField('Username', [Length(min=3, max=25)])
|
||||
password = PasswordField('Password', [DataRequired()])
|
||||
method = StringField('Method', [DataRequired()])
|
||||
open = SubmitField('Open')
|
||||
present = SubmitField('Present')
|
||||
close = SubmitField('Close')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
FlaskForm.__init__(self, *args, **kwargs)
|
||||
self.desired_state = DoorState.Closed
|
||||
|
||||
def validate(self):
|
||||
if not FlaskForm.validate(self):
|
||||
return False
|
||||
|
||||
if self.open.data:
|
||||
self.desired_state = DoorState.Open
|
||||
elif self.present.data:
|
||||
self.desired_state = DoorState.Present
|
||||
|
||||
if self.method.data == 'Local':
|
||||
self.method = AuthMethod.LOCAL_USER_DB
|
||||
else: # default: use LDAP
|
||||
self.method = AuthMethod.LDAP_USER_PW
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@socketio.on('request_status')
|
||||
@socketio.on('connect')
|
||||
def on_connect():
|
||||
|
34
pydoorlock/WebApp.py
Normal file
34
pydoorlock/WebApp.py
Normal file
@ -0,0 +1,34 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import PasswordField, StringField, SubmitField
|
||||
from wtforms.validators import DataRequired, Length
|
||||
|
||||
from .Door import DoorState
|
||||
from .Authenticator import AuthMethod
|
||||
|
||||
class AuthenticationForm(FlaskForm):
|
||||
username = StringField('Username', [Length(min=3, max=25)])
|
||||
password = PasswordField('Password', [DataRequired()])
|
||||
method = StringField('Method', [DataRequired()])
|
||||
open = SubmitField('Open')
|
||||
present = SubmitField('Present')
|
||||
close = SubmitField('Close')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
FlaskForm.__init__(self, *args, **kwargs)
|
||||
self.desired_state = DoorState.Closed
|
||||
|
||||
def validate(self):
|
||||
if not FlaskForm.validate(self):
|
||||
return False
|
||||
|
||||
if self.open.data:
|
||||
self.desired_state = DoorState.Open
|
||||
elif self.present.data:
|
||||
self.desired_state = DoorState.Present
|
||||
|
||||
if self.method.data == 'Local':
|
||||
self.method = AuthMethod.LOCAL_USER_DB
|
||||
else: # default: use LDAP
|
||||
self.method = AuthMethod.LDAP_USER_PW
|
||||
|
||||
return True
|
Loading…
Reference in New Issue
Block a user