0

I have a function that sets a user to confirmed after they login to my site for the first time. However, whenever I run this function and I log out and try to log back in the password doesn't work anymore and I have to do a manual reset in the database. I can't seem to find what would cause a change in the password. Any advice?

Note that I am using mongodb.

function update_profile($uid,$attribute_name,$attribute_value,$arrayaction=NULL)
{
    // update some user property
    $existing = user_load($uid);
    $edit = (array) $existing;

    //Update profile iformation
    if(!empty($arrayaction))
    {
        if(strtolower($arrayaction) == 'push')
        {
            array_push($edit[$attribute_name]['und'][0],$attribute_value);
        }
        else if (strtolower($arrayaction) == 'unset')
        {
            if(($key = array_search($attribute_value, $edit[$attribute_name]['und'][0])) !== false) {
               unset($edit[$attribute_name]['und'][0][$key]);
            }
        }
    }
    else
    {
        $edit[$attribute_name]['und'][0] = $attribute_value;
    }

    //Make the changes to the user
    user_save($existing, $edit);
}

function module_user_login(&$edit,$account) {
    if ($account->access == 0) {
        update_profile($account->uid,'field_confirmed',array('value'=>1),NULL);
    }
}
  • 1
    try rules module for any work after user login for the first time – harsh_behl_0007 Aug 19 '14 at 10:49
  • I use this function in other places as well, for example on the user page so that they can edit their preferences. – John Aug 19 '14 at 10:52
  • 1
    Be sure to unset($edit['pass']) if you don't want to edit password. Generally creating $edit from $existing makes no sense to me. You do not need to re-save all fields. Only put into $edit what you know you want to change. You should, usually, be able to start with empty array, without seeding it first. – Mołot Aug 19 '14 at 10:52
  • unset($edit['pass']) worked great! If you add it as an answer I'll mark it as such. – John Aug 19 '14 at 10:58
1

Be sure to

unset($edit['pass']);

if you don't want to edit password. Generally creating $edit from $existing shouldn't be needed. You do not need to re-save all fields, you only put into $edit what you know you want to change. You should, usually, be able to start with empty array, without seeding it first.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.