Having some issues creating a login solution

Hello again,

First of all, sorry in advance for my multiple posts with beginner questions, still trying to get the hang of the feature-filled API of Servoy.

I first created an unsecure login form that just checked the Username and Password in the DB, and then proceeded.
After looking around though, it seems I should be using the security functions that come with Servoy.

I have written some code to try and perform this task:

function loginToForm(event){
var userUID = security.getUserUID(userNameField);
var userGroups = security.getUserGroups(userUID);
var checkPW = security.checkPassword(userUID,passWordField);

if(checkPW){
security.login(userNameField,userUID,userGroups);
application.output(‘logged in’);
}
else {
application.output(‘failed login’);
}
}

userNameField and passWordField are tied to text areas on the form where the user inputs their information.

I am getting an error on the security.login line, saying I cannot provide String,String,JSDataSet, and instead to provide String,Object,Array.
As you can tell I am using the supported methods that come with the Security property. Why won’t the provided methods fit together? Shouldn’t security.getUserUID return the UID in a manner that would fit the security.login method?

Thanks in advance for any assistance!
Chris

Hi Chris,

actually the ‘getUserGroups’ function is returning a dataset.
from that dataset you need to get the correct column (thought this is column 2) as an array:

/** @type {Array<String>} */
var groupArray = userGroups.getColumnAsArray(2);

Then use the groupArray to pass to the login function.

Hope this helps

mboegem:
Hi Chris,

actually the ‘getUserGroups’ function is returning a dataset.
from that dataset you need to get the correct column (thought this is column 2) as an array:

/** @type {Array<String>} */

var groupArray = userGroups.getColumnAsArray(2);




Then use the groupArray to pass to the login function.

Hope this helps

Thanks for the assistance!
I had already tried the getColumnAsArray(2), tho what fixed it is adding the /** @type {Array} */
I was under the impression that doc comments weren’t programatically relevant, but it seems I am wrong.

EDIT: I noticed when I launch the smart client it’s automatically logging me in to some “dummy-login”. How am I supposed to test out my own login solution if the system keeps auto logging me in dummy-login?

Why would the security.login() return false?
I have traced each value I am passing into the function, which has the correct username, UUID, and groups, but it just returns false no matter what.
What could be causing this?
Thanks,
Chris