예제 #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
 /**
  * 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', '');
 }
예제 #3
0
파일: Resolver.php 프로젝트: ntentan/nibii
 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");
 }
예제 #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;
 }
예제 #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()}");
     }
 }
예제 #6
0
 public function setUp()
 {
     $this->testDatabase = 'yentu_rollback_test';
     parent::setup();
     $this->createDb($GLOBALS['DB_NAME']);
     $this->initDb($GLOBALS['DB_FULL_DSN'], file_get_contents("tests/sql/{$GLOBALS['DRIVER']}/pre_rollback.sql"));
     $this->connect($GLOBALS['DB_FULL_DSN']);
     $this->setupStreams();
     $init = new \yentu\commands\Init();
     $init->createConfigFile(array('driver' => $GLOBALS['DRIVER'], 'host' => $GLOBALS['DB_HOST'], 'dbname' => $GLOBALS["DB_NAME"], 'user' => $GLOBALS['DB_USER'], 'password' => $GLOBALS['DB_PASSWORD'], 'file' => $GLOBALS['DB_FILE']));
     Config::readPath(\yentu\Yentu::getPath('config'), 'yentu');
 }
예제 #7
0
파일: Driver.php 프로젝트: ntentan/atiaa
 /**
  * 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);
     }
 }
예제 #8
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);
     }
 }
예제 #9
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();
     }
 }
예제 #10
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();
     }
 }
예제 #11
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);
 }
예제 #12
0
파일: Ntentan.php 프로젝트: ntentan/ntentan
 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);
 }
예제 #13
0
파일: Init.php 프로젝트: codogh/yentu
 public function run($options = array())
 {
     Yentu::greet();
     if (file_exists(Yentu::getPath(''))) {
         throw new CommandException("Could not initialize yentu. Your project has already been initialized with yentu.");
     } else {
         if (!is_writable(dirname(Yentu::getPath('')))) {
             throw new CommandException("Your current directory is not writable.");
         }
     }
     $params = $this->getParams($options);
     if (count($params) == 0 && defined('STDOUT')) {
         global $argv;
         throw new CommandException("You didn't provide any parameters for initialization. Please execute " . "`{$argv[0]} init -i` to initialize yentu interractively. " . "You can also try `{$argv[0]} init --help` for more information.");
     }
     $this->createConfigFile($params);
     Config::readPath(Yentu::getPath('config'), 'yentu');
     $db = \yentu\DatabaseManipulator::create($params);
     if ($db->getAssertor()->doesTableExist('yentu_history')) {
         throw new CommandException("Could not initialize yentu. Your database has already been initialized with yentu.");
     }
     $db->createHistory();
     $db->disconnect();
     ClearIce::output("Yentu successfully initialized.\n");
 }
예제 #14
0
파일: Yentu.php 프로젝트: ekowabaka/yentu
 /**
  * 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);
 }
예제 #15
0
 /**
  * 
  * @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);
 }
예제 #16
0
파일: cli.php 프로젝트: codogh/yentu
ClearIce::setFootnote("Report bugs to jainooson@gmail.com");
ClearIce::setUsage("[command] [options]");
ClearIce::addHelp();
ClearIce::setStrict(true);
$options = ClearIce::parse();
if (isset($options['verbose'])) {
    ClearIce::setOutputLevel($options['verbose']);
}
try {
    if (isset($options['__command__'])) {
        if (isset($options['home'])) {
            Yentu::setDefaultHome($options['home']);
        }
        $class = "\\yentu\\commands\\" . ucfirst($options['__command__']);
        unset($options['__command__']);
        Config::readPath(Yentu::getPath('config'), 'yentu');
        $command = new $class();
        $command->run($options);
    } else {
        ClearIce::output(ClearIce::getHelpMessage());
    }
} catch (\yentu\exceptions\CommandException $e) {
    ClearIce::resetOutputLevel();
    ClearIce::error("Error! " . $e->getMessage() . "\n");
} catch (\ntentan\atiaa\exceptions\DatabaseDriverException $e) {
    ClearIce::resetOutputLevel();
    ClearIce::error("Database driver failed: " . $e->getMessage() . "\n");
    Yentu::reverseCommand($command);
} catch (\yentu\exceptions\DatabaseManipulatorException $e) {
    ClearIce::resetOutputLevel();
    ClearIce::error("Failed to perform database action: " . $e->getMessage() . "\n");
예제 #17
0
 public static function connectBroker($parameters)
 {
     Config::set('ajumamoro:broker', $parameters);
     return new Queue();
 }
예제 #18
0
파일: Cache.php 프로젝트: ntentan/kaikai
 /**
  * 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';
 }
예제 #19
0
파일: Url.php 프로젝트: ntentan/ntentan
 public static function path($path)
 {
     return preg_replace('~/+~', '/', Config::get('ntentan:app.prefix') . "/{$path}");
 }
예제 #20
0
파일: Db.php 프로젝트: ntentan/atiaa
 public static function getConnection($parameters)
 {
     Config::set('ntentan:db', $parameters);
     return InjectionContainer::resolve(self::getDriverClassName($parameters['driver']));
 }
예제 #21
0
 public function tearDown()
 {
     parent::tearDown();
     Config::reset();
 }
예제 #22
0
파일: YentuTest.php 프로젝트: codogh/yentu
 public function tearDown()
 {
     $this->pdo = null;
     Config::reset();
 }
예제 #23
0
 public function testConfigFile()
 {
     Config::readPath(__DIR__ . '/../fixtures/config/file.php');
     $this->assertEquals(true, Config::get('dump'));
 }