예제 #1
0
 public function onPost($data, $context)
 {
     //Ensure that our mongo and config references are valid
     if (empty($context['mongo'])) {
         throw new \Exception('No database handler found');
     }
     if (empty($context['config'])) {
         throw new \Exception('No configuration manager found');
     }
     if (!$context['mongo'] instanceof \MongoDB\Database) {
         throw new \Exception('Invalid database handler');
     }
     if (!$context['config'] instanceof \CaseFiles\Config) {
         throw new \Exception('Invalid configuration manager');
     }
     $mongo = $context['mongo'];
     $config = $context['config'];
     //Select the 'users' collection
     $users = $mongo->selectCollection('users');
     //Create a new user
     $user = new \CaseFiles\Models\User($users, $config);
     $user_id = $user->create($data['password']);
     //Return the user id
     return array('success' => true, 'id' => $user_id);
 }
예제 #2
0
파일: App.php 프로젝트: d0x2f/CaseFiles
 public function __construct()
 {
     $this->config = new \CaseFiles\Config('../config/config.json');
     //Create an instance of Affront
     try {
         $this->affront = new \Affront\App('../config/affront-config.json');
     } catch (\Exception $e) {
         echo 'Couldn\'t instantiate Affront: ' . $e->getMessage();
         exit;
     }
     //Setup MongoDB connection
     $mongo_host = $this->config->get('mongo_host');
     $mongo_port = $this->config->get('mongo_port');
     $mongo_user = $this->config->get('mongo_user');
     $mongo_password = $this->config->get('mongo_password');
     $mongo_database = $this->config->get('mongo_database');
     $this->mongo = new \MongoDB\Database(new \MongoDB\Driver\Manager("mongodb://{$mongo_user}:{$mongo_password}@{$mongo_host}:{$mongo_port}/{$mongo_database}"), $mongo_database);
     $mongo_user_lexical = $this->mongo->selectCollection('users');
     $config_lexical = $this->config;
     //Set user verification closures for oauth
     $this->affront->setPasswordVerifyFunction(function ($id, $password) use($mongo_user_lexical, $config_lexical) {
         $user = new \CaseFiles\Models\User($mongo_user_lexical, $config_lexical);
         //Check the user exists
         $loaded = $user->load($id);
         if (!$loaded) {
             return false;
         }
         //Attempt to decrypt the document
         $decrypted = $user->decrypt($password);
         if (!$decrypted) {
             return false;
         }
         return true;
     });
     $this->affront->setVerifyUsernameFunction(function ($id) use($mongo_user_lexical) {
         $result = $mongo_user_lexical->findOne(array('id' => $id));
         return is_null($result) ? false : $id;
     });
 }