Exemplo n.º 1
0
 protected function setAdditionalParameters(DeligatedUser $user)
 {
     $steamKey = Config::get('accounts.steam.key');
     if ($steamKey) {
         $openid = $user->getUniqueId();
         $params = explode('/', $openid);
         $id = array_pop($params);
         // Now fetch the user data
         $request = new Request();
         $request->setUrl('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/');
         $request->setParameters(array('key' => $steamKey, 'steamids' => $id));
         $response = Client::getInstance()->get($request);
         // No headers? No gain.
         $data = json_decode($response->getBody(), true);
         if ($data) {
             $userdata = $data['response']['players'][0];
             $user->setName($userdata['personaname']);
             $user->setAvatar($userdata['avatarfull']);
             $user->setFirstname($userdata['realname']);
             $user->setUrl($userdata['profileurl']);
         }
     }
 }
Exemplo n.º 2
0
 public function merge(DeligatedUser $user)
 {
     if ($user->getAvatar()) {
         $this->setAvatar($user->getAvatar());
     }
     if ($user->getName()) {
         $this->setName($user->getName());
     }
     if ($user->getFirstname()) {
         $this->setFirstname($user->getFirstname());
     }
     if ($user->getLastname()) {
         $this->setLastname($user->getLastname());
     }
     if ($user->getAccessToken()) {
         $this->setAccessToken($user->getAccessToken());
     }
     if ($user->getGender()) {
         $this->setGender($user->getGender());
     }
     if ($user->getLocale()) {
         $this->setLOcale($user->getLocale());
     }
     if ($user->getEmail()) {
         $this->setEmail($user->getEmail());
     }
     if ($user->getBirthday()) {
         $this->setBirthday($user->getBirthday());
     }
     if ($user->getAvatar()) {
         $this->setAvatar($user->getAvatar());
     }
 }
 protected function getObjectFromData($data)
 {
     $deligatedUser = new DeligatedUser();
     $deligatedUser->setId(intval($data['ud_id']));
     $deligatedUser->setType($data['ud_type']);
     $deligatedUser->setUniqueId($data['ud_unique_id']);
     if ($data['ud_name']) {
         $deligatedUser->setName($data['ud_name']);
     }
     if ($data['ud_access_token']) {
         $deligatedUser->setAccessToken($data['ud_access_token']);
     }
     if ($data['ud_gender']) {
         $deligatedUser->setGender($data['ud_gender']);
     }
     if ($data['ud_email']) {
         $deligatedUser->setEmail($data['ud_email']);
     }
     if ($data['ud_birthday']) {
         $deligatedUser->setBirthday(new Carbon($data['ud_birthday']));
     }
     if ($data['ud_locale']) {
         $deligatedUser->setLocale($data['ud_locale']);
     }
     if ($data['ud_avatar']) {
         $deligatedUser->setAvatar($data['ud_avatar']);
     }
     if ($data['ud_firstname']) {
         $deligatedUser->setFirstname($data['ud_firstname']);
     }
     if ($data['ud_lastname']) {
         $deligatedUser->setLastname($data['ud_lastname']);
     }
     if ($data['u_id']) {
         $user = \Neuron\MapperFactory::getUserMapper()->getFromId($data['u_id']);
         if ($user) {
             $deligatedUser->setUser($user);
         }
     }
     $deligatedUser->setCreatedAt(strtotime($data['created_at']));
     $deligatedUser->setUpdatedAt(strtotime($data['updated_at']));
     return $deligatedUser;
 }
Exemplo n.º 4
0
 public function login()
 {
     $this->initialize();
     $helper = new FacebookRedirectLoginHelper(URLBuilder::getAbsoluteURL($this->module->getRoutePath() . '/login/' . $this->getToken(), array('next' => 1)));
     if (!$this->request->input('next')) {
         $loginUrl = $helper->getLoginUrl($this->scopes);
         return Response::redirect($loginUrl);
     } else {
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
             return Response::error($ex->getMessage());
         } catch (\Exception $ex) {
             // When validation fails or other local issues
             return Response::error($ex->getMessage());
         }
         if ($session) {
             // Check if this user is already registered.
             $request = new FacebookRequest($session, 'GET', '/me', array('fields' => 'id,name,gender,verified,locale,timezone,email,birthday,first_name,last_name'));
             $response = $request->execute();
             $graphObject = $response->getGraphObject();
             $data = $graphObject->asArray();
             // Create an object.
             $user = new DeligatedUser();
             $user->setType('facebook');
             $user->setUniqueId($data['id']);
             $user->setAccessToken((string) $session->getAccessToken());
             if (isset($data['name'])) {
                 $user->setName($data['name']);
             }
             if (isset($data['gender'])) {
                 switch (strtoupper($data['gender'])) {
                     case DeligatedUser::GENDER_FEMALE:
                     case DeligatedUser::GENDER_MALE:
                         $user->setGender(strtoupper($data['gender']));
                         break;
                 }
             }
             if (isset($data['locale'])) {
                 $user->setLocale($data['locale']);
             }
             if (isset($data['email'])) {
                 $user->setEmail($data['email']);
             }
             if (isset($data['birthday'])) {
                 if (strlen($data['birthday']) == 10) {
                     $parts = explode('/', $data['birthday']);
                     $user->setBirthday(Carbon::createFromDate($parts[2], $parts[0], $parts[1]));
                 }
             }
             if (isset($data['first_name'])) {
                 $user->setFirstname($data['first_name']);
             }
             if (isset($data['last_name'])) {
                 $user->setLastname($data['last_name']);
             }
             $user->setAvatar('https://graph.facebook.com/' . $user->getUniqueId() . '/picture?type=large');
             // Touchy touchy!
             return $this->setDeligatedUser($user);
         }
     }
 }
 protected function afterLogin($openid)
 {
     $user = new DeligatedUser();
     $user->setType('openid');
     $user->setUniqueId($openid);
     $this->setAdditionalParameters($user);
     return $this->setDeligatedUser($user);
 }
 /**
  * Return an error (string) or redirect
  * @param DeligatedUser $deligatedUser
  * @param $email
  * @param $password
  * @return Response|string
  * @throws ExpectedType
  */
 private function processLogin(DeligatedUser $deligatedUser, $email, $password)
 {
     $mapper = \Neuron\MapperFactory::getUserMapper();
     ExpectedType::check($mapper, UserMapper::class);
     $user = $mapper->getFromLogin($email, $password);
     if ($user) {
         // Everything okay
         // Link the deligated user to this user.
         $deligatedUser->setUser($user);
         MapperFactory::getDeligatedMapper()->update($deligatedUser);
         return $this->module->login($this->request, $user);
     } else {
         // Check if we have this email address
         $user = $mapper->getFromEmail($email);
         if ($user) {
             return 'PASSWORD_INCORRECT';
         } else {
             return 'USER_NOT_FOUND';
         }
     }
 }