Hello you all.
Can any one explain a bit how to use the loginForm in a mobile solution?
Cheers,
Hello you all.
Can any one explain a bit how to use the loginForm in a mobile solution?
Cheers,
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.
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,
Juan,
Did you try out the mobile sample, it uses logging in?
Rob
Hi Rob.
It does but not with a custome login form
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
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)
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.
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?
I use a call like this in my mobile client solution
security.authenticate([sUsername, sPassword]);
And a call like this in my mobile service solution on my offline_data form
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.
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())
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.
security.authenticate([fvUsername, fvPassword]);
forms.main.controller.show();
jcompagner:
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
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:
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.
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
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
JD, I’m going to save you a little bit of time if you are developing a Servoy Mobile application by saying that you should immediately start reading up on jquery and jquery mobile, how they work, and what is possible. We’ve learned how to successfully get out of the Servoy box and this information is pretty darn vital. I’m hoping to write-up a couple of helper posts on Servoy Mobile for the lost sheep out there because I was a lost for a bit on how to make things work like I wanted to and there isn’t much info here or in the Servoy documentation that will get you to where you need to go.
mattfrizzell:
I’m hoping to write-up a couple of helper posts on Servoy Mobile for the lost sheep out there because I was a lost for a bit on how to make things work like I wanted to and there isn’t much info here or in the Servoy documentation that will get you to where you need to go.
+1 Looking forward to that!
mattfrizzell:
I’m hoping to write-up a couple of helper posts on Servoy Mobile for the lost sheep out there because I was a lost for a bit on how to make things work like I wanted to and there isn’t much info here or in the Servoy documentation that will get you to where you need to go.
+1
+1 Thanks in advance