コード例 #1
0
 /**
  * Updates a user's profile. This updates the user's information according to the database columns.
  * If you need to change client session data, use UserSessionsManager instead.
  *
  * @param $user object UserAccount
  * @param $new_user_data array optional
  * @return $user object | null
  */
 public function update_user(UserAccount $user, array $new_user_data = null)
 {
     if ($new_user_data) {
         $user->set_user_data($new_user_data);
     }
     $password_updated = false;
     if (!empty($user['password'])) {
         if (!empty($user['old_password'])) {
             $this->change_password($user, $user['password'], $user['old_password']);
         } else {
             $this->change_password($user, $user['password']);
         }
         $password_updated = true;
     }
     //we've done with passwords
     unset($user['password']);
     unset($user['old_password']);
     //we never update the id
     $user_id = $user['id'];
     unset($user['id']);
     //encrypt the new shared key
     if (!empty($user['sharedKey'])) {
         $user['sharedKey'] = $this->encryption->encrypt($user['sharedKey'], $this->options['shared_key_encryption']);
     }
     //refresh the ip address to the current user
     if (isset($data['ipAddress'])) {
         $data['ipAddress'] = $this->ip_transformer->insert($data['ipAddress']);
     }
     //validate if the columns are correct
     $columns = array_keys($user->get_user_data());
     if (!$this->storage->validate_columns($this->options['table_users'], $columns)) {
         throw new DatabaseValidationException($this->lang['account_update_invalid']);
     }
     if ($this->storage->update_user($user_id, $user->get_user_data(), $columns) or $password_updated) {
         //put the id back into the user
         $user['id'] = $user_id;
         return $user;
     }
 }
コード例 #2
0
ファイル: Authenticator.php プロジェクト: polycademy/polyauth
 protected function set_session_state(UserAccount $user = null)
 {
     $session = $this->strategy->get_session();
     //if the user doesn't exist, we'll setup an anonymous user
     if (!$user) {
         $session['user_id'] = false;
         $anonymous_user = new UserAccount(false);
         $anonymous_user->set_user_data(array('anonymous' => true));
         $this->user = $anonymous_user;
     } else {
         $session['user_id'] = $user['id'];
         $this->user = $user;
     }
 }