You are not logged in.
Hi,
I'm having a hard time trying to store/retrieve additinal user info, I have an TSQLHttpserver which is serving interface based services, and because I'm consuming data from another TCP server didn't have the need for storing retrieving info from SQLite, the groups and users are stored in a SQLite file to take advantage of the mORMot authentication, this database is populated at server startup using the ORM, everything is working well so far, but I have the need to store the date time (just an example) of user login, so I created an inherited TSQLAuthUser class :
TSQLMyAuthUser = class(TSQLAuthUser)
protected
FLastAccess : TDateTime;
published
property LastAccess : TDateTime read FLastAccess write FLastAccess;
end;
Then added:
class function TSessionmORMot.sessionCreated(Sender: TSQLRestServer;
Session: TAuthSession; Ctxt: TSQLRestServerURIContext): boolean;
var
myUser: TSQLMyAuthUser;
begin
myUser := TSQLMyAuthUser(Session.User);
myUser.LastAccess := Now;
TSqlRestserver(sender).Update(myUser);
Result := False;
end;
restServer.OnSessionCreate := TSessionmORMot.sessionCreated; // restServer is TSQLRestServerDB
Seemed to work fine, I can see populated the field LastAccess on the db file, but after two different users log in I have an error like this :
20170201 04062437 EXC ESecurityException {"Message":"Invalid TAuthSession.Create(TSQLRestRoutingREST,TSQLMyAuthUser)"} at 0054EB90 stack trace ...
Obviously that doesn't seem to be the right way, I was hoping that I would have access to the new field on my Interface based services with the following code ( recommendations are welcome ) :
var
context : TServiceRunningContext;
user : TSQLMyAuthUser;
theDate : TDateTime;
Begin
context := CurrentServiceContext;
user := TSQLMyAuthUser.Create(context.Request.Server, context.Request.SessionUser);
theDate := user.LastAccess;
End
So can a mORMot guru give me some advice on how to store safely the additional data and how to retrieve it from a service ?
Thank you all
Last edited by moctes (2017-02-01 04:31:54)
Offline
Well this was kind of urgent and I know everybody here are pretty busy people, I passed the task to the existing TCP (non mormot) server and stored the user info on a legacy database, but STILL it would be nice if someone can enligthen me on how can one work with the SQLite database from SERVER code and in particular in this use case, I did some tests from client code and is pretty easy but not in this case, I couldn't use a TSQLRestclient in sessionCreated event because, well the TSQLRestclient needs to authenticate and that would fire sessionCreated again and that give us an ugly loop of events.
Regards
Offline