I’ve got a solution with custom login code. It all works great locally in developer, but when I get it on my server “security.login” is returning false.
I can’t figure out why. No errors thrown or logged.
I’ve added debugging code and can confirm than the right values are getting passed to security.login – but it just fails silently on the server.
It tries built-in Servoy users first, and that works on both developer and on the test server. On the test server, the built-in users also work, but the db users fail. The code makes it through to the “security.login” call, and calls it but it returns false.
Not sure what else to look for.
var userId = security.getUserId(login);
var ok = false;
var groups = [];
if(userId)
{
var ok = security.checkPassword(userId, password);
var groups = [];
if(ok)
groups = security.getUserGroups(userId).getColumnAsArray(2);
}
if(!ok) // try user logins
{
var q = "SELECT user_id FROM users WHERE user_login = ?";
var fs = databaseManager.getFoundSet('cfbs','users');
fs.loadRecords(q, [login]);
if(fs.getSize()==1)
{
var user = fs.getRecord(1);
if(user.is_active != 1)
{
application.beep();
errMsg = 'Login disabled.';
return;
}
if(globals.security_hashPassword(password) != user.user_password)
{
application.beep();
errMsg = 'Invalid password.';
return;
}
userId = user.user_login;
for(var ix=1; ix<=user.users_to_user_groups.getSize(); ix++)
{
var ug = user.users_to_user_groups.getRecord(ix);
groups.push(ug.group_name);
}
ok = true;
}
else
{
errMsg = 'Login not found.';
return;
}
}
if(!ok)
{
errMsg = 'Invalid login/password';
return;
}
errMsg = '';
globals.dialog_info(login + "|" + userId + "|" + groups);
if(!security.login(login, userId, groups))
errMsg = 'Error logging in, please try again';
else
{
application.output("LOGIN: " + login + "|" + userId + "|" + groups);
globals.cfbs_model_currentuser_login = login;
}