Commit 0d785cfb by Mac Stephens

Add automatic login selector on login form

parent f68da2f3
...@@ -38,6 +38,8 @@ type ...@@ -38,6 +38,8 @@ type
// JWT helpers // JWT helpers
procedure Logout; procedure Logout;
function AutoLoginEnabled: Boolean;
procedure SetAutoLoginEnabled(Value: Boolean);
function GetToken: string; function GetToken: string;
function Authenticated: Boolean; function Authenticated: Boolean;
function TokenExpirationDate: TDateTime; function TokenExpirationDate: TDateTime;
...@@ -180,6 +182,21 @@ end; ...@@ -180,6 +182,21 @@ end;
procedure TAuthService.Logout; procedure TAuthService.Logout;
begin begin
DeleteToken; 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; end;
// ---- Credential ID storage ---- // ---- Credential ID storage ----
......
...@@ -53,6 +53,14 @@ object FViewLogin: TFViewLogin ...@@ -53,6 +53,14 @@ object FViewLogin: TFViewLogin
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnShowPasswordClick OnClick = btnShowPasswordClick
end 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 object btnLogin: TWebButton
Left = 240 Left = 240
Top = 217 Top = 217
......
...@@ -67,6 +67,10 @@ ...@@ -67,6 +67,10 @@
<!-- populated dynamically --> <!-- populated dynamically -->
</select> </select>
</div> </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" <button id="view.login.btnlogin"
class="btn btn-primary w-100"> class="btn btn-primary w-100">
Login Login
......
...@@ -15,6 +15,7 @@ type ...@@ -15,6 +15,7 @@ type
edtPassword: TWebEdit; edtPassword: TWebEdit;
btnShowPassword: TWebButton; btnShowPassword: TWebButton;
btnLogin: TWebButton; btnLogin: TWebButton;
chkAutoLogin: TWebCheckBox;
btnPasskeyLogin: TWebButton; btnPasskeyLogin: TWebButton;
pnlMessage: TWebPanel; pnlMessage: TWebPanel;
lblMessage: TWebLabel; lblMessage: TWebLabel;
...@@ -110,6 +111,9 @@ var ...@@ -110,6 +111,9 @@ var
end; end;
begin begin
chkAutoLogin.Checked := AuthService.AutoLoginEnabled;
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
Document.getElementById('view.login.autologinsection').classList.remove('d-none');
GetAgencyConfigList; GetAgencyConfigList;
el := Document.getElementById('view.login.version'); el := Document.getElementById('view.login.version');
if Assigned(el) then if Assigned(el) then
...@@ -149,6 +153,8 @@ var ...@@ -149,6 +153,8 @@ var
procedure OnLoginOK; procedure OnLoginOK;
begin begin
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
AuthService.SetAutoLoginEnabled(chkAutoLogin.Checked);
FLoginProc; FLoginProc;
end; end;
......
...@@ -88,6 +88,18 @@ begin ...@@ -88,6 +88,18 @@ begin
end; end;
procedure StartApplication; 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 begin
if AuthService.DeviceManagementMode then if AuthService.DeviceManagementMode then
begin begin
...@@ -104,7 +116,12 @@ begin ...@@ -104,7 +116,12 @@ begin
// Step 2: normal JWT auth check // Step 2: normal JWT auth check
if (not AuthService.Authenticated) or AuthService.TokenExpired then 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 else
DisplayMainView; DisplayMainView;
end; end;
......
...@@ -38,6 +38,8 @@ type ...@@ -38,6 +38,8 @@ type
// JWT helpers // JWT helpers
procedure Logout; procedure Logout;
function AutoLoginEnabled: Boolean;
procedure SetAutoLoginEnabled(Value: Boolean);
function GetToken: string; function GetToken: string;
function Authenticated: Boolean; function Authenticated: Boolean;
function TokenExpirationDate: TDateTime; function TokenExpirationDate: TDateTime;
...@@ -208,6 +210,21 @@ end; ...@@ -208,6 +210,21 @@ end;
procedure TAuthService.Logout; procedure TAuthService.Logout;
begin begin
DeleteToken; 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; end;
// ---- Credential ID storage ---- // ---- Credential ID storage ----
......
...@@ -53,6 +53,14 @@ object FViewLogin: TFViewLogin ...@@ -53,6 +53,14 @@ object FViewLogin: TFViewLogin
WidthPercent = 100.000000000000000000 WidthPercent = 100.000000000000000000
OnClick = btnShowPasswordClick OnClick = btnShowPasswordClick
end 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 object btnLogin: TWebButton
Left = 240 Left = 240
Top = 217 Top = 217
......
...@@ -67,6 +67,10 @@ ...@@ -67,6 +67,10 @@
<!-- populated dynamically --> <!-- populated dynamically -->
</select> </select>
</div> </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" <button id="view.login.btnlogin"
class="btn btn-primary w-100"> class="btn btn-primary w-100">
Login Login
......
...@@ -15,6 +15,7 @@ type ...@@ -15,6 +15,7 @@ type
edtPassword: TWebEdit; edtPassword: TWebEdit;
btnShowPassword: TWebButton; btnShowPassword: TWebButton;
btnLogin: TWebButton; btnLogin: TWebButton;
chkAutoLogin: TWebCheckBox;
btnPasskeyLogin: TWebButton; btnPasskeyLogin: TWebButton;
pnlMessage: TWebPanel; pnlMessage: TWebPanel;
lblMessage: TWebLabel; lblMessage: TWebLabel;
...@@ -110,6 +111,9 @@ var ...@@ -110,6 +111,9 @@ var
end; end;
begin begin
chkAutoLogin.Checked := AuthService.AutoLoginEnabled;
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
Document.getElementById('view.login.autologinsection').classList.remove('d-none');
GetAgencyConfigList; GetAgencyConfigList;
el := Document.getElementById('view.login.version'); el := Document.getElementById('view.login.version');
if Assigned(el) then if Assigned(el) then
...@@ -149,6 +153,8 @@ var ...@@ -149,6 +153,8 @@ var
procedure OnLoginOK; procedure OnLoginOK;
begin begin
if AuthService.IsSimpleKey and not AuthService.DeviceManagementMode then
AuthService.SetAutoLoginEnabled(chkAutoLogin.Checked);
FLoginProc; FLoginProc;
end; end;
......
...@@ -88,6 +88,18 @@ begin ...@@ -88,6 +88,18 @@ begin
end; end;
procedure StartApplication; 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 begin
if AuthService.DeviceManagementMode then if AuthService.DeviceManagementMode then
begin begin
...@@ -104,7 +116,12 @@ begin ...@@ -104,7 +116,12 @@ begin
// Step 2: normal JWT auth check // Step 2: normal JWT auth check
if (not AuthService.Authenticated) or AuthService.TokenExpired then 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 else
DisplayMainView; DisplayMainView;
end; end;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Agency=BFD Agency=BFD
[Settings] [Settings]
LogFileNum=214 LogFileNum=216
webClientVersion=0.9.5.0 webClientVersion=0.9.5.0
MemoLogLevel=3 MemoLogLevel=3
FileLogLevel=4 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