Commit 0d785cfb by Mac Stephens

Add automatic login selector on login form

parent f68da2f3
......@@ -38,6 +38,8 @@ type
// JWT helpers
procedure Logout;
function AutoLoginEnabled: Boolean;
procedure SetAutoLoginEnabled(Value: Boolean);
function GetToken: string;
function Authenticated: Boolean;
function TokenExpirationDate: TDateTime;
......@@ -180,6 +182,21 @@ end;
procedure TAuthService.Logout;
begin
DeleteToken;
if not DeviceManagementMode then
SetAutoLoginEnabled(False);
end;
function TAuthService.AutoLoginEnabled: Boolean;
begin
Result := window.localStorage.getItem(CREDENTIAL_NAME + '_AUTO_LOGIN') = 'true';
end;
procedure TAuthService.SetAutoLoginEnabled(Value: Boolean);
begin
if Value then
window.localStorage.setItem(CREDENTIAL_NAME + '_AUTO_LOGIN', 'true')
else
window.localStorage.removeItem(CREDENTIAL_NAME + '_AUTO_LOGIN');
end;
// ---- Credential ID storage ----
......
......@@ -53,6 +53,14 @@ object FViewLogin: TFViewLogin
WidthPercent = 100.000000000000000000
OnClick = btnShowPasswordClick
end
object chkAutoLogin: TWebCheckBox
Left = 240
Top = 250
Width = 200
Height = 22
Caption = 'Sign me in automatically'
ElementID = 'view.login.autologin'
end
object btnLogin: TWebButton
Left = 240
Top = 217
......
......@@ -67,6 +67,10 @@
<!-- populated dynamically -->
</select>
</div>
<div id="view.login.autologinsection" class="form-check mb-3 d-none">
<input id="view.login.autologin" class="form-check-input fs-6" type="checkbox">
<label class="form-check-label" for="view.login.autologin">Sign me in automatically</label>
</div>
<button id="view.login.btnlogin"
class="btn btn-primary w-100">
Login
......
......@@ -15,6 +15,7 @@ type
edtPassword: TWebEdit;
btnShowPassword: TWebButton;
btnLogin: TWebButton;
chkAutoLogin: TWebCheckBox;
btnPasskeyLogin: TWebButton;
pnlMessage: TWebPanel;
lblMessage: TWebLabel;
......@@ -110,6 +111,9 @@ var
end;
begin
chkAutoLogin.Checked := AuthService.AutoLoginEnabled;
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
Document.getElementById('view.login.autologinsection').classList.remove('d-none');
GetAgencyConfigList;
el := Document.getElementById('view.login.version');
if Assigned(el) then
......@@ -149,6 +153,8 @@ var
procedure OnLoginOK;
begin
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
AuthService.SetAutoLoginEnabled(chkAutoLogin.Checked);
FLoginProc;
end;
......
......@@ -88,6 +88,18 @@ begin
end;
procedure StartApplication;
procedure OnAutoLoginFailed(AMessage: string);
begin
DisplayLoginView(AMessage);
end;
procedure OnChallenge(AChallenge, AChallengeToken: string);
begin
AuthService.LoginDeviceKey(AuthService.GetCredentialId, AChallengeToken,
@DisplayMainView, @OnAutoLoginFailed);
end;
begin
if AuthService.DeviceManagementMode then
begin
......@@ -104,7 +116,12 @@ begin
// Step 2: normal JWT auth check
if (not AuthService.Authenticated) or AuthService.TokenExpired then
DisplayLoginView
begin
if AuthService.IsSimpleKey and AuthService.AutoLoginEnabled then
AuthService.BeginAuthentication(AuthService.GetCredentialId, @OnChallenge, @OnAutoLoginFailed)
else
DisplayLoginView;
end
else
DisplayMainView;
end;
......
......@@ -38,6 +38,8 @@ type
// JWT helpers
procedure Logout;
function AutoLoginEnabled: Boolean;
procedure SetAutoLoginEnabled(Value: Boolean);
function GetToken: string;
function Authenticated: Boolean;
function TokenExpirationDate: TDateTime;
......@@ -208,6 +210,21 @@ end;
procedure TAuthService.Logout;
begin
DeleteToken;
if not DeviceManagementMode then
SetAutoLoginEnabled(False);
end;
function TAuthService.AutoLoginEnabled: Boolean;
begin
Result := window.localStorage.getItem(CREDENTIAL_NAME + '_AUTO_LOGIN') = 'true';
end;
procedure TAuthService.SetAutoLoginEnabled(Value: Boolean);
begin
if Value then
window.localStorage.setItem(CREDENTIAL_NAME + '_AUTO_LOGIN', 'true')
else
window.localStorage.removeItem(CREDENTIAL_NAME + '_AUTO_LOGIN');
end;
// ---- Credential ID storage ----
......
......@@ -53,6 +53,14 @@ object FViewLogin: TFViewLogin
WidthPercent = 100.000000000000000000
OnClick = btnShowPasswordClick
end
object chkAutoLogin: TWebCheckBox
Left = 240
Top = 250
Width = 200
Height = 22
Caption = 'Sign me in automatically'
ElementID = 'view.login.autologin'
end
object btnLogin: TWebButton
Left = 240
Top = 217
......
......@@ -67,6 +67,10 @@
<!-- populated dynamically -->
</select>
</div>
<div id="view.login.autologinsection" class="form-check mb-3 d-none">
<input id="view.login.autologin" class="form-check-input fs-6" type="checkbox">
<label class="form-check-label" for="view.login.autologin">Sign me in automatically</label>
</div>
<button id="view.login.btnlogin"
class="btn btn-primary w-100">
Login
......
......@@ -15,6 +15,7 @@ type
edtPassword: TWebEdit;
btnShowPassword: TWebButton;
btnLogin: TWebButton;
chkAutoLogin: TWebCheckBox;
btnPasskeyLogin: TWebButton;
pnlMessage: TWebPanel;
lblMessage: TWebLabel;
......@@ -110,6 +111,9 @@ var
end;
begin
chkAutoLogin.Checked := AuthService.AutoLoginEnabled;
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
Document.getElementById('view.login.autologinsection').classList.remove('d-none');
GetAgencyConfigList;
el := Document.getElementById('view.login.version');
if Assigned(el) then
......@@ -149,6 +153,8 @@ var
procedure OnLoginOK;
begin
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
AuthService.SetAutoLoginEnabled(chkAutoLogin.Checked);
FLoginProc;
end;
......
......@@ -88,6 +88,18 @@ begin
end;
procedure StartApplication;
procedure OnAutoLoginFailed(AMessage: string);
begin
DisplayLoginView(AMessage);
end;
procedure OnChallenge(AChallenge, AChallengeToken: string);
begin
AuthService.LoginDeviceKey(AuthService.GetCredentialId, AChallengeToken,
@DisplayMainView, @OnAutoLoginFailed);
end;
begin
if AuthService.DeviceManagementMode then
begin
......@@ -104,7 +116,12 @@ begin
// Step 2: normal JWT auth check
if (not AuthService.Authenticated) or AuthService.TokenExpired then
DisplayLoginView
begin
if AuthService.IsSimpleKey and AuthService.AutoLoginEnabled then
AuthService.BeginAuthentication(AuthService.GetCredentialId, @OnChallenge, @OnAutoLoginFailed)
else
DisplayLoginView;
end
else
DisplayMainView;
end;
......
......@@ -2,7 +2,7 @@
Agency=BFD
[Settings]
LogFileNum=214
LogFileNum=216
webClientVersion=0.9.5.0
MemoLogLevel=3
FileLogLevel=4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment