You are not logged in.
Pages: 1
Hi all,
I am looking into the authentication mechanism of mORMot. Just checking if I am on the right track.
For this purpose I have modified Sample 4.
I have put 2 Tedit and a Tbutton component to the form of the server. When the button is clicked a new user is added
to the database. Below is the code snippet in the onclick eventhandler of the button.
procedure TForm1.Button2Click(Sender: TObject);
var
aNewUser:TSQLAuthUser;
begin
aNewUser := TSQLAuthUser.Create;
aNewUser.PasswordPlain := edit2.Text;
aNewUser.LogonName := edit1.Text;
aNewUser.GroupRights := TSQLAuthGroup.Create(DB, 'Ident=?', ['User']);
if DB.Add(aNewUser, true)<>0 then
showmessage('User '+ aNewUser.LogonName + ' added.');
end;
When checking project04server.db3 with SqliteMan, I see that a corresponding record has been created in table AuthUser.
Unfortunately, when starting the client (in Delphi XE) an EOSException is raised with message 'System Error. Code 12002' at
TSQLHttpClient(Form1.Database).SetUser('wai','test');
When I try to delete the new record in table AuthUser with SqliteMan I get a notification that I cannot commit because a pending
transaction is in progress.
What am I missing? Remarks and tips much appreciated.
Thanks,
Wai
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
Main problem with your code is that the GroupRights property should not contain a class instance, but an integer ID.
See the SAD pdf about how TSQLRecord properties are handled.
You should set GroupRights with the ID.
Something like this:
aNewUser.Grouprights := pointer(DB.MainFieldID(TSQLAuthGroup,'User'));
Then do not forget to call aNewUser.Free.
Offline
ahaa, so that is why the field Grouprights in table authuser has such a big number instead of the value 3. (Learned something new again, usage of MainFieldID)
allright, so now i have made the suggested changes and now I see the value 3 in the grouprights field.
The new code looks like:
procedure TForm1.Button2Click(Sender: TObject);
var
aNewUser:TSQLAuthUser;
begin
aNewUser := TSQLAuthUser.Create;
try
aNewUser.PasswordPlain := edit2.Text;
aNewUser.LogonName := edit1.Text;
aNewUser.DisplayName := edit1.Text;
aNewUser.Grouprights := pointer(DB.MainFieldID(TSQLAuthGroup,'User'));
if DB.Add(aNewUser, true)<>0 then begin
showmessage('User '+ aNewUser.LogonName + ' added.');
end;
finally
aNewUser.Free;
end;
end;
Now the issue is that when I add a new user to the database and in the client I use SetUser('User', 'synopse') everything works according to plan. But, when
I use SetUser('wai', 'test') I cannot add any data with the client. When running the client in Delphi I see that an EOSError (message 'System error. Code 12002') occurs.
Tracing the call I see that this happens at
lineno 21572. aNonce := CallBackGetResult('auth',['UserName',U.LogonName]);
in unit mORMot.
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
Ah, sorry. I was not clear on which side it is. This is on the server side.
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
When running only the executables, everything is fine. When running the client in IDE, the EOSError (Systemerror, Code 12002) appears.
Last edited by wai-kit (2013-05-30 15:31:56)
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
The URI is registerer in :
procedure TForm1.FormCreate(Sender: TObject);
begin
Model := CreateSampleModel;
DB := TSQLRestServerDB.Create(Model,ChangeFileExt(paramstr(0),'.db3'),true);
DB.CreateMissingTables(0);
Server := TSQLHttpServer.Create('8080',[DB],'+',useHttpApiRegisteringURI);
Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
end;
Right?
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
By regisrer url AB mean call to THttpApiServer.AddUrlAuthorize under windows administrator user. See here http://synopse.info/forum/viewtopic.php?id=989 and in SAD by keyword AddUrlAuthorize
Offline
hi MPV, thanks for clarifying.
I have noticed that the EOSError only occurs when running 'this' Project04client in Delphi and not when running the executable. When I run a Project04client from
a different sample then also no problem.
I then decided to remove Project04Client from the project group, delete all files generated by Delphi (.dproj, .res) and added the project back to the project group.
And then no problem ...
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
RTFM!
Indeed RTFM (or RTFF ), if i knew what to look for. I search in the SAD for 'http.sys', 'authorize', but not AddUrlAuthorize. Unfortunately,
my pdf reader cannot do partial searches.
This brings me to these questions:
- when using mORMot authentication scheme, do I have to use sqlite3 for persistence?
- is it also possible to use an external database for user/pw persistence?
It might be that these questions has already been answered, so feel free to RTFM me .
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
Some answers:
- you can use fast in-memory TObjectList storage - some samples do it that way - you are not tied to use SQLite3 for persistence;
- you can use external database access (e.g. FireBird, Oracle, MSSQL, Access...) for persistence (but SQLite3 engine is needed as core).
It is of course already answered in the f.... SAD pdf.
Offline
Pages: 1