I’m making a solution login for one application, and all is correct, both methods the login and the authenticator, but i have a doubt, and it’s when i succeful login want to redirect automatically to a form, in this case to make a report, but i don’t know how to make this.
The loggin button function
function login(event) {
var passValidation = true;
if (!userName) {
errorMessage = 'Please specify a user name';
passValidation = false;
}
if (!password) {
errorMessage = 'Please specify a password';
passValidation = false;
}
if (passValidation) {
if (!security.authenticate("bamboo_authenticator", "loginUser", [userName, password])) {
errorMessage = "No tenant found. Please check your password";
passValidation = false;
}
}
errorMessage = 'Login Failed';
return passValidation;
}
The authenticator
function loginUser(user, password) {
var result = false;
if (! (user && password)) {
application.output('Unexpected credentials received', LOGGINGLEVEL.DEBUG);
result = false;
}
var _query = 'SELECT *\
FROM users\
WHERE user_name=?\
AND user_password=MD5(?)'
var dataset = databaseManager.getDataSetByQuery("bamboo", _query, [user, password], 1);
if (dataset.getMaxRowIndex() == 1) {
result = true;
}
return result;
}
Both are modules of a principal solution, but i don’t know if i make anything wrong, any help?
If the login is successful the main solution onOpen method is executed and the “firstForm” is shown, you can put your logic in the onOpen method or simly use the firstForm property for that. On the other hand if the login is not successful the main solution is not loaded so the user can try to login again or can close the client.
You need to call the security.login() method in the authenticator when the password was validated OK.
When the authenticator is logged in, the normal client switches automatically from the login solution to the main solution.
I am upgrading a 5.2 app to Servoy 7 and I am switching to the new login system using a login and authenticator solutions.
I have a situation where I want to communicate to the main app a selection made by the user during login. I am finding that the main app can’t access formvars or globalvars in either the login or authenticator solutions, and nor can those solutions place data in the main app’s globals. I imagine that is done deliberately for security reasons. Below I explain what it is I’m trying to do, and perhaps someone has an idea how I can do it under the new security system.
In my 5.2 app, I use custom security with my own login form and my own users table. At solution startup, if I detect that the user is running in Developer, I ask the user which db server they want to log into (development, test or production) and I use databaseManager.switchServer() to switch database servers. All this happens before the user even logs in, and it works great.
Under the new security system I can ask the user what db they want to log into, and I can specify the selected db server in my SQL queries during authentication, and that works, but once the user is logged in I still need to do a switchServer() so that the main app targets the correct db. How can the main app find out which db server the user selected during authentication? As I said, I’ve tried passing the info on via formvars & globals and it doesn’t work. I have made the login solution a module of the main app and that has not helped.
that is strange! We fill a MEDIA global which is in the login-solution, with an array of properties, once we are logged in, we read that same global in the main solution, to set all kind of settings…
Are you really using security.login in the authenticator?
You are right - with the global declared in the login solution this works. I thought I had tried that but I guess I had only tried using a global declared in the main solution. Thanks for your help.
No, the login module is included in the main solution.
But yes, the login module has (by design) access to the module where the global variable “lives”…
In case anyone didn’t follow that, what Harjo and lwjwillemsen are doing is this:
Aside from the Login solution and the Main solution, they have a third solution in which they declare, among other things, global vars, and they make that third solution a module of both the Login solution and the Main solution. That way both solutions have access to the same global vars.
(I didn’t understand that at first but an brief offline exchange with Harjo cleared it up for me so I thought I’d share).