1 (edited by asawyer13 2020-11-29 18:03:46)

Topic: Use custom login with Roles

I understand that as of now, the login form can't be changed if I am using Roles.

Is it possible to use Roles, but create my own login form???

Somehow the app would have to open my login form, rather than the default. Is this possible?

I don't know what my login form would have to do to still allow the use of Roles..

Is there a better way?

Thanks
Alan

PS. The reason I want to create a custom login is that I want to add a forgot password and possibly a registration option to the login screen.

2 (edited by CDB 2020-11-29 18:58:15)

Re: Use custom login with Roles

asawyer13,

It is possible to add extra buttons and edit boxes to the inbuilt login form, see below.  You could also create your own two user and roles table and then you are free to do whatever you want.

Another way you could do this is to enable users and roles - this will create the database and then disable the feature. This would create the database tables for users and roles, however you will be completely responsible for not only the login form but also for checking roles etc.


To add to the current form this is what you need to do, my example is placing a label. Note positioning items is through trial and error.

In the default begin....end place code similar too.


lbYourLabel := TLabel.Create(frmdbCoreLogin); //Whatever component must have component.create(frmdbCoreLogin)
  lbYourLabel.Left := 113;
  lbYourLabel.Top := 170;
  lbYourLabel.Width := 300;
  lbYourLabel.Height:= 15;
  lbYourLabel.Margins.Top :=10;
  lbYourLabel.Margins.Left :=10;
  lbYourLabel.Margins.Right :=10;
  lbYourLabel.Margins.Bottom := 10;
  lbYourLabel.Parent := frmdbCoreLogin;  //component.parent must be attached to frmdbCoreLogin
  lbYourLabel.Wordwrap := true;
  lbYourLabel.Caption := 'image copyright free from unsplash.com/photos/jXd2FSvcRr8';
  lbYourLabel.Visible := True;

  frmdbCoreLogin.Caption := 'MY Login form';
On a clear disk you can seek forever

3 (edited by asawyer13 2020-11-30 01:29:49)

Re: Use custom login with Roles

CDB,
Thanks

Please excuse my ignorance but when you say "in the default begin....end place code similar too."

what do you mean?? Where do I put it in my script file. I have much to learn.

And if I create a couple buttons, how can I program the OnClick?

Alan

Re: Use custom login with Roles

Alan,

If you look at your script file before you have entered everything you'll see the following.

var
  sHello: string;  // delete this

procedure HelloWorld (s: string);  //delete this procedure, you'll never use it.
begin
  ShowMessage(s);
end;

begin
  // just for example 
  sHello := 'Script said hello!';    //here is where you put the code for your login form if using the default form.
  HelloWorld(sHello);
end.

So here here is what your script file will look like before you start adding your own events etc.

begin
  lbYourLabel := TLabel.Create(frmdbCoreLogin); //Whatever component must have component.create(frmdbCoreLogin)
  lbYourLabel.Left := 113;
  lbYourLabel.Top := 170;
  lbYourLabel.Width := 300;
  lbYourLabel.Height:= 15;
  lbYourLabel.Margins.Top :=10;
  lbYourLabel.Margins.Left :=10;
  lbYourLabel.Margins.Right :=10;
  lbYourLabel.Margins.Bottom := 10;
  lbYourLabel.Parent := frmdbCoreLogin;  //component.parent must be attached to frmdbCoreLogin
  lbYourLabel.Wordwrap := true;
  lbYourLabel.Caption := 'image copyright free from unsplash.com/photos/jXd2FSvcRr8';
  lbYourLabel.Visible := True;

  frmdbCoreLogin.Caption := 'MY Login form';
end.
On a clear disk you can seek forever

Re: Use custom login with Roles

CDB, Thanks but getting an error.

Basically I want to duplicate what you've done as a starting point to make sure I understand.

I'm actually using the Library example app, but when I add your code I get a red line on the first line of your code.

I put it between and Begin and End.

I'm new to MVD so it might be something stupid that I'm doing wrong, but I sure don't see it.

Do you know if I'm successful in getting something like a button to show, how I would handle the OnClick event?

6 (edited by CDB 2020-12-01 11:06:23)

Re: Use custom login with Roles

A demo provided.   I forgot to declare the label above, however the code attached works.  The user and password is the default admin/admin

Post's attachments

Attachment icon asawyer.zip 336.79 kb, 292 downloads since 2020-12-01 

On a clear disk you can seek forever