/** * Process login with Facebook * * @param \Facebook\GraphNodes\GraphUser $userNode * @return array */ private function _process($userNode) { $userInfo = []; $userInfo['email'] = $userNode->getField('email'); $userInfo['first_name'] = $userNode->getFirstName(); $userInfo['last_name'] = $userNode->getLastName(); $userInfo['facebook_id'] = $userNode->getId(); return (new ZSocialHelper($userInfo, 'facebook'))->process(); }
/** * Register a user from a GraphUser object. * * @param GraphUser $userGraph * * @return integer|boolean */ public function register(GraphUser $userGraph) { $username = sanitize_user($userGraph->getFirstName(), true); $i = ''; while (username_exists($username . $i)) { $i = absint($i); $i++; } $username = $username . $i; $userdata = apply_filters($this->container->getSlug() . '.register.user.filter', array('user_pass' => wp_generate_password(), 'user_login' => $username, 'user_nicename' => $username, 'user_email' => $userGraph->getField('email'), 'display_name' => $userGraph->getField('name'), 'nickname' => $username, 'first_name' => $userGraph->getField('first_name'), 'last_name' => $userGraph->getField('last_name'), 'role' => get_option('default_role'))); $localUserId = wp_insert_user($userdata); if ($localUserId instanceof WP_Error) { throw new Exception($localUserId->get_error_message(), 500); } return $localUserId; }
/** * Create or update user by using data from facebook and login to store * * @param GraphUser $facebookUser * @param AccessToken $accessToken * * @return CustomerInterface */ private function createOrUpdateAndLogin(GraphUser $facebookUser, AccessToken $accessToken) { if (!$this->customer->getId()) { $this->customer->setEmail($facebookUser->getEmail()); $this->customer->setFirstname($facebookUser->getFirstName()); $this->customer->setLastname($facebookUser->getLastName()); $this->customer->setMiddlename($facebookUser->getMiddleName()); $this->customer->setGender((int) ($facebookUser->getGender() == 'male')); } $this->customer->setCustomAttribute('sf_id', $facebookUser->getId()); $this->customer->setCustomAttribute('sf_access_token', serialize($accessToken)); if ($this->customer->getId()) { $customer = $this->customerRepository->save($this->customer); } else { $customer = $this->accountManagement->createAccount($this->customer); } $this->login($customer->getId()); return $customer; }
/** * Get the Facebook account first name * * @return string */ public function getFirstname() { return $this->graphuser->getFirstName(); }