Ejemplo n.º 1
0
 public function testMagicMethod()
 {
     $schema = new Mongo_Mongo_Schema();
     Epic_Mongo::addSchema('magic', $schema);
     $this->assertInstanceOf('Mongo_Mongo_Schema', Epic_Mongo::magic());
     $this->assertInstanceOf('Mongo_Mongo_Document_Test', Epic_Mongo::magic('test'));
 }
Ejemplo n.º 2
0
 /**
  * Attempt to log a user into the application.
  *
  * @param  array  $arguments
  * @return void
  */
 public function attempt($arguments = array())
 {
     $username = Config::get('auth.username');
     if (!Config::has('auth.username')) {
         throw new Exception('The username in application/config/auth.php must be defined.');
     }
     $model = Config::get('auth.model');
     // Add the username to the query
     $query = array('$or' => array(array(Config::get('auth.username') => $arguments[Config::get('auth.username')])));
     // If we've specified an 'username_alt' field in the config, add that to the $OR
     if (Config::has('auth.username_alt')) {
         $query['$or'][] = array(Config::get('auth.username_alt') => $arguments[Config::get('auth.username')]);
     }
     $user = Epic_Mongo::db('user')->findOne($query);
     // This driver uses a basic username and password authentication scheme
     // so if the credentials match what is in the database we will just
     // log the user into the application and remember them if asked.
     $password = $arguments[Config::get('auth.password')];
     // if ( ! is_null($user) and Hash::check($password, $user->password))
     if (!is_null($user) and Hash::check($password, $user->password)) {
         return $this->login($user->_id, array_get($arguments, 'remember'));
     } else {
         if (!is_null($user) and md5($password) == $user->password) {
             return $this->login($user->_id, array_get($arguments, 'remember'));
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 public function testSimpleGroup()
 {
     $pipeline = array(array('$group' => array('_id' => '$v1', 'count' => array('$sum' => 1))));
     $results = Epic_Mongo::db('test')->aggregate($pipeline);
     foreach ($results['result'] as $result) {
         $this->assertEquals(1000, $result['count']);
     }
 }
Ejemplo n.º 4
0
 public function getMongoDb()
 {
     return Epic_Mongo::getConnection('default')->selectDB($this->dbName);
 }
Ejemplo n.º 5
0
 public function getMongoDb()
 {
     return Epic_Mongo::getConnection($this->getConnection())->selectDB($this->getDb());
 }
Ejemplo n.º 6
0
 /**
  * @expectedException Epic_Mongo_Exception
  */
 public function testGetConnectionException()
 {
     Epic_Mongo::getConnection('doesnt_exist');
 }
Ejemplo n.º 7
0
 public function testFindOneNull()
 {
     $query = array('keyThatDoesntExist' => true);
     $doc = Epic_Mongo::testCollection('test')->findOne($query);
     $this->assertNull($doc);
 }
Ejemplo n.º 8
0
*/
Autoloader::map(array('Epic_Mongo' => path('bundle') . '/epic_mongo/Mongo.php'));
// Ensure the User has created the epicmongo.php config file in application/config
if (!Config::has('epicmongo')) {
    throw new Exception("Please create 'epicmongo.php' in your application/config folder (template found in bundles/epic_mongo/examples/laravel_config).");
}
// Establish a Default Connection
Epic_Mongo::addConnection('default', Config::get('epicmongo.host'));
// Include the Laravel Schema
require_once dirname(__FILE__) . "/Mongo/Schema/Laravel.php";
// Load the default schema and ensure it exists
$schema = Config::get('epicmongo.schema');
if (!Config::has('epicmongo.schema')) {
    throw new Exception("Schema not found, please specify a schema in 'EpicMongo.php' in your application/config folder (example found on the template found in bundles/epic_mongo/examples/laravel_config).");
}
// Add the Schema to EpicMongo
Epic_Mongo::addSchema('db', new $schema());
// Include the Laravel Auth
require_once dirname(__FILE__) . "/Mongo/Auth/Laravel.php";
Auth::extend('epic_mongo', function () {
    return new Epic_Mongo_Auth_Laravel(Config::get('auth.model'));
});
//
// Testing Authentication
//
// $credentials = array('username' => 'username', 'password' => 'password');
//
// if (Auth::attempt($credentials))
// {
// 	var_dump(Auth::user()->email); exit;
// }