public function testGetAttribute() { $login = new Login('username', 'password', true); $login->setAttribute('aname', 'avalue'); $login->setAttribute('bname', 'bvalue'); $this->assertSame('avalue', $login->getAttribute('aname')); $this->assertSame('bvalue', $login->getAttribute('bname')); $login->setAttribute('aname', 'cvalue'); $this->assertSame('cvalue', $login->getAttribute('aname')); $this->assertNull($login->getAttribute('doesnt exist')); }
/** * Get the user from user provided for the given instance of Login object. * * @param Login $login Instance of Login object. * * @return AbstractUser * @throws UserNotFoundException */ public function getUser(Login $login) { // check if we have the tw_oauth_server attribute if (!$login->getAttribute('tw_oauth_server')) { throw new UserNotFoundException('User not found.'); } // try to get the user from oauth $connection = $login->getAttribute('tw_oauth_server'); try { $twUserObj = $connection->getUserDetails(); $eventObj = new TwitterEvent($twUserObj, $connection); $this->eventManager()->fire(TwitterEvent::TWITTER_AUTH_SUCCESS, $eventObj); } catch (\Exception $e) { throw new UserNotFoundException($e->getMessage()); } // create the user object $user = new User(); $user->populate($twUserObj->getUsername(), '', $login->getAttribute('tw_oauth_roles'), true); return $user; }
/** * Get the user from user provided for the given instance of Login object. * * @param Login $login Instance of Login object. * * @return UserAbstract * @throws UserNotFoundException */ public function getUser(Login $login) { // check if we have the oauth_server attribute if (!$login->getAttribute('oauth2_server')) { throw new UserNotFoundException('User not found.'); } // try to get the user from oauth $oauth2 = $login->getAttribute('oauth2_server'); try { $oauth2User = $oauth2->request()->getUserDetails(); // fire the event $eventClass = new OAuth2Event($oauth2User, $oauth2); $this->eventManager()->fire(OAuth2Event::OAUTH2_AUTH_SUCCESS, $eventClass); } catch (\Exception $e) { $this->httpSession()->delete('oauth_token'); throw new UserNotFoundException($e->getMessage()); } // create the user object $user = new User(); $user->populate($oauth2User->email, '', $login->getAttribute('oauth2_roles'), true); return $user; }