mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 15:56:17 +00:00
Sign In and TOTP is done
This commit is contained in:
@@ -19,7 +19,7 @@ def ResponseObject(status=True, message=None, data=None, status_code = 200) -> F
|
||||
def login_required(f):
|
||||
@wraps(f)
|
||||
def func(*args, **kwargs):
|
||||
if session.get("username") is None or session.get("role") != "client":
|
||||
if session.get("username") is None or session.get("totpVerified") is None or not session.get("totpVerified") or session.get("role") != "client":
|
||||
return ResponseObject(False, "Unauthorized access.", data=None, status_code=401)
|
||||
return f(*args, **kwargs)
|
||||
return func
|
||||
@@ -47,12 +47,49 @@ def createClientBlueprint(wireguardConfigurations: dict[WireguardConfiguration],
|
||||
def ClientAPI_SignIn():
|
||||
data = request.json
|
||||
status, msg = DashboardClients.SignIn(**data)
|
||||
if status:
|
||||
session['username'] = data.get('Email')
|
||||
session['role'] = 'client'
|
||||
session['totpVerified'] = False
|
||||
return ResponseObject(status, msg)
|
||||
|
||||
@client.get(f'{prefix}/api/signin/totp')
|
||||
def ClientAPI_SignIn_TOTP():
|
||||
token = request.args.get('Token', None)
|
||||
if not token:
|
||||
return ResponseObject(False, "Please provide TOTP token")
|
||||
|
||||
status, msg = DashboardClients.SignIn_GetTotp(token)
|
||||
return ResponseObject(status, msg)
|
||||
|
||||
@client.post(f'{prefix}/api/signin/totp')
|
||||
def ClientAPI_SignIn_ValidateTOTP():
|
||||
data = request.json
|
||||
token = data.get('Token', None)
|
||||
userProvidedTotp = data.get('UserProvidedTOTP', None)
|
||||
if not all([token, userProvidedTotp]):
|
||||
return ResponseObject(False, "Please fill in all fields")
|
||||
status, msg = DashboardClients.SignIn_GetTotp(token, userProvidedTotp)
|
||||
if status:
|
||||
if session.get('username') is None:
|
||||
return ResponseObject(False, "Sign in status is invalid", status_code=401)
|
||||
session['totpVerified'] = True
|
||||
|
||||
return ResponseObject(status, msg)
|
||||
|
||||
@client.get(prefix)
|
||||
@login_required
|
||||
def ClientIndex():
|
||||
print(wireguardConfigurations.keys())
|
||||
return render_template('client.html')
|
||||
|
||||
@client.get(f'{prefix}/api/validateAuthentication')
|
||||
@login_required
|
||||
def ClientAPI_ValidateAuthentication():
|
||||
return ResponseObject(True)
|
||||
|
||||
@client.get(f'{prefix}/api/configurations')
|
||||
@login_required
|
||||
def ClientAPI_Configurations():
|
||||
return ResponseObject(True, "Ping Pong!")
|
||||
|
||||
return client
|
Reference in New Issue
Block a user