I have a problem with the result of a query.
The code is in a XData service function
I call Login with Name/Password
In my service function I call CheckUser(Username,Password) and want to get the User.
The FUser Object is in the class.
I find the User. Everything ok. In the debugger, I cann see all. In this function I can use the FUser.
But if I get out of the function CheckUser and go back to "Login_v1" the FUser is "inaccessible".
Will the List be deleted? (the TUserlist : TObejctList<TUser>)
But if I get out of the function CheckUser and go back to "Login_v1" the FUser is "inaccessible".
Will the List be deleted? (the TUserlist : TObejctList<TUser>)
Please look at the code.
I call the function at line ##########################
The reading process is bold
Thank you.
Thank you.
unit Auth.func.Impl;
interface
uses
( ... )
type
[ServiceImplementation]
TAuthFunc = class(TInterfacedObject, IsngFunc, IAuthFunc)
strict private // Interface IAuthFunc
function Login ( const Param: TJSONObject) : TJSONObject;
private
FUser : TUser; // User aus Datenbank
function Login_v1 ( const AsngPara: TsngParameter) : TJSONObject;
function CheckUser ( const Username, Password: string): integer;
end;
implementation
uses
( ... )
function TAuthFunc.Login( const Param: TJSONObject) : TJSONObject;
begin
( ... )
Result := Login_v1( sngPara)
( ... )
end;
function TAuthFunc.Login_v1( const AsngPara: TsngParameter) : TJSONObject;
var
JWT : TJWT;
LUsername : string;
LPassword : string;
LResult : TsngResult;
res : integer;
begin
( ... )
//###########################################################
res := CheckUser( LUsername, LPassword);
//###########################################################
if res <> smc_ok then begin
LResult := TsngResult.Create( res, local_location_prefix+'Login_v1');
Result := LResult.toJSONObject;
LResult.Free;
exit;
end;
if not assigned( FUser) then
raise Exception.Create(local_location_prefix+'Login_v1: interner Fehler: User nicht initialisiert.');
try
JWT := TJWT.Create;
try
JWT.Claims.Issuer := 'SOPHA Server App';
JWT.Claims.Subject := FUser.Name;
( ... )
finally
JWT.Free;
end;
end;
function TAuthFunc.CheckUser(const Username, Password: string): integer;
var
LSession : IDBSession;
LUserEncoded : string; // der verschlüsselte Username
LPasswordEncoded : string; // das verschlüsselte Passwort
LUserlist : TObjectList<TUser>; // Userliste aus Datenbank
begin
LSession := TDBSession.Create( TdmDatabaseAuth(dmDatabase).DBConnection);
LUserEncoded := Username;
LUserlist := LSession.objManager.Find<TUser>
.Where(Linq['Name'] = LUserEncoded)
.List;
if LUserlist.Count <> 1 then begin
DoLog( loaWarning, 'User nicht gefunden!');
Result := smcAuth_UserNotExists;
exit;
end;
FUser := LUserlist[0];
LPasswordEncoded := HashKey( Password);
if FUser.Password <> LPasswordEncoded then begin
Result := smcAuth_WrongPassword;
exit;
end;
end;
result := smc_Ok;
end;
initialization
RegisterServiceType(TAuthFunc);
end.