Skip to content

Instantly share code, notes, and snippets.

@iantearle
Created April 1, 2012 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iantearle/2272370 to your computer and use it in GitHub Desktop.
Save iantearle/2272370 to your computer and use it in GitHub Desktop.
Appcelerator Register with custom fields
var sex = (male == 1) ? 'male' : 'female';
var data = {
email: email.value,
first_name: global.user_names[0],
last_name: global.user_names[1],
password: password.value,
password_confirmation: password.value,
custom_fields: '{ "dob": "'+ dob.value +'", "sex": "'+ sex +'" }' // REMOVE THIS LINE IT ALL WORKS... HAVE HAD MULTIPLE PEDRMEATATIONS, SO THIS WAY MAY NOT BE THE ONLY CAUSE OF THIS NOT WORKING, JUST THE LAST ONE I TRIED.
};
sdk.sendRequest('users/create.json', 'POST', data, false, callback);
function callback(data) {
if(data) {
if(data.meta) {
var meta = data.meta;
if(meta.status == 'ok' && meta.code == 200 && meta.method_name == 'createUser') {
var message = '';
var user = data.response.users[0];
Ti.API.info("User id is => " + user.id);
var cred = [user.id, email.value];
Ti.App.Properties.setString('credentials', cred);
keychain.setPasswordForService(password.value, 'Heritage', email.value);
Ti.App.fireEvent('accountLoggedIn');
} else{
alert(meta.status +' ' + meta.code)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment