コード例 #1
1
 public function signin()
 {
     $client = new \Google_Client();
     $client->setClientId(Config::get('ntentan:social.google.client_id'));
     $client->setClientSecret(Config::get('ntentan:social.google.client_secret'));
     $client->setRedirectUri(Config::get('ntentan:social.google.redirect_uri'));
     $client->addScope(array('profile', 'email'));
     $oauth2 = new \Google_Service_Oauth2($client);
     if (isset($_REQUEST['logout'])) {
         Session::set('access_token', '');
         $client->revokeToken();
     }
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         Session::set('access_token', $client->getAccessToken());
         Redirect::path(\ntentan\Router::getRoute());
     }
     if (isset($_SESSION['access_token'])) {
         $client->setAccessToken($_SESSION['access_token']);
     }
     if ($client->isAccessTokenExpired()) {
         $authUrl = $client->createAuthUrl();
         header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         $_SESSION['token'] = $client->getAccessToken();
         return array('firstname' => $user['given_name'], 'lastname' => $user['family_name'], 'key' => "google_{$user['id']}", 'avatar' => $user['picture'], 'email' => $user['email'], 'email_confirmed' => $user['verified_email']);
     } else {
         header("Location: {$client->createAuthUrl()}");
         die;
     }
     return false;
 }
コード例 #2
0
 public function __construct($route = null, $attemptedResources = [])
 {
     if ($route == '') {
         $route = Router::getRoute();
     }
     parent::__construct("Route [{$route}] is currently not available. " . (count($attemptedResources) ? "Failed to find any of the following resources: [" . implode(", ", $attemptedResources) . "]" : ""));
 }
コード例 #3
0
ファイル: Url.php プロジェクト: ntentan/ntentan
 public static function action($action, $variables = [])
 {
     $controller = Router::getVar('controller_path');
     $queries = [];
     foreach ($variables as $key => $value) {
         $queries[] = sprintf("%s=%s", urldecode($key), urlencode($value));
     }
     $path = Config::get('ntentan:app.prefix') . ($controller == "" ? "" : "/{$controller}");
     return preg_replace('~/+~', '/', "{$path}/{$action}" . (count($queries) ? "?" . implode('&', $queries) : ""));
 }
コード例 #4
0
 public function authorize()
 {
     // Prevent the user from having access to protected content
     foreach ($this->excludedRoutes as $excludedRoute) {
         if (preg_match_all("/{$excludedRoute}/i", Router::getRoute()) > 0) {
             return;
         }
     }
     if (!Session::get("logged_in")) {
         Redirect::path($this->signinRoute ? $this->signinRoute : Url::action('signin'));
     }
 }
コード例 #5
0
ファイル: WyfController.php プロジェクト: ntentan/wyf
 public function __construct()
 {
     $this->addComponent('auth', array('users_model' => 'system.users', 'on_success' => 'call_function', 'login_route' => 'auth/login', 'success_function' => AuthController::class . '::postLogin'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../../views/default'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../../views/menus'));
     View::set('route_breakdown', explode('/', Router::getRoute()));
     View::set('wyf_title', Config::get('ntentan:app.name'));
     $class = get_class($this);
     $namespace = Ntentan::getNamespace();
     if (preg_match("/{$namespace}\\\\app\\\\(?<base>.*)\\\\controllers\\\\(?<name>.*)Controller/", $class, $matches)) {
         $this->package = strtolower(str_replace("\\", ".", $matches['base']) . "." . $matches['name']);
         $this->name = str_replace(".", " ", $this->package);
         $this->path = str_replace(' ', '/', $this->name);
     }
 }
コード例 #6
0
ファイル: Wyf.php プロジェクト: ntentan/wyf
 public static function init($parameters = [])
 {
     Router::mapRoute('wyf_auth', 'auth/{action}', ['default' => ['controller' => controllers\AuthController::class]]);
     Router::mapRoute('wyf_api', 'api/{*path}', ['default' => ['controller' => controllers\ApiController::class, 'action' => 'rest']]);
     Router::mapRoute('wyf_main', function ($route) {
         $routeArray = explode('/', $route);
         $routeDetails = self::getController($routeArray, realpath(__DIR__ . '/../../../../src/app/'), \ntentan\Ntentan::getNamespace() . '\\app');
         return $routeDetails;
     }, ['default' => ['action' => 'index']]);
     TemplateEngine::appendPath(realpath(__DIR__ . '/../views/layouts'));
     TemplateEngine::appendPath(realpath(__DIR__ . '/../views'));
     AssetsLoader::appendSourceDir(realpath(__DIR__ . '/../assets'));
     View::set('wyf_app_name', $parameters['short_name']);
     InjectionContainer::bind(ModelClassResolver::class)->to(ClassNameResolver::class);
     InjectionContainer::bind(ControllerClassResolver::class)->to(ClassNameResolver::class);
 }