Commit cf24b2b6 by emsys

debugging

parent 76453efa
unit Api.ServiceImpl;
unit Api.ServiceImpl;
interface
......@@ -17,8 +17,8 @@ type
strict private
ApiDB: TApiDatabaseModule;
private
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
//procedure AfterConstruction; override;
//procedure BeforeDestruction; override;
procedure RequireAdmin;
procedure RequireActiveDevice;
function OpenLemsConnection: TUniConnection;
......
unit Auth.ServiceImpl;
unit Auth.ServiceImpl;
interface
......@@ -22,8 +22,8 @@ type
userId: string;
userPersonnelId: string;
userIsAdmin: Boolean;
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
//procedure AfterConstruction; override;
//procedure BeforeDestruction; override;
function VerifyVersion(ClientVersion: string): TJSONObject;
function CheckUser(const User, Password, Agency: string): Integer;
function Decrypt(inStr, keyStr: AnsiString): AnsiString;
......@@ -36,7 +36,7 @@ type
signature: string): string;
constructor Create;
destructor Destroy; override;
function Login(const User, Password, Agency: string): string;
//function Login(const User, Password, Agency: string): string;
function GetAgencieslist(): TAgenciesList;
function GetAgencyConfiglist: TAgencyConfigList;
function BeginRegistration(const PhoneNumber: string): TJSONObject;
......@@ -819,53 +819,53 @@ begin
end;
end;
function TAuthService.Login(const User, Password, Agency: string): string;
var
userState: Integer;
JWT: TJWT;
begin
Logger.Log(1, Format('AuthService.Login - User: "%s" Agency: "%s"', [User, Agency]));
userState := CheckUser(User, Password, Agency);
try
userState := CheckUser(User, Password, Agency);
except
on E: Exception do
begin
Logger.Log(2, 'AuthService.Login - CheckUser error: ' + E.ClassName + ': ' + E.Message);
raise EXDataHttpException.Create(500, 'Login failed');
end;
end;
if userState = 0 then
begin
Logger.Log(2, Format('AuthService.Login - invalid login for User: "%s" Agency: "%s"', [User, Agency]));
raise EXDataHttpUnauthorized.Create('Invalid user or password');
end;
if userState = 1 then
begin
Logger.Log(2, Format('AuthService.Login - inactive user: "%s" Agency: "%s"', [User, Agency]));
raise EXDataHttpUnauthorized.Create('User not active');
end;
JWT := TJWT.Create;
try
JWT.Claims.JWTId := LowerCase(Copy(TUtils.GuidToVariant(TUtils.NewGuid), 2, 36));
JWT.Claims.IssuedAt := Now;
JWT.Claims.Expiration := IncHour(Now, 24);
JWT.Claims.SetClaimOfType<string>('user_name', userName);
JWT.Claims.SetClaimOfType<string>('user_fullname', userFullName);
JWT.Claims.SetClaimOfType<string>('user_agency', userAgency);
JWT.Claims.SetClaimOfType<string>('user_badge', userBadge);
JWT.Claims.SetClaimOfType<string>('user_id', userId);
JWT.Claims.SetClaimOfType<string>('user_personnelid', userPersonnelId);
Result := TJOSE.SHA256CompactToken(ServerConfig.jwtTokenSecret, JWT);
finally
JWT.Free;
end;
end;
//
//function TAuthService.Login(const User, Password, Agency: string): string;
//var
// userState: Integer;
// JWT: TJWT;
//begin
// Logger.Log(1, Format('AuthService.Login - User: "%s" Agency: "%s"', [User, Agency]));
// userState := CheckUser(User, Password, Agency);
//
// try
// userState := CheckUser(User, Password, Agency);
// except
// on E: Exception do
// begin
// Logger.Log(2, 'AuthService.Login - CheckUser error: ' + E.ClassName + ': ' + E.Message);
// raise EXDataHttpException.Create(500, 'Login failed');
// end;
// end;
//
// if userState = 0 then
// begin
// Logger.Log(2, Format('AuthService.Login - invalid login for User: "%s" Agency: "%s"', [User, Agency]));
// raise EXDataHttpUnauthorized.Create('Invalid user or password');
// end;
//
// if userState = 1 then
// begin
// Logger.Log(2, Format('AuthService.Login - inactive user: "%s" Agency: "%s"', [User, Agency]));
// raise EXDataHttpUnauthorized.Create('User not active');
// end;
//
// JWT := TJWT.Create;
// try
// JWT.Claims.JWTId := LowerCase(Copy(TUtils.GuidToVariant(TUtils.NewGuid), 2, 36));
// JWT.Claims.IssuedAt := Now;
// JWT.Claims.Expiration := IncHour(Now, 24);
// JWT.Claims.SetClaimOfType<string>('user_name', userName);
// JWT.Claims.SetClaimOfType<string>('user_fullname', userFullName);
// JWT.Claims.SetClaimOfType<string>('user_agency', userAgency);
// JWT.Claims.SetClaimOfType<string>('user_badge', userBadge);
// JWT.Claims.SetClaimOfType<string>('user_id', userId);
// JWT.Claims.SetClaimOfType<string>('user_personnelid', userPersonnelId);
// Result := TJOSE.SHA256CompactToken(ServerConfig.jwtTokenSecret, JWT);
// finally
// JWT.Free;
// end;
//end;
function TAuthService.CheckUser(const User, Password, Agency: string): Integer;
var
......
......@@ -31,7 +31,9 @@ uses
Ws.Server.Module in 'Source\Ws.Server.Module.pas' {WsServerModule: TDataModule},
Ws.DataModel in 'Source\Ws.DataModel.pas',
WsMessages in 'Source\shared\WsMessages.pas',
WebSocket.Manager in 'Source\WebSocket.Manager.pas';
WebSocket.Manager in 'Source\WebSocket.Manager.pas',
Webauthn.Cbor in 'Source\Webauthn.Cbor.pas',
Webauthn.Crypto in 'Source\Webauthn.Crypto.pas';
type
TMemoLogAppender = class( TInterfacedObject, ILogAppender )
......
......@@ -180,6 +180,8 @@
<DCCReference Include="Source\Ws.DataModel.pas"/>
<DCCReference Include="Source\shared\WsMessages.pas"/>
<DCCReference Include="Source\WebSocket.Manager.pas"/>
<DCCReference Include="Source\Webauthn.Cbor.pas"/>
<DCCReference Include="Source\Webauthn.Crypto.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
......@@ -872,9 +874,6 @@
<Platform Name="Win64x">
<Operation>1</Operation>
</Platform>
<Platform Name="WinARM64EC">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectiOSDeviceDebug">
<Platform Name="iOSDevice32">
......@@ -945,10 +944,6 @@
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="WinARM64EC">
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="UWP_DelphiLogo44">
<Platform Name="Win32">
......@@ -959,10 +954,6 @@
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="WinARM64EC">
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iOS_AppStore1024">
<Platform Name="iOSDevice64">
......
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