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;
 }
Exemple #2
0
 public static function getDriverAdapterClassName()
 {
     $driver = Config::get('ntentan:db.driver', false);
     if ($driver) {
         return __NAMESPACE__ . '\\adapters\\' . Text::ucamelize(Config::get('ntentan:db.driver')) . 'Adapter';
     }
     throw new NibiiException("Please specify a driver");
 }
 /**
  * Initialize the component.
  * 
  * @see ntentan\controllers.Controller::init()
  */
 public function init()
 {
     parent::init();
     // Setup the template engine and set params
     TemplateEngine::appendPath(realpath(__DIR__ . "/../../views/signin"));
     View::set('app', Config::get('ntentan:app.name'));
     View::set('social_signin_base_url', '');
 }
Exemple #4
0
 private static function factory()
 {
     if (!Config::get('ajumamoro:broker') || !Config::get('ajumamoro:broker.driver')) {
         throw new Exception('Please specify a broker for the jobs.');
     }
     $storeDriverClass = '\\ajumamoro\\brokers\\' . ucfirst(Config::get('ajumamoro:broker.driver')) . 'Broker';
     $storeDriver = new $storeDriverClass();
     $storeDriver->init();
     return $storeDriver;
 }
Exemple #5
0
 public function init()
 {
     $settings = Config::get('ajumamoro:broker');
     unset($settings['driver']);
     $this->redis = new \Predis\Client($settings);
     try {
         $this->redis->connect();
     } catch (\Predis\CommunicationException $ex) {
         throw new BrokerConnectionException("Failed to connect to redis broker: {$ex->getMessage()}");
     }
 }
Exemple #6
0
 /**
  * Creates a new instance of the Atiaa driver. This class is usually initiated
  * through the \ntentan\atiaa\Atiaa::getConnection() method. For example
  * to create a new instance of a connection to a mysql database.
  * 
  * ````php
  * use ntentan\atiaa\Driver;
  * 
  * \\ This automatically insitatiates the driver class
  * $driver = Driver::getConnection(
  *     array(
  *         'driver' => 'mysql',
  *         'user' => 'root',
  *         'password' => 'rootpassy',
  *         'host' => 'localhost',
  *         'dbname' => 'somedb'
  *     )
  * );
  * 
  * var_dump($driver->query("SELECT * FROM some_table");
  * var_dump($driver->describe());
  * ````
  * 
  * @param array<string> $config The configuration with which to connect to the database.
  */
 public function __construct($config = null)
 {
     $this->config = $config ? $config : Config::get('ntentan:db');
     $username = isset($this->config['user']) ? $this->config['user'] : null;
     $password = isset($this->config['password']) ? $this->config['password'] : null;
     try {
         $this->pdo = new \PDO($this->getDriverName() . ":" . $this->expand($this->config), $username, $password);
         $this->pdo->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
         $this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
         $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     } catch (\PDOException $e) {
         throw new DatabaseDriverException("PDO failed to connect: {$e->getMessage()}", $e);
     }
 }
Exemple #7
0
 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);
     }
 }
Exemple #8
0
 public function init($parameters = array())
 {
     $this->parameters = Parameters::wrap($parameters);
     $this->authenticated = Session::get('logged_in');
     foreach ($this->parameters->get('excluded_routes', array()) as $excludedRoute) {
         if (preg_match("/{$excludedRoute}/i", Ntentan::$route) > 0) {
             return;
         }
     }
     if ($this->authenticated !== true) {
         View::set('app_name', Config::get('ntentan:app.name'));
         View::set('title', "Login");
         $this->login();
     }
 }
Exemple #9
0
 public function run($options)
 {
     if (isset($options['config'])) {
         Config::readPath($options['config'], 'ajumamoro');
     }
     if ($options['daemon'] === true) {
         ClearIce::output("Starting ajumamoro daemon ... ");
         Logger::init(Config::get('ajumamoro:log_file', './ajumamoro.log'), 'ajumamoro');
         if ($this->checkExistingInstance() === false) {
             $pid = $this->startDaemon($options);
             ClearIce::output($pid > 0 ? "OK [PID:{$pid}]\n" : "Failed\n");
         } else {
             ClearIce::output("Failed\nAn instance already exists.\n");
         }
     } else {
         Logger::init('php://output', 'ajumamoro');
         Runner::mainLoop();
     }
 }
Exemple #10
0
 public static function mainLoop()
 {
     $bootstrap = Config::get('ajumamoro:bootstrap');
     if ($bootstrap) {
         require Config::get("ajumamoro:bootstrap");
     }
     Logger::info("Starting Ajumamoro");
     set_error_handler(function ($no, $message, $file, $line) {
         Logger::error("Job #" . self::$jobId . " Warning {$message} on line {$line} of {$file}");
     }, E_WARNING);
     // Get Store;
     $delay = Config::get('delay', 200);
     do {
         $job = self::getNextJob();
         if ($job !== false) {
             self::executeJob($job);
         } else {
             usleep($delay);
         }
     } while (true);
 }
Exemple #11
0
 public function testConfigFile()
 {
     Config::readPath(__DIR__ . '/../fixtures/config/file.php');
     $this->assertEquals(true, Config::get('dump'));
 }
Exemple #12
0
 public static function getDefaultDriverClassName()
 {
     return self::getDriverClassName(Config::get('ntentan:db.driver'));
 }
Exemple #13
0
 public static function init($namespace)
 {
     self::$namespace = $namespace;
     self::$prefix = Config::get('app.prefix');
     self::$prefix = (self::$prefix == '' ? '' : '/') . self::$prefix;
     self::setupAutoloader();
     logger\Logger::init('logs/app.log');
     Config::readPath(self::$configPath, 'ntentan');
     kaikai\Cache::init();
     panie\InjectionContainer::bind(ModelClassResolverInterface::class)->to(ClassNameResolver::class);
     panie\InjectionContainer::bind(ModelJoinerInterface::class)->to(ClassNameResolver::class);
     panie\InjectionContainer::bind(TableNameResolverInterface::class)->to(nibii\Resolver::class);
     panie\InjectionContainer::bind(ComponentResolverInterface::class)->to(ClassNameResolver::class);
     panie\InjectionContainer::bind(ControllerClassResolverInterface::class)->to(ClassNameResolver::class);
     panie\InjectionContainer::bind(controllers\RouterInterface::class)->to(DefaultRouter::class);
     if (Config::get('ntentan:db.driver')) {
         panie\InjectionContainer::bind(DriverAdapter::class)->to(Resolver::getDriverAdapterClassName());
         panie\InjectionContainer::bind(atiaa\Driver::class)->to(atiaa\Db::getDefaultDriverClassName());
     }
     Controller::setComponentResolverParameters(['type' => 'component', 'namespaces' => [$namespace, 'controllers\\components']]);
     nibii\RecordWrapper::setComponentResolverParameters(['type' => 'behaviour', 'namespaces' => [$namespace, 'nibii\\behaviours']]);
     controllers\ModelBinderRegister::setDefaultBinderClass(controllers\model_binders\DefaultModelBinder::class);
     controllers\ModelBinderRegister::register(utils\filesystem\UploadedFile::class, controllers\model_binders\UploadedFileBinder::class);
 }
Exemple #14
0
 protected function runArrayAssertions($config)
 {
     foreach ($config as $key => $value) {
         $this->assertEquals($value, Config::get($key));
     }
 }
Exemple #15
0
 /**
  * Returns information about all migration paths.
  * Yentu can be configured to use multiple migration homes, for multiple
  * database configurations. This makes it possible to use a single command
  * to run multiple migrations accross multiple databases.
  * @return array
  */
 public static function getMigrationPathsInfo()
 {
     $variables = Config::get('default.variables', []);
     $otherMigrations = Config::get('default.other_migrations', []);
     return array_merge(array(array('home' => Yentu::getPath('migrations'), 'variables' => $variables)), $otherMigrations);
 }
 /**
  * 
  * @param array<mixed> $config
  * @return \yentu\DatabaseManipulator;
  */
 public static function create()
 {
     $config = Config::get('yentu:default.db');
     if ($config['driver'] == '') {
         throw new exceptions\DatabaseManipulatorException("Please specify a database driver.");
     }
     $class = "\\yentu\\manipulators\\" . ucfirst($config['driver']);
     unset($config['variables']);
     return new $class($config);
 }
Exemple #17
0
 /**
  * Initialize the caching engine.
  * Reads the current configuration to determine the caching backend to use.
  */
 public static function init()
 {
     $backend = Config::get('ntentan:cache.backend', 'volatile');
     self::$backendClass = '\\ntentan\\kaikai\\backends\\' . Text::ucamelize($backend) . 'Cache';
 }
Exemple #18
0
 public static function path($path)
 {
     return preg_replace('~/+~', '/', Config::get('ntentan:app.prefix') . "/{$path}");
 }