Correction:
I am NOT sending back the userid code for some strange reason. I am using the unmodified code from the SDK examples for “user-service”. The problem is explained below.
TL;DR : The example code provided with the SDK has a bug in it.
I have setup my “User” table as :
email - required, string
firstName - required, string
lastName - required, string
password - required, string
userid - required, identity, string
When the code requests the "userclassprops", it returns the following:
[{"name":"userid","required":true,"type":"STRING","defaultValue":null,"identity":true,"selected":true},{"name":"email","required":true,"type":"STRING","defaultValue":null,"identity":false,"selected":true},{"name":"password","required":true,"type":"STRING","defaultValue":null,"identity":false,"selected":true},{"name":"firstName","required":true,"type":"STRING","defaultValue":null,"identity":false,"selected":true},{"name":"lastName","required":true,"type":"STRING","defaultValue":null,"identity":false,"selected":true}]
When I fill out the form, it looks like this:
http://support.backendless.com/public/4jZaIUghrO3DlO3e2X71.png</img>
When I submit the form, it strangely submits the following:
{"userid":"","email":"Tester500@XXXXXXXX.com","password":"XXXXXXXXXX","firstName":"TestFirst","lastName":"TestLast","pswrd":""}
Where did that “pswrd” field come from? Why is the “userid” value blank? So, I go poking through the code. The “pswrd” comes from here:
Notice that this is the LOGIN function, NOT the register function.
function loginUser(form)/*function to check userid & password*/
{
try{
var user = Backendless.UserService.login( form.userid.value, form.pswrd.value );
if(user != null)
showInfo("Login successful");
else
showInfo("Login failed");
}
catch (e)
{
showInfo("Login failed. "+ e.message);
}
}
So, why are fields that are referenced in the “loginUser” function getting passed when I am trying to register? Here is the answer:
function createUser( form ) {
var user = new Backendless.User();
$("input").each(function(){
var propertyName = $(this)[0].name;
if(propertyName)
user[propertyName] = $(this)[0].value;
});
try
{
var register = Backendless.UserService.register(user);
showInfo(" User successfully created");
}
catch(e)
{
showInfo(e.message);
}
}
The createUser function is doing a query selector that finds ALL input elements in the DOM. Those input elements will include the register form AND the login form. So, while I am putting a “userid” in, the .each function is finding the first “userid” field in the register function, doing looping through all other fields, and overwriting my “userid” from the register form with the empty “userid” from the login form.
That mystery is solved!
Here is the fix:
Step 1:
The “register” form has an id “regForm”. The login form does NOT have an id. This needs to be fixed:
<form class="form-signin" id="loginForm">
Step 2:
The query selector for the the register form needs to change from :
$("input").each(function(){
to
$('#regForm input').each(function(){
Now, I STILL don’t understand why the backend does not auto-generate details such as a unique key for user records, no created field, and no updated field. I also want to be able to edit the user records via the GUI.