/** * Inserts a new row into the App table and create the corresponding user table. * @param array $data * @throws Exception * @return int $id id of the new app */ public function insertRow(array $data = array()) { if (empty($data)) { throw new Exception('$data not provided in ' . get_class($this) . '::' . __FUNCTION__ . '()'); } // handle unencrypted password $data['password'] = Daiquiri_Crypt_Abstract::factory()->encrypt($data['new_password']); // insert the new row $this->getAdapter()->insert('Auth_Apps', array('appname' => $data['appname'], 'password' => $data['password'], 'active' => 1)); // create database for app if (Daiquiri_Config::getInstance()->query) { $userDb = Daiquiri_Config::getInstance()->getUserDbName($data['appname']); $adapter = Daiquiri_Config::getInstance()->getUserDbAdapter('', $data['appname']); $sql = "CREATE DATABASE `{$userDb}`"; $adapter->query($sql)->closeCursor(); } // return the id of the newly created app return $this->getAdapter()->lastInsertId(); }
/** * @brief constructor - initialises password cryptography and all required database tables * * Sets up everything needed for the Zend Authentication mechanism and hooks up the * desired password crypto method with the password check. */ protected function __construct() { // get the acl class, this could be more general $this->_acl = new Daiquiri_Acl(); // store roles in auth object $roleModel = new Auth_Model_Roles(); $this->_roles = $roleModel->getResource()->fetchValues('role'); // store status in auth object $statusModel = new Auth_Model_Status(); $this->_status = $statusModel->getResource()->fetchValues('status'); // get user detail keys $detailKeysModel = new Auth_Model_DetailKeys(); $this->_detailKeys = $detailKeysModel->getResource()->fetchValues('key'); // get treatment from default crypt object try { $crypt = Daiquiri_Crypt_Abstract::factory(); } catch (Exception $e) { $crypt = null; } if ($crypt !== null) { $treatment = $crypt->getTreatment(); // get treatment for users $userTreatment = $treatment; $activeId = $this->getStatusId('active'); if (is_numeric($activeId)) { $userTreatment .= 'AND status_id=' . $activeId; } // get treatement for apps $appTreatment = $treatment . ' AND active=1'; // set properties of the user adapter $this->_userAdapter = new Zend_Auth_Adapter_DbTable(); $this->_userAdapter->setTableName('Auth_User'); $this->_userAdapter->setIdentityColumn('username'); $this->_userAdapter->setCredentialColumn('password'); $this->_userAdapter->setCredentialTreatment($userTreatment); // set properties of the app adapter $this->_appAdapter = new Zend_Auth_Adapter_DbTable(); $this->_appAdapter->setTableName('Auth_Apps'); $this->_appAdapter->setIdentityColumn('appname'); $this->_appAdapter->setCredentialColumn('password'); $this->_appAdapter->setCredentialTreatment($appTreatment); } }
/** * Registers a new user. * @param array $data * @return int $id (id of the new entry in the registration table) */ public function registerUser(array $data) { // handle password $data['password'] = Daiquiri_Crypt_Abstract::factory()->encrypt($data['new_password']); // handle additional versions of the password foreach (array_keys(Daiquiri_Config::getInstance()->auth->password->toArray()) as $type) { if ($type != 'default') { $data['details']['password_' . $type] = Daiquiri_Crypt_Abstract::factory($type)->encrypt($data['new_password']); } } // unset password unset($data['new_password']); // seperate primary credentials and details $details = $data['details']; // construct details string $data['details'] = Zend_Json::encode($details); // insert the new row $this->getAdapter()->insert('Auth_Registration', $data); // return the id of the user just inserted return $this->getAdapter()->lastInsertId(); }