public function setUp()
 {
     $this->redbean = new RedBean_Facade();
     $this->redbean->setup('sqlite::memory:');
     $this->tables = array('client' => 'clients', 'access_token' => 'accesstokens', 'code' => 'codes');
     $this->redbean_storage = new GrantCode($this->redbean, $this->tables);
 }
Example #2
0
function createUser()
{
    $success = false;
    RedBean_Facade::setup('mysql:host=localhost;
			dbname=didapi', 'root', '');
    //$user = R::find('user', ' username = ?', array( 'admin') );
    //	if (!isset($user))
    //	{
    $user = RedBean_Facade::dispense('user');
    $user->username = '******';
    $user->name = 'Admin';
    $user->firstname = 'Admin';
    $user->is_admin = true;
    $user->password = hash('sha256', 'Di8Ap1');
    $id = RedBean_Facade::store($user);
    if ($id != null) {
        $success = true;
    }
    //	}
    //	else
    //	{
    //		$success = false;
    //	}
    return $success;
}
 public function setUp()
 {
     $redbean = new RedBean_Facade();
     $redbean->setup('sqlite::memory:');
     $tables = array('client' => 'clients', 'access_token' => 'accesstokens', 'code' => 'codes');
     $this->storage = new \ebussola\oauth\redbean\GrantCode($redbean, $tables);
     $client_bean = $redbean->dispense($tables['client']);
     $client = new \ebussola\oauth\client\Client($client_bean);
     $client->redirect_uris = array();
     $client->client_secret = 'xpto';
     $redbean->store($client->getBean());
     $this->oauth2 = new \OAuth2\OAuth2($this->storage);
 }
Example #4
0
 static function connect($_db = false)
 {
     if (!$_db) {
         $_db = Configure::get('db');
     }
     if (!self::$initialized) {
         self::getInstance();
     }
     if (!self::$isConnected) {
         if (\RedBean_Facade::setup(sprintf('mysql:host=%s;dbname=%s', $_db['host'], $_db['db']), $_db['user'], $_db['password'])) {
             return self::$isConnected = true;
         }
         return self::$isConnected = false;
     }
     return true;
 }
Example #5
0
 /**
  * Initializes application
  */
 public static function init()
 {
     // Start store
     session_start();
     // start database
     if (DBUSER) {
         R::setup(DBDSN, DBUSER, DBPASS);
     } else {
         R::setup(DBDSN, DBUSER, DBPASS);
     }
     // start language
     if (self::getIdiom() == null) {
         self::setIdiom(IDIOM);
     }
     setlocale(LC_ALL, self::getIdiom() . '.UTF8');
 }
Example #6
0
function loginUser()
{
    $success = false;
    RedBean_Facade::setup('mysql:host=' . Database::HOST . ';dbname=' . Database::NAME, Database::USERNAME, Database::PASSWORD);
    //echo hash('sha256', $_POST['password']);
    $user = RedBean_Facade::findOne('user', ' username = :username AND password = :password LIMIT 1', array(':username' => $_POST['username'], ':password' => hash('sha256', $_POST['password'])));
    if (isset($user)) {
        $currentUser = new User($user["username"], $user["firstname"], $user["name"], $user["is_admin"], $user["id"]);
        $_SESSION['username'] = $user["username"];
        $_SESSION['user_id'] = $user["id"];
        $_SESSION['name'] = $user["name"];
        $_SESSION['firstname'] = $user["firstname"];
        $_SESSION['is_admin'] = $user["is_admin"];
        $success = true;
    }
    return $success;
}
Example #7
0
 public static function setupRedBeans()
 {
     $config = Config::get();
     if (!isset($config['db']['host'])) {
         throw new Exception('Config[db][host] not set. Check api.conf in project folder.');
     }
     if (!isset($config['db']['db'])) {
         throw new Exception('Config[db][db] not set. Check api.conf in project folder.');
     }
     if (!isset($config['db']['user'])) {
         throw new Exception('Config[db][user] not set. Check api.conf in project folder.');
     }
     if (!isset($config['db']['password'])) {
         throw new Exception('Config[db][password] not set. Check api.conf in project folder.');
     }
     R::setup('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['db'], $config['db']['user'], $config['db']['password'], true);
     R::exec('SET NAMES utf8mb4');
     R::freeze(true);
 }
Example #8
0
 public function __construct($routes = null)
 {
     $appConfig = array('templates.path' => realpath('../views'), 'mode' => isset($_SERVER['PLIERS_ENV']) ? $_SERVER['PLIERS_ENV'] : 'development');
     if ($appConfig['mode'] === 'development') {
         $appConfig['debug'] = true;
     } else {
         $appConfig['debug'] = false;
     }
     parent::__construct($appConfig);
     if ($routes !== null) {
         self::$initialRoutes = $routes;
     }
     $this->addRoutes();
     $this->setupConfig();
     // Set up RedBean
     R::setup($this->conf->db->dsn, $this->conf->db->username, $this->conf->db->password);
     $this->app = self::getInstance();
     $this->utils = new Utils();
 }
Example #9
0
$default_config['db_user'] = null;
$default_config['db_pass'] = null;
$default_config['default_sql_limit'] = array(0, 25);
$default_config['rate_limit'] = 100;
$config = array_merge($default_config, $config);
if (file_exists('config.php.default') && $config['debug'] === false) {
    die('Please remove the config.php.default.');
}
require_once 'utils.php';
/* make sure admin pass has changed */
if ($config['password'] === 'admin') {
    die('Change the password in config.php');
}
/* setup database */
use RedBean_Facade as R;
R::setup($config['db_conn'], $config['db_user'], $config['db_pass']);
R::$writer->setUseCache(false);
RedBean_OODBBean::setFlagBeautifulColumnNames(false);
/* app start */
if ($config['debug'] === false) {
    ini_set('display_errors', '0');
}
$app = new \Slim\Slim(array('debug' => $config['debug'], 'templates.path' => 'templates'));
/* Middlewares */
$r = new Util($app);
/* load hooks */
$r->loadHooks();
function API()
{
    $app = \Slim\Slim::getInstance();
    $app->view(new \JsonApiView());
Example #10
0
<?php

define(DOMAIN, "tempmai.ir");
define(DB_DNS, "mysql:host=localhost;dbname=database");
define(DB_UNAME, "username");
define(DB_PASS, "password");
define(ENV, "production");
define(PRODUCTION, "production");
require 'vendor/autoload.php';
use RedBean_Facade as R;
R::setup(DB_DNS, DB_UNAME, DB_PASS);
$app = new \Slim\Slim();
$app->config('templates.path', './template');
if (ENV != PRODUCTION) {
    $app->config('debug', true);
}
$app->get('/', function () use($app) {
    $app->render('index.php');
});
$app->post('/get', function () use($app) {
    $email = $app->request->post('email');
    $ip = $app->request()->getIp();
    if ($email == NULL || $email == '' || !check_email_address($email)) {
        echo json_encode(array('success' => FALSE, 'error' => 'INVALID'));
    } else {
        if (R::count('email', 'ip=:ip AND time>=:time', array(':ip' => $ip, ':time' => time() + 119 * 60)) >= 20) {
            echo json_encode(array('success' => FALSE, 'error' => 'LIMITATION'));
        } else {
            $bean = R::findOne('email', 'forwardto=:email AND time >= :time', array(':email' => $email, ':time' => time()));
            if ($bean) {
                $bean->time = time() + 120 * 60;
Example #11
0
require_once __DIR__ . '/../.env.config.php';
require_once __DIR__ . '/../vendor/autoload.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Silex\Provider\FormServiceProvider;
use RedBean_Facade as R;
// use Acme\MyClass;
// $myClass = new MyClass();
$app = new Application();
$env = getenv('APP_ENV') ?: 'prod';
define('APP_ENV', $env);
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/../config/{$env}.json"));
// use $app['debug'], $app['db_name'], etc...
R::setup("mysql:host={$app['db_host']};dbname={$app['db_name']}", "{$app['db_user']}", "{$app['db_pass']}");
$app->register(new Silex\Provider\HttpCacheServiceProvider(), ['http_cache.cache_dir' => __DIR__ . '/http_cache/']);
$app->register(new Silex\Provider\TranslationServiceProvider(), array('locale' => 'de', 'translation.class_path' => __DIR__ . '/../locales', 'translator.messages' => array()));
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/logging.log'));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views', 'twig.options' => array('debug' => $app['debug'], 'strict_variables' => false, 'cache' => __DIR__ . '/twig_cache/', 'auto_reload' => $app['debug'])));
$app['twig']->addExtension(new Twig_Extension_Debug());
$addCacheMiddleware = function (Request $request, Response $response, Application $app) {
    return $response->setCache(['s_maxage' => 3600]);
};
// prepare structure for current request site
$app->before(function ($request, $app) {
});
// ------ ROUTING ------
// remove favicon spam
Example #12
0
 public static function setup($dsn = null, $username = null, $password = null, $frozen = false)
 {
     parent::setup($dsn, $username, $password, $frozen);
     self::$x = new Rx_FindHelper();
 }
Example #13
0
 protected static function Connect()
 {
     RedBean_Facade::setup('mysql:host=' . Database::HOST . ';dbname=' . Database::NAME, Database::USERNAME, Database::PASSWORD);
 }
Example #14
0
<?php

require_once __DIR__ . '/../../../vendor/autoload.php';
use RedBean_Facade as R;
define('REDBEAN_MODEL_PREFIX', 'JustMapIt\\Model\\');
R::setup('mysql:host=localhost;dbname=<dbname>', '<dbuser>', '<dbpass>');
Example #15
0
if ($_SESSION['step'] == 6 && $_SESSION['step5_ok']) {
    $step6_results = array();
    try {
        require_once 'vendor/autoload.php';
        require_once 'lib/Link.php';
        require_once 'lib/BootWiki.php';
        require_once 'lib/Idiom.php';
        require_once 'lib/Image.php';
        require_once 'lib/Content.php';
        require_once 'lib/BootWiki.php';
        if ($_SESSION['step2']['dbdriver'] == 'mysql') {
            $dsn = $_SESSION['step2']['dbdriver'] . ':host=' . $_SESSION['step2']['dbhost'] . ';dbname=' . $_SESSION['step2']['dbname'];
        } else {
            $dsn = $_SESSION['step2']['dbdriver'] . ':' . $_SESSION['step2']['dbfile'];
        }
        RedBean_Facade::setup($dsn, $_SESSION['step2']['dbuser'], $_SESSION['step2']['dbpass']);
        define('ENCRYPT_SALT', $_SESSION['step4']['encrypt_salt']);
        BootWiki::install();
        $step6_results[] = 'Database instalation was completed';
        $_SESSION['step6_ok'] = true;
    } catch (\PDOException $e) {
        $step6_results[] = 'Database error: ' . $e->getMessage();
    }
}
/**
 * Do not let to go further than step 6 if database is not installed
 */
if (!$_SESSION['step6_ok'] && $_SESSION['step'] > 6) {
    $_SESSION['step'] = 5;
}
require_once $_SESSION['step1']['templatepath'] . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . 'installer.php';