How Exactly Do You Use security.login()?

That is at least what I did… Really it works!

I believe you! Unfortunately, I still have the same problem. Not sure what else to do.

You also have an onShow and on startup method that I took out.

Make your login form as clean as possible as well as the solution. Now check that a login is required and check that the solution works as expected. Rebuild the solution now to see what creates the issue.

Hi Marcel,

Make your login form as clean as possible as well as the solution.

That’s good advice. Unfortunately, even after simplifying my sample solution per your instructions, I still have the same problem, which is that the Login Form setting seems to be ignored. I’m not sure I can make my sample solution any simpler. Very frustrating. I even tried removing any third-party plugins. Maybe I need to reinstall Developer.

Thanks again for all of your help.

Sean, I simply don’t understand what is happening.
I took your solution, did as described and it worked. Took about 5 minutes!

Attached is the adjusted version of your sample. Please don’t forget to check the security/‘Solution login required’ checkbox…

Marcel,

I did not have that security checkbox checked :oops: In the thread that I linked to in my second post, one of the developers had unchecked this checkbox, and I assumed I should have done the same. My mistake.

I still have problems, though. After logging in successfully, I am expecting to go to the First Form, but nothing happens, so I’ll play with your version later today.

Well, glad the first thing is solved. Now the next: In your sample you do a check on the correct login but you did not add a method to go the first form…

Now the next: In your sample you do a check on the correct login but you did not add a method to go the first form…

Hmmmm…once again I get in trouble for assuming things. Earlier in this thread Jan Blok said:

after loginForm you will pass on to the firstForm

I interpreted this to mean that I would go to the First Form automatically, instead of using something like forms.first_form.controller.show().

Well, I would assume that too but… On the other hand, when you do your check manually how would Servoy know when you are ready to hand over to the nex form?

Maybe a nice question for Jan Blok?

Good point. I assumed (there I go again) that after executing the method that contained the security.login() fx, Servoy would then “know” to show the First Form and execute the onOpen method, but it’s a simple matter to add those steps manually.

Thanks Sean for that very helpful piece of code:

chartpacs:
I think the following code works OK:

var username   = globals.login_username;

var passwd = globals.login_password;

var userID = security.getUserId(username);
var ok = security.checkPassword(userID, passwd);
var userGroups = null;

if (!ok)
{
application.beep();
plugins.dialogs.showWarningDialog(“Red Alert”, “Your login is incorrect.”, “OK”);
}
else
{
userGroups = security.getUserGroups(userID); // returns dataset (group id, group name)
security.login(username, userID, userGroups.getColumnAsArray(2)); // “officially” logging in
plugins.dialogs.showInfoDialog(“Woohooooooo!”, “Your login is CORRECT!”, “OK”);

// do startup stuff here

}




The code in this thread gave me a head start:
<a class="postlink" href="http://forum.servoy.com/viewtopic.php?t=2148">http://forum.servoy.com/viewtopic.php?t=2148</a>

However, I must ask: why do we need to specify both the username and the userUID when using security.login ? If we specify one, isn’t the other just a corresponding value anyway ? :? I don’t really see why we would have to query for the userUID, since we have already provided the username using a global …

And why can’t we just pass on the password as an argument to security.login (since we have another global for that), instead of using the security.checkPassword bit ? Wouldn’t that simplify things a lot ?

Also, why do we need to get the list of groups for the specified user ? Does Servoy need to know this in advance before logging a user in ? I would’ve thought that, since this is part of the solution security already, Servoy could automatically check to which groups a user belongs to, just like when we don’t use a login form but the ‘regular’ Servoy security dialog ; otherwise, what is the usefulness of getting the groups list ‘manually’ ?

Sorry, lots of questions for a Friday morning, but hey, I’m on a learning curve here … :wink:

Thanks for your input,

Ben

Ben,

The security.login() method may also be used when you want to use a non-servoy authentication method (for instance LDAP).

In that case the servoy does not maintain the users and passwords.

However, I must ask: why do we need to specify both the username and the userUID when using security.login ? If we specify one, isn’t the other just a corresponding value anyway ? Confused I don’t really see why we would have to query for the userUID, since we have already provided the username using a global …

This may also be your external auth system id, used for logging

And why can’t we just pass on the password as an argument to security.login (since we have another global for that), instead of using the security.checkPassword bit ? Wouldn’t that simplify things a lot ?

In that case servoy does not manage the password

Also, why do we need to get the list of groups for the specified user ? Does Servoy need to know this in advance before logging a user in ? I would’ve thought that, since this is part of the solution security already, Servoy could automatically check to which groups a user belongs to, just like when we don’t use a login form but the ‘regular’ Servoy security dialog ; otherwise, what is the usefulness of getting the groups list ‘manually’ ?

when servoy does not manage the users you have to specify the group(s)

So basically, the security interface is applicable for both internal and external auth systems.

Rob

Thanks for that answer Rob, I hadn’t considered external authentification scenarios… Now it all makes sense.

Cheers,

Ben

To continue on the same ‘security.login()’ subject:

Since Servoy doesn’t presently allow setting the locale ‘on the fly’, I’m thinking of creating a ‘Login’ solution (without the ‘Solution login required’ check), where the user enters (in globals) their name, password and (optionally) chooses the solution they want to use. [This solution would also contain a table with users, passwords, the chosen/preferred locale and (optionally) a list of available solutions for each user.]

After verifying that the username and password are correct, I would like to pass that information (as well as the locale) as arguments to start and login to the other solution chosen previously in the correct language. [This other solution would also have the corresponding username and password entered in the ‘Login’ solution, of course.]

Am I right in assuming that this is feasable in a relatively easy fashion? Does anyone have an example handy that shows the correct way of passing the arguments to obtain this result?

Thank for ‘showing me the way’, as old Rafiki would say! :)

Ben

Also, refering to the Servoy Developer User’s Guide (the notes on pages 450 and 451), I was wondering what happens in the case where User A in module_A belongs to a Group that has Admin access, but to a limited-access Group in module_B. Since the combination of Groups spans multiple modules and the entire solution, and that if a user is in multiple groups the highest access rights will be applied to them, does this mean that User A will finally have full access to all modules, since he is defined that way in one of them? Or is the access rights promotion done on a module by module basis?

Hope this is clearly stated… :?

TIA,

Ben

Regarding your first question, I don’t believe you can switch from one solution to another programatically as you are hoping to do.

Regarding your first question, I don’t believe you can switch from one solution to another programatically as you are hoping to do.

I don’t know if I get this right, but that should be possible by calling

application.closeSolution(nextSolutionToOpen)

I stand corrected. I note that closeSolution() also lets you pass a starting method and arguments to the new solution so that should get you where you are trying to get Benoit.

Use i18n.setLocale() to set the locale programatically.

Thanks for the information, guys! I think I’ll try to apply this principle by modifying your login solution, Adrian (the one you showcased during the last Servoy Virtual User Group) - when you make it available to us. :wink:

Now, I would really appreciate it if someone could clarify my other question about group promotion…

Sincerely,

Ben

Anyone care to elaborate on group promotion when using modules?

What is

group promotion

?