function connectWithFacebookUID($fb_uid) { // if there is already a facebook account if ($fb_user = User::getByFacebookUID($fb_uid)) { // if there are two separate accounts for the same // user, then delete the Facebook-specific one // and connect the facebook id with the existing // account. // // a real site wouldn't actually delete an account - // the user should probably control the merging // of data from the to-be-deleted account to their own if ($fb_user->username != $this->username) { $fb_user->delete(); } } if (!$fb_uid) { return false; } $this->fb_uid = $fb_uid; return $this->save(); }