Login error

Questions, tips and tricks and techniques for scripting in Servoy

Login error

Postby nromeou » Fri Oct 01, 2010 9:38 pm

Hi all,
I´m working on a new solution and trying to make a login on 5.2.2.
So i have a form in the login solution that calls a global method
Code: Select all
security.authenticate("Authenticator",globals.login(varCuit,varClaveFiscal), argumentsArray);
from the authenticate solution.
The error that appears is: Cannot find function login

My question is, whats the problem if the method is recognized when im writing the code
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: Login error

Postby ptalbot » Sat Oct 02, 2010 7:37 am

First, the "security.authenticate()" method is using a String as second argument, which is the name of a method in the Authenticator module of you solution, (and there's no need to prefix this method name with "globals." since your Authenticator module should really have nothing but globals anyway!).

So your method should read:
Code: Select all
security.authenticate("Authenticator","login", [varCuit,varClaveFiscal]);


Then, you don't call this from the Authenticator module itself, but from your Login module (usually from the login form of your Login module).

This is how the security is really 'enhanced':
Because you cannot access your Authenticator module differently than using the security.authenticate() method.

Also note that authenticate() returns an Object (meaning that it can be anything, and or example it can be a JSObject where you can put lots of information to be retrieved by the Login module - think of creating a User object, that will contain all relevant informations, like user ID, groups, name, etc.)
And finally, note that you can put many globals in your Authenticator module that will all be called the same way.

Hope this helps,
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Login error

Postby nromeou » Mon Oct 04, 2010 8:56 pm

yea works tks
But I want to check userName and password and i have a data base where userName and password are located in a table. How can i check that password from the database table?
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: Login error

Postby rgansevles » Mon Oct 04, 2010 9:32 pm

nromeou,

When your user is not logged in yet, he/she will have only access to the login solution and no database access.
But when you call a method in the authenticator (using security.authenticate()), the authenticator code is executed in the server in the authenticator solution and this solution has full access to the database.

So in the global 'login' method you can use foundsets, sql, etc to validate the username/password.
If valid, you should call security.login() in the authenticator, this will be picked up by the server and will trigger the client solution to load the main solution.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Login error

Postby nromeou » Wed Oct 06, 2010 9:20 pm

I have 2 diferent login methods. 1 normal to start the program and another for users who wants to register and the next error is shown...
Borrow prepareStatement from pool failed
like if one login method was calling the other

tks for the help
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: Login error

Postby rgansevles » Thu Oct 07, 2010 10:43 pm

nromeou,

We will need some more info, like a stack trace from the logs or the smart client java console.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Login error

Postby nromeou » Tue Oct 12, 2010 9:33 pm

the console does not help me too much, the only message shown is:
Borrow prepareStatement from pool failed at loginA
but this is the code:
Code: Select all
function loginA(userName, password) {
   
    if (userName == '123' && password == '123456')
        return security.login(userName, security.getUserUID(userName), ['Administrators'])
    var queryUN = 'select id, clave from tabla1 where userName = ? and password = ?'
    var args = new Array()
    args[0] = userName
    args[1] = password
    var dataset = databaseManager.getDataSetByQuery('server',queryUN,args,1)
    if(dataset.getMaxRowIndex()==1)
    {
        globals.globalUsername = userName
        return security.login(userName, security.getUserUID(userName), ['Administrators'])
    }
   
    return false;
}


the error point me the line of:
Code: Select all
var dataset = databaseManager.getDataSetByQuery('munibrown',queryUN,args,1)


tks for the help, really appreciate
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: Login error

Postby rgansevles » Tue Oct 12, 2010 10:44 pm

nromeou,

Check the server log, it will contain a stack trace.

This is running in the authenticator solution, I assume?
If so, setting of the global does not do anything, the authenticating client in the server will be destroyed immediately after this call.

Rob

Btw, it is better practice to store passwords encrypted in your db and not in plain text.
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL


Return to Methods

Who is online

Users browsing this forum: No registered users and 6 guests

cron