Correct usage of hook_user_login and hook_user_presave for saving data to user I have a custom module that syncs LDAP-data to custom user fields (every 24 hours, depending on when the user logs in). Everything seems to be working, but I'm not an expert on PHP and Drupal hooks so I want to be sure I'm not doing anything silly. 

My understanding is that when user account is saved in hook_user_login, hook_user_presave is run and the values are saved (values are located in the $edit variable). Am I saving the values correctly? Have I missed a critical check that could lead to errors?

Here's my code:

// runs everytime a user logs in, checks if ldap attributes need to be updated
function company_ldap_user_login(&amp;$edit, $account) {

      // If the user is user 1 or guest, then do nothing
      if ($account-&gt;uid &lt;= 1) {
        return;
      }

      // don't update data if it's less than 24 hours ago
      if (isset($account-&gt;data-&gt;ldap_sync) &amp;&amp; $account-&gt;data-&gt;ldap_sync &lt; time() - 3600 * 24) {
        return;
      } else {

        // load custom LDAP configuration
        require_once('custom_ldap.inc');

        $ldap = new ldap();

        // get LDAP data
        $data = $ldap-&gt;get_info();

        // do nothing, since user does not exist in LDAP
        if($data["count"] == 0)
        {                          
          return;
        }

        $data = $data[0];

        $first_name = trim($data["givenname"][0]);
        $last_name = trim($data["sn"][0]);
        $fullname = "$first_name $last_name";
        unset($data['mailaddresses']['count']);

        // load the user that has logged in
        $account = user_load($account-&gt;uid);

        // save LDAP data to an array
        $edits = array(
          'first_name' =&gt; $first_name,
          'last_name' =&gt; $last_name,
          'fullname' =&gt; $fullname,
          'emails' =&gt; $data['mailaddresses'],
          'ldap_sync' =&gt; time(),
        );

        // save the user with the data provided above
        user_save($account, $edits, 'company_ldap');

      }
}


// when user account is being saved or updated
function company_ldap_user_presave(&amp;$edit, $account, $category) {

  // make sure to only update ldap-attributes when needed
  if ($category == 'company_ldap') {

    // if there is no data to save, don't save
    if (isset($edit['fullname'])) {

      // save ldap-data to custom user fields
      $edit['field_company_fullname'][LANGUAGE_NONE][0]['value'] = $edit['fullname'];
      $edit['field_company_first_name'][LANGUAGE_NONE][0]['value'] = $edit['first_name'];
      $edit['field_company_last_name'][LANGUAGE_NONE][0]['value'] = $edit['last_name'];

      // loop through all mail addresses and add them to the custom user field
      foreach ($edit['emails'] as $i =&gt; $email ) {
        $edit['field_company_emails'][LANGUAGE_NONE][$i]['value'] = $email;
      }

      // save serialized data of last ldap sync to users.data table
      $edit['data']['ldap_sync'] = $edit['ldap_sync'];
    }

  }

}
IMO you don't need the implementation of the hook_user_presave(), I see that in the implementation of hook_user_login() you have all the values that you need to create the user.