Search code examples
iostitaniumcloudtitanium-mobileappcelerator-mobile

Update password field from Titanium application


I'm working on a Titanium based iOS application.

In which I need to implement the password reset functionality within my app.

Password reset

I found this requestResetPassword method for doing this:

Cloud.Users.requestResetPassword({
    email: '[email protected]'
}, function (e) {
    if (e.success) {
        alert('Success: Reset Request Sent');
    } else {
        alert('Error:\\n' +
            ((e.error && e.message) || JSON.stringify(e)));
    }
});

From docs it says that, it'll send a reset password option to user's mail account. But I don't want that. I need to reset password within my application.

Also I can't remove the current user and create a new account for the same user with new password because there is a lot of custom data saved for each particular user. So that's not a good solution.

Also I found the update function, but I don't know how to use it for updating the password field in cloud, because it is not a custom field.

Cloud.Users.update({
    email: '[email protected]',
    first_name: 'm',
    last_name: 'e',
}, function (e) {
    if (e.success) {
        var user = e.users[0];
        alert('Success:\\n' +
            'id: ' + user.id + '\\n' +
            'first name: ' + user.first_name + '\\n' +
            'last name: ' + user.last_name);
    } else {
        alert('Error:\\n' +
            ((e.error && e.message) || JSON.stringify(e)));
    }
});

Is there anyway to do this from my application ? How can I update user's password field within my application ?

Referred docs:

  1. Titanium.Cloud.Users-module
  2. Titanium.Cloud.Users

Please help, thanks in advance.


Solution

  • Use "update". Specify the password properties like you do in your create call:

    {
        password: 'cheese',
        password_confirmation: 'cheese',
        email: '[email protected]'
    }
    

    http://cloud.appcelerator.com/docs/api/v1/users/update