I saw something similar yesterday with the Appery user login function on a server code script as it happens and I'm working out how to make it work for me. If I find anything useful I'll post it
here.
I saw something similar yesterday with the Appery user login function on a server code script as it happens and I'm working out how to make it work for me. If I find anything useful I'll post it
here.
Terry try this way if it suits. My server code script looks like this:
code
var username = request.get("username");
var password = request.get("password");
var userLoginInfo = {};
var result = {};
try {
token = DatabaseUser.login(RTdatabaseId, username, password);
var user = DatabaseUser.retrieve(RTdatabaseId, token._id, "employee");
userLoginInfo = _.extend(user,token);
result = userLoginInfo;
}
catch (e) {
result = {"employee":userLoginInfo};
}
response.success(result, "application/json");
/code
So I always get back success.data.employee which is populated if it was successful or an empty object {} if it failed.
Then in my JS code I test for the empty object like this:
code
var userInfoData = success.data.employee;
if (Object.getOwnPropertyNames(userInfoData).length === 0) {
[alert the user, etc.]
}
/code
Terry, please check on the network tab your request parameters and server response. I think, your service returns header code=200 everytime, even it is wrong request
I am actually getting an error code of 400 Bad Request when the service is called from the app. but the service test works correctly returning an error code of 401 Unauthorized
Could you disable the proxy and send us the same screenshot again? Also, please check, does that request work in API Express?
using API express, I get the following response for a valid login:
pre{
"BODY": {
"id": 4,
"firstname": "",
"lastname": "",
"businessname": "",
"gender": "",
"mobile": "",
"email": "",
"streetaddress": "",
"address2": "",
"town": "",
"county": "",
"postcode": "",
"adinumber": "333333",
"hourlyrate": 0,
"makeandmodel": "",
"transmission": "",
"fueltype": "",
"areascovered": "",
"radius": 0,
"bankdetails": "",
"monziaregistered": 0,
"monziapassword": "",
"striperegistered": 0,
"stripereference": "",
"invoicingrequired": 0,
"logourl": "",
"lastinvoicenumber": 0,
"publicdiary": 0,
"owdextensions": 0,
"databaseuserid": 17,
"token": "Basic MzMzMzMzOnJhdmluZQ=="
},
"HTTP_RESPONSE_HEADERS": {
"Transfer-Encoding": "chunked",
"Date": "Thu, 03 Nov 2016 16:43:44 GMT",
"Expires": "0",
"Keep-Alive": "timeout=3, max=170",
"Set-Cookie": "PHPSESSID=7200c8f236364f99948e6b6c8be81603; path=/",
"Content-Type": "text/plain",
"Connection": "Keep-Alive",
"Server": "Apache",
"Pragma": "no-cache",
"Cache-Control": "no-cache, must-revalidate"
},
"HTTP_RESPONSE_CODE": 200
}/pre
and the following for an invalid login:
pre{
"BODY": {
"error": {
"code": 401,
"message": "Unauthorised"
}
},
"HTTP_RESPONSE_HEADERS": {
"Transfer-Encoding": "chunked",
"Date": "Thu, 03 Nov 2016 16:46:12 GMT",
"Expires": "0",
"Keep-Alive": "timeout=3, max=170",
"Set-Cookie": "PHPSESSID=01d286fdcb97682892891bfd2eab9907; path=/",
"Content-Type": "text/plain",
"Connection": "Keep-Alive",
"Server": "Apache",
"Pragma": "no-cache",
"Cache-Control": "no-cache, must-revalidate"
},
"HTTP_RESPONSE_CODE": 401
}/pre
which is as I was expecting, so yes, it works there
Please clarify, does it work, do you need further assistance?
no I don't have it fixed, only that the API Express works the way it should. I haven't been using API express, so, if you think i should use that instead of creating my own services in the app, can you point me to some documentation / videos which will help me understand how to use API express correctly?