/** * @param $token * @return Response */ public function authenticator($token) { $authenticator = $this->module->getAuthenticators()->getFromToken($token); if (!$authenticator) { return Response::error('Authenticator not found', Response::STATUS_NOTFOUND); } $authenticator->setRequest($this->request); return $authenticator->register(); }
/** * @return Response */ public function register() { return Response::error('Authenticator does not have register method.', Response::STATUS_NOTFOUND); }
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); } } }
private function runFinish() { $consumer = $this->getConsumer(); // Complete the authentication process using the server's // response. $return_to = $this->getReturnTo(); $response = $consumer->complete($return_to); // Check the response status. if ($response->status == Auth_OpenID_CANCEL) { // This means the authentication was cancelled. $msg = 'Verification cancelled.'; } else { if ($response->status == Auth_OpenID_FAILURE) { // Authentication failed; display the error message. $msg = "OpenID authentication failed: " . $response->message; } else { if ($response->status == Auth_OpenID_SUCCESS) { // This means the authentication succeeded; extract the // identity URL and Simple Registration data (if it was // returned). $openid = $response->getDisplayIdentifier(); return $this->afterLogin($openid); } } } return Response::error($msg); }
public function routerVerifier(\Neuron\Models\Router\Filter $filter) { if ($filter->getRequest()->getUser()) { return true; } return Response::error('You must be authenticated', Response::STATUS_UNAUTHORIZED); }
/** * Execute the router: Loop all defined before middlewares and routes, and execute the handling function if a mactch was found * * @param Request $request * @return Response */ public function run(Request $request) { // Define which method we need to handle $this->method = $request->getMethod(); // Set request $this->request = $request; // Handle all routes $numHandled = 0; if (isset($this->routes[$this->method])) { $numHandled = $this->handle($this->routes[$this->method], true); } // If no route was handled, trigger the 404 (if any) if ($numHandled == 0) { if ($this->notFound) { //call_user_func($this->notFound); $this->handleMatch($this->notFound, array()); } else { $request = Response::error('Page not found.', Response::STATUS_NOTFOUND); $request->output(); } } // If it originally was a HEAD request, clean up after ourselves by emptying the output buffer if ($_SERVER['REQUEST_METHOD'] == 'HEAD') { ob_end_clean(); } }
/** * Return an error response. * @return Response */ public function getErrorResponse() { return Response::error($this->getError(), self::STATUS_INVALID_INPUT); }
public function getError($message) { return Response::error($message, 401); }