You are not logged in.
Hello,
I used the sample 14 (interfaced based services, Project14ServerExternal) and tried to add a new user at the startup of the server like this:
function CreateUser(const ServerL: TSQLRestServer; const strLogon, strDisplay, strPassword: String): Boolean;
var AuthUser: TSQLAuthUser;
AuthGroup: TSQLAuthGroup;
begin
AuthGroup := TSQLAuthGroup.Create(ServerL, 'Ident=''User''');
AuthUser := TSQLAuthUser.Create(ServerL, 'LogonName=''' + StringToUTF8(strLogon) + '''');
try
if Assigned(AuthUser) and (AuthUser.ID > 0) then
Result := False
else
begin
if not Assigned(AuthUser) then
AuthUser := TSQLAuthUser.Create;
AuthUser.LogonName := StringToUTF8(strLogon);
AuthUser.DisplayName := StringToUTF8(strDisplay);
AuthUser.PasswordPlain := StringToUTF8(strPassword);
AuthUser.GroupRights := AuthGroup;
ServerL.Add(AuthUser, True);
Result := True;
end;
finally
AuthUser.Free;
AuthGroup.Free;
end;
end;
I put the call to this function in the server programm directly after CreateMissingTables.
What I expected was that this would create a new user that is part of the group "User".
When I check in the sqlite database, the new user has GroupRights=49224560 in the AuthUser table, but I would have expected GroupRights=3 (since the new user should be in the "User" group with Id=3).
This new user is not able to call the interface methods, only when I change the GroupRights to 3 manually does the user account work as expected.
Thanks in advance for your help.
Offline
Change to this :
AuthUser.GroupRights := AuthGroup.IDValue;
Then it will be as expected
Best regards
Offline
Thanks for your answer, unfortunately, this does not work (it results in a compiler error "incompatible types" in Delphi).
AuthUser.GroupRights is of the type TSQLAuthGroup, not TID.
Best regards
Offline
Sorry I forgot you need to typecast it
AuthUser.GroupRights := TSQLAuthGroup(AuthGroup.IDValue);
For additional info check into class procedure TSQLAuthGroup.InitializeTable which will show you how the default groups and users are set up.
Last edited by pvn0 (2019-11-07 10:24:37)
Offline
Thank you very much for your help and the hint with InitializeTable.
I didn't think that such a cast would be allowed.
Best regards
Offline