Page 1 of 2

Login Form

PostPosted: Wed Oct 09, 2013 5:00 pm
by jasantana
Hello you all.

Can any one explain a bit how to use the loginForm in a mobile solution?

Cheers,

Re: Login Form

PostPosted: Wed Oct 16, 2013 7:02 am
by johann.agcanas
I'm gonna bump this for interest. Since the login method is through a form rather than a login solution as per normal Servoy, I assume it's implemented differently ? Documentation on a custom mobile login form doesn't seem to exist at all.

Re: Login Form

PostPosted: Wed Oct 16, 2013 9:36 am
by jasantana
Hi Johan.

You are right, the security.authenticate() method works slightly different. You do not need to send the authenticator solution nor the method, just the user name and password. Like security.authenticate(null,null,userName,userPwd).

But to be honest it does not work or I'm missing something because I'm not able to authenticate. Maybe some servoy gut can give us llight on this.

Cheers,

Re: Login Form

PostPosted: Wed Oct 23, 2013 9:53 am
by rgansevles
Juan,

Did you try out the mobile sample, it uses logging in?

Rob

Re: Login Form

PostPosted: Thu Oct 24, 2013 10:02 am
by jasantana
Hi Rob.

It does but not with a custome login form

Re: Login Form

PostPosted: Thu Oct 24, 2013 2:39 pm
by pbakker
I just tested and using a custom login for is straight forward: create a form and set it as the value for the loginForm property on solution level.

On the login form have whatever you need to collect the username and password from the user and then fire a call to security.authenticate(null, null, ['theUserName", "thePassword"]).

That should do the trick. In order to NOT get a alert saying that authentication failed on first launch, make sure to set the mustAuthenticate property on the Mobile solution to true. Without this setting it will still work, you just get an unneeded alert.

In the Service Solution you must of course implement the ws_authenticate method on the offline_data form or else no authentication is needed at all.

Paul

Re: Login Form

PostPosted: Wed Oct 30, 2013 5:53 pm
by jdbruijn
i've just tried to modify my mobile solution to use a custom login form.
Running in chrome I get the new login form, and I can login (the ws_read method is triggered) but right after that I get a login popup from the browser and I cannot get past this.
My mobile solution is set to mustAuthenticate (it used the default login previously and that worked correctly)

Re: Login Form

PostPosted: Wed Nov 27, 2013 5:34 pm
by jcompagner
i guess the user/password combination is not correct, and then you are bumping against a browser (i guess you use chrome?) bug.
Because if a 401 status code is given back then for an ajax request, the browser takes over and shows its own login dialog.
The browser shouldn't do that it should give use the error callback that authentication fails. I think they are working on this.

Re: Login Form

PostPosted: Mon Mar 10, 2014 5:25 pm
by marbeisol
Hello everyone!

I have a simple mobile app that asks for customer ID and retrieves his information from a Database, I created a custom login form and added the follow code:
var bResult = security.authenticate(null, null, [sUser,sPass])
if(!bResult){
plugins.dialogs.showWarningDialog("Test","User or password incorrect.")
exit()
return;
}
When runs the app on the Servoy Mobile, and I enter with a customer ID and password correct, I'm getting the message "User or password incorrect." then retrieves the information the customer ID. Otherwise when I enter with a customer ID or password incorrect I'm getting the same message, however the app retrieves other message " Authentication failed "
I am using Servoy Mobile Version: 7.3.0
Any ideas about how to make a user and password validation?

Re: Login Form

PostPosted: Mon Mar 10, 2014 11:05 pm
by mattfrizzell
I use a call like this in my mobile client solution

Code: Select all
security.authenticate([sUsername, sPassword]);


And a call like this in my mobile service solution on my offline_data form

Code: Select all
function ws_authenticate(sUser, sPassword)
{
   var sUserID = security.getUserUID(sUser);
   if (!security.checkPassword(sUserID, sPassword)) {
      return false;
   }
   
   var oRetval = {
      username : sUser,
      userid : sUserID
   }
   return oRetval;
}


The only other thing you must make sure is correct are that your users are setup properly. Other than that, there isn't much going on to make this work.

Re: Login Form

PostPosted: Tue Mar 11, 2014 4:22 pm
by jcompagner
in the mobile solution authenticate() call doesn't return anything
It can't return anything because the only thing it really does is set the user/pw combination ready for the sync/load data call to the server
All the calls to the server are also async (so using callbacks) to that method really can't return it directly because there is no direct call where we can wait for/on

If you have a custom login form that was shown as the result of a sync/loaddata call then when you call authenticate it will try to login and get data from the server
if login fails your login form is "shown again" and the user can fill in the right credentials and it can try again (again a call to authenticate())

Re: Login Form

PostPosted: Tue Mar 11, 2014 4:32 pm
by mattfrizzell
Yes, that was a bad copy and paste my actual method in the mobile solution is the following, I don't know what tab on my computer I grabbed that other bit. :oops:

Code: Select all
   security.authenticate([fvUsername, fvPassword]);
   forms.main.controller.show();

Re: Login Form

PostPosted: Mon Mar 31, 2014 8:23 pm
by jd2p
jcompagner wrote:in the mobile solution authenticate() call doesn't return anything

Hi everyone! I was looking through this thread as I'm getting accustomed to servoy mobile. I was wondering, if this is the case, then how can one manage the message that is displayed to the user? Like saying that user/pwd is incorrect instead of letting the default servoy msg to appear?
Thanks!
JD

Re: Login Form

PostPosted: Tue Apr 01, 2014 10:03 am
by vschuurhof
What you also can do is to perform a manual web service call for authentication before letting Servoy synchronizing the data. I have created a GET request like this:

Code: Select all
function authenticate(callbackSuccess, callbackError) {
   scopes.ui.showLoading(null, i18n.getI18NMessage('servoy.mobile.authenticating'));
   
   $.ajax({
      type: "GET",
      url: scopes.globals.serverURL + "/servoy-service/rest_ws/dss_mobile_service/authenticate/1/list",
      dataType: "json",
      async: true,
      timeout: 5000,
      beforeSend: function(header) {
         header.setRequestHeader("Authorization", "Basic " + scopes.encryption.encodeBase64(scopes.globals.username + ':' + scopes.globals.password));
      },
      success: function(result) {
         scopes.ui.hideLoading();
         
         callbackSuccess(result);
      },
      error: function(httpRequest, status, error) {
         scopes.ui.hideLoading();
         
         callbackError(httpRequest, status, error);
      }
   });
}


On server level, I created a form called "authenticate" which only authenticates the user. From there I return an object including a variable called "successful". Based on this I can determine whether authentication has been succesful and can even display a specific message to the user which I return in the same object. When successful I simply execute Servoy's synchronization mechanism.

Re: Login Form

PostPosted: Tue Apr 01, 2014 6:30 pm
by jd2p
Wow.. nice! I'm sorry, what is $.ajax function and how do you know about callback and those other functions?? I've been using restful WS on Servoy for a while based on the help file.. where did you learn all that? Thanks! I'll also try the manual webservice call you suggest.

JD