Ejemplo n.º 1
0
 /**
  * Main authentication method
  *
  * @param string $login
  * @param string $password
  * @return False if not found or not enabled, User instance if succedes
  */
 function authenticate($login, $password)
 {
     $UserInstance =& new User();
     if (($User =& $UserInstance->find('first', array('conditions' => array('login = ? AND __owner.is_enabled = ? AND _roles.is_enabled = ?', $login, true, true), 'include' => 'role'))) && $User->isValidPassword($password)) {
         $User->set('last_login_at', Ak::getDate());
         $User->save();
         return $User;
     }
     return false;
 }
Ejemplo n.º 2
0
 public function Test_for_getTimestamp()
 {
     $this->assertEqual(Ak::getTimestamp(), Ak::time());
     $this->assertEqual('17:52:03', Ak::getDate(Ak::getTimestamp('17:52:03'), 'H:i:s'));
     $this->assertEqual(date('Y-m-d') . ' 17:52:03', Ak::getDate(Ak::getTimestamp('17:52:03')));
     $this->assertEqual('2005-12-25 00:00:00', Ak::getDate(Ak::getTimestamp('2005-12-25')));
     $this->assertEqual('1592-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('1592-10-09')));
     $this->assertEqual('2192-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('2192-10-09')));
     $this->assertEqual('2192-10-09 01:02:03', Ak::getDate(Ak::getTimestamp('2192-10-9 01:02:03')));
 }
Ejemplo n.º 3
0
 public function test_should_record_timestamps()
 {
     $this->WebPage->body = 'Akelos PHP framework...';
     $this->WebPage->save();
     $created_at = Ak::getDate();
     $this->assertEqual($this->WebPage->created_at, $created_at);
     sleep(1);
     $this->WebPage->save();
     $this->assertEqual($this->WebPage->created_at, $created_at);
     $this->assertEqual($this->WebPage->updated_at, Ak::getDate());
 }
Ejemplo n.º 4
0
 /**
  * Main authentication method
  * 
  * @param string $login user name or password
  * @param string $password
  * @return False if not found or not enabled, User instance if succedes
  */
 function authenticate($login, $password)
 {
     $UserInstance =& new User();
     $login_or_email = preg_match(AK_EMAIL_REGULAR_EXPRESSION, $login) ? 'email' : 'login';
     if (($User =& $UserInstance->find('first', array('conditions' => array($login_or_email . ' = ? AND __owner.is_enabled = ? AND _roles.is_enabled = ?', $login, true, true), 'include' => 'role'))) && $User->isValidPassword($password)) {
         $User->set('last_login_at', Ak::getDate());
         $User->save();
         return $User;
     }
     return false;
 }
Ejemplo n.º 5
0
 function authenticateWithToken($token)
 {
     $options = User::_decodeToken($token);
     if (!empty($options) && !empty($options['hash']) && !empty($options['id'])) {
         $User = new User();
         $User = $User->find($options['id']);
         if (!empty($options['expires']) && $options['expires'] < Ak::getTimestamp()) {
             return false;
         }
         if ($options['hash'] == $User->_getTokenHash($options)) {
             $User->updateAttribute('last_login_at', Ak::getDate());
             return $User;
         }
     }
     return false;
 }
Ejemplo n.º 6
0
 public function authenticateWithToken($token, $update_last_login = true)
 {
     $options = User::decodeToken($token);
     if (!empty($options) && !empty($options['hash']) && !empty($options['id'])) {
         $User = new User();
         $User = $User->find($options['id']);
         if (!empty($options['expires']) && $options['expires'] < Ak::getTimestamp()) {
             return false;
         }
         if ($options['hash'] == $User->getTokenHash($options)) {
             if ($update_last_login) {
                 $User->updateAttribute('last_login_at', Ak::getDate());
             }
             $this->setCurrentUser($User);
             return $User;
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 public function test_setup()
 {
     $this->controller = new AkActionController();
     $this->controller->Request = new MockAkRequest($this);
     $this->controller->controller_name = 'test';
     $this->controller->instantiateHelpers();
     $this->active_record_helper =& $this->controller->active_record_helper;
     $this->installAndIncludeModels(array('ProtectedPerson', 'Property'));
     $this->controller->ProtectedPerson = new ProtectedPerson();
     $this->LuckyLuke =& $this->controller->ProtectedPerson;
     $this->controller->ProtectedPerson->name = "Lucky Luke";
     $this->controller->ProtectedPerson->created_by = "1";
     $this->controller->ProtectedPerson->birthday = Ak::getDate(mktime(8, 42, 36, 3, 27, 1982));
     $this->controller->ProtectedPerson->save();
     $this->controller->ProtectedPerson->created_at = Ak::getDate(mktime(8, 42, 36, 3, 27, 1982));
     $this->controller->ProtectedPerson->updated_at = Ak::getDate(mktime(8, 42, 36, 3, 27, 1982));
     $this->controller->Property = new Property('description->', '阿尔罕布拉宫', 'details->', '阿尔罕布拉宫 <> & (阿拉伯语: الحمراء‎‎ = Al Ħamrā\'; 即"红色城堡")');
     $this->alhambra =& $this->controller->Property;
     $this->alhambra->save();
 }
Ejemplo n.º 8
0
 public function test_setup()
 {
     //echo NumberHelper::human_size(memory_get_peak_usage()).' '.__LINE__."\n";
     $Request = new MockAkRequest();
     $Request->setReturnValue('getController', 'test');
     $Request->setReturnValue('getRelativeUrlRoot', '');
     $Request->setReturnValue('getParametersFromRequestedUrl', array('controller' => 'test'));
     $this->controller = new AkActionController();
     $this->controller->Request = $Request;
     $this->active_record_helper = $this->controller->active_record_helper;
     $this->installAndIncludeModels(array('DummyProtectedPerson', 'DummyProperty'));
     $this->controller->DummyProtectedPerson = new DummyProtectedPerson();
     $this->LuckyLuke = $this->controller->DummyProtectedPerson;
     $this->controller->DummyProtectedPerson->name = "Lucky Luke";
     $this->controller->DummyProtectedPerson->created_by = "1";
     $this->controller->DummyProtectedPerson->birthday = Ak::getDate(mktime(8, 42, 36, 3, 27, 1982));
     $this->controller->DummyProtectedPerson->save();
     $this->controller->DummyProtectedPerson->created_at = Ak::getDate(mktime(8, 42, 36, 3, 27, 1982));
     $this->controller->DummyProtectedPerson->updated_at = Ak::getDate(mktime(8, 42, 36, 3, 27, 1982));
     $this->controller->DummyProperty = new DummyProperty(array('description' => '阿尔罕布拉宫', 'details' => '阿尔罕布拉宫 <> & (阿拉伯语: الحمراء‎‎ = Al Ħamrā\'; 即"红色城堡")'));
     $this->alhambra = $this->controller->DummyProperty;
     $this->alhambra->save();
     //echo NumberHelper::human_size(memory_get_peak_usage()).' '.__LINE__."\n";
 }
Ejemplo n.º 9
0
 public function to_date_tag()
 {
     $defaults = $this->default_date_options;
     $date = $this->getValue();
     $date = !empty($date) ? $date : Ak::getDate();
     return AkDateHelper::select_day($date, array_merge($defaults, array('prefix' => "{$this->object_name}[{$this->_column_name}(3)]"))) . AkDateHelper::select_month($date, array_merge($defaults, array('prefix' => "{$this->object_name}[{$this->_column_name}(2)]"))) . AkDateHelper::select_year($date, array_merge($defaults, array('prefix' => "{$this->object_name}[{$this->_column_name}(1)]")));
 }
Ejemplo n.º 10
0
 public function Test_of_populate_todo_list()
 {
     for ($i = 0; $i <= 30; $i++) {
         $attributes = array('task' => 'Task number ' . ($i + 3), 'due_time' => Ak::getDate(Ak::time() + 60 * 60 * 24 * $i));
         $TodoTask = new TodoItem($attributes);
         $this->assertTrue($TodoTask->save());
         $this->assertTrue($TodoTask->task == $attributes['task'] && $TodoTask->due_time == $attributes['due_time']);
     }
 }
Ejemplo n.º 11
0
 public function multipart_with_mime_version($recipient)
 {
     $this->set(array('recipients' => $recipient, 'subject' => "multipart with mime_version", 'from' => "*****@*****.**", 'sent_on' => Ak::getDate(strtotime('2004-12-12')), 'mime_version' => "1.1", 'content_type' => "multipart/alternative", 'parts' => array(array('content_type' => 'text/plain', 'body' => 'blah'), array('content_type' => 'text/html', 'body' => '<b>blah</b>'))));
 }
Ejemplo n.º 12
0
 function _getRequestOrigin()
 {
     return $this->Request->remote_ip . ' at ' . Ak::getDate();
 }
Ejemplo n.º 13
0
    function setInstalledVersion($version, $options = array())
    {
        //if(!$this->tableExists('akelos_migrations')) {
            $this->_createMigrationsTable();
        //}
        /**
         * this will produce an error if the unique index on name is violated, then we update
         */
        $this->log('Setting version of '.$this->getInstallerName().' to '.$version);
        $old_version=$this->db->selectValue(array('SELECT version from akelos_migrations WHERE name = ?', $this->getInstallerName()));
        if($old_version !== null || !@$this->db->execute(array('INSERT INTO akelos_migrations (version,created_at,name) VALUES (?,?,?)',$version,Ak::getDate(),$this->getInstallerName()))) {
            return @$this->db->execute(array('UPDATE akelos_migrations SET version=?, updated_at=? WHERE name=?',$version,Ak::getDate(),$this->getInstallerName()));
        }

        return true;

    }
Ejemplo n.º 14
0
 /**
  * Creates a new record with values matching those of the instance attributes.
  * Must be called as a result of a call to createOrUpdate.
  */
 function _create()
 {
     if ($this->isFrozen()) {
         $this->transactionFail();
         return false;
     }
     if ($this->beforeCreate()) {
         $this->notifyObservers('beforeCreate');
         if ($this->_recordTimestamps) {
             if ($this->hasColumn('created_at')) {
                 $this->setAttribute('created_at', Ak::getDate());
             }
             if ($this->hasColumn('created_on')) {
                 $this->setAttribute('created_on', Ak::getDate(null, 'Y-m-d'));
             }
             if (isset($this->expires_on)) {
                 if (isset($this->expires_at) && $this->hasColumn('expires_at')) {
                     $this->setAttribute('expires_at', Ak::getDate(strtotime($this->expires_at) + (defined('AK_TIME_DIFFERENCE') ? AK_TIME_DIFFERENCE * 60 : 0)));
                 } elseif (isset($this->expires_on) && $this->hasColumn('expires_on')) {
                     $this->setAttribute('expires_on', Ak::getDate(strtotime($this->expires_on) + (defined('AK_TIME_DIFFERENCE') ? AK_TIME_DIFFERENCE * 60 : 0), 'Y-m-d'));
                 }
             }
         }
         $attributes = $this->removeUnavailableColumns($this->getAttributes());
         if ($this->isLockingEnabled()) {
             $attributes['lock_version'] = 1;
             $this->setAttribute('lock_version', 1);
         }
         $pk = $this->getPrimaryKey();
         $table = $this->getTableName();
         foreach ($attributes as $column => $value) {
             $attributes[$column] = $this->castAttributeForDatabase($column, $value);
         }
         /**
          * @todo sanitize attributes
          * 'beforeValidationOnCreate', 'afterValidationOnCreate'
          */
         if (!isset($this->_generateSequence) || isset($this->_generateSequence) && $this->_generateSequence !== false) {
             if (empty($attributes[$pk]) || !empty($attributes[$pk]) && (int) $attributes[$pk] > 0) {
                 if ($this->_getDatabaseType() != 'mysql') {
                     $table_details = $this->_databaseTableInternals('seq_' . $table);
                     if (!isset($table_details['ID'])) {
                         $this->_db->CreateSequence('seq_' . $table);
                     }
                     $attributes[$pk] = $this->_db->GenID('seq_' . $table);
                 }
             }
         }
         $__attributes = $attributes;
         $attributes = array_diff($attributes, array('', "''"));
         $sql = 'INSERT INTO ' . $table . ' ' . '(' . join(', ', array_keys($attributes)) . ') ' . 'VALUES (' . join(',', array_values($attributes)) . ')';
         if (!$this->_db->Execute($sql)) {
             AK_DEBUG ? trigger_error($this->_db->ErrorMsg(), E_USER_NOTICE) : null;
         }
         $id = !empty($attributes[$pk]) ? $attributes[$pk] : $this->_db->Insert_ID($table, $pk);
         $this->setId($id);
         if (!$this->transactionHasFailed()) {
             $this->_newRecord = false;
             if (!$this->afterCreate()) {
                 $this->transactionFail();
             } else {
                 $this->notifyObservers('afterCreate');
             }
         }
     } else {
         $this->transactionFail();
     }
     return $this;
 }
Ejemplo n.º 15
0
 function test_should_be_able_to_authenticate()
 {
     $this->assertFalse(User::authenticate('aliciasadurni', 'badpass'));
     $this->assertTrue($Alicia = User::authenticate('aliciasadurni', 'goodpass'));
     $this->assertNotNull($Alicia->get('last_login_at'), 'Should update last_login_at');
     $this->assertEqual(substr($Alicia->get('last_login_at'), 0, -2), substr(Ak::getDate(), 0, -2));
 }
Ejemplo n.º 16
0
 /**
 * Joins date arguments into a single attribute. Like the array generated by the date_helper, so
 * array('published_on(1i)' => 2002, 'published_on(2i)' => 'January', 'published_on(3i)' => 24)
 * Will be converted to array('published_on'=>'2002-01-24')
 *
 * @access private
 */
 function _castDateParametersFromDateHelper_(&$params)
 {
     if(empty($params)){
         return;
     }
     $date_attributes = array();
     foreach ($params as $k=>$v) {
         if(preg_match('/^([A-Za-z0-9_]+)\(([1-5]{1})i\)$/',$k,$match)){
             $date_attributes[$match[1]][$match[2]] = $v;
             unset($params[$k]);
         }
     }
     foreach ($date_attributes as $attribute=>$date){
         $params[$attribute] = Ak::getDate(Ak::getTimestamp(trim(@$date[1].'-'.@$date[2].'-'.@$date[3].' '.@$date[4].':'.@$date[5].':'.@$date[6],' :-')));
     }
 }
Ejemplo n.º 17
0
    function _setRecordTimestamps()
    {
        if (!$this->_recordTimestamps){
            return;
        }
        if ($this->_newRecord){
            if ($this->hasColumn('created_at')){
                $this->setAttribute('created_at', Ak::getDate());
            }
            if ($this->hasColumn('created_on')){
                $this->setAttribute('created_on', Ak::getDate(null, 'Y-m-d'));
            }
        }else{
            if ($this->hasColumn('updated_at')){
                $this->setAttribute('updated_at', Ak::getDate());
            }
            if ($this->hasColumn('updated_on')){
                $this->setAttribute('updated_on', Ak::getDate(null, 'Y-m-d'));
            }
        }

        if($this->_newRecord && isset($this->expires_on)){
            if(isset($this->expires_at) && $this->hasColumn('expires_at')){
                $this->setAttribute('expires_at',Ak::getDate(strtotime($this->expires_at) + (defined('AK_TIME_DIFFERENCE') ? AK_TIME_DIFFERENCE*60 : 0)));
            }elseif(isset($this->expires_on) && $this->hasColumn('expires_on')){
                $this->setAttribute('expires_on',Ak::getDate(strtotime($this->expires_on) + (defined('AK_TIME_DIFFERENCE') ? AK_TIME_DIFFERENCE*60 : 0), 'Y-m-d'));
            }
        }

    }
Ejemplo n.º 18
0
 function _generate_date($db_date)
 {
     //1998-05-12T14:15:00
     if (!is_int($db_date)) {
         $db_date = strtotime($db_date);
     }
     return Ak::getDate($db_date, 'Y-m-d\\Th:i:sP');
 }
Ejemplo n.º 19
0
 /**
  * Return the current time in this time zone.
  */
 function dateTime()
 {
     return Ak::getDate($this->now(), Ak::locale('date_time_format'));
 }
Ejemplo n.º 20
0
 function setOptions($options = array())
 {
     $this->year = empty($options['year']) ? Ak::getDate(null,'Y') : $options['year'];
     $this->month = empty($options['month']) ? Ak::getDate(null,'n') : $options['month'];
     $this->day = empty($options['day']) ? Ak::getDate(null,'j') : $options['day'];
     $this->week_day = CalendarCalculations::getDayOnTheWeek($this->year, $this->month, $this->day);
     $this->week = date('W', mktime(0,0,0,$this->month, $this->day, $this->year));
     $this->is_today = Ak::getDate(null, 'Y-n-j') == $this->year.'-'.$this->month.'-'.$this->day;
 }
Ejemplo n.º 21
0
 public function test_today()
 {
     $Zone = $this->_createTimeZone("Test", 43200);
     $Zone->_timestamp = $this->timestamp;
     $this->assertEqual(Ak::getDate(mktime(0,0,0,7,26,2004), Ak::locale('date_format')), $Zone->today());
 }
Ejemplo n.º 22
0
 /**
  * Converts an ISO date to current locale format
  *
  */
 function locale_date($iso_date)
 {
     $timestamp = Ak::getTimestamp($iso_date);
     $format = Ak::locale('date_format');
     return Ak::getDate($timestamp, $format);
 }
Ejemplo n.º 23
0
 public function test_should_convert_between_timestamp_and_date()
 {
     $iso_date = '2007-10-15 16:30:00';
     $this->assertEqual(Ak::getDate(Ak::getTimestamp($iso_date)), $iso_date);
     $this->assertEqual(Ak::getDate(Ak::getTimestamp('2007-10-15 16:30')), $iso_date);
 }
Ejemplo n.º 24
0
 function to_date_tag()
 {
     require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'date_helper.php';
     $defaults = $this->default_date_options;
     $date = $this->getValue();
     $date = !empty($date) ? $date : Ak::getDate();
     return DateHelper::select_day($date, array_merge($defaults, array('prefix' => "{$this->object_name}[{$this->_column_name}(3)]"))) . DateHelper::select_month($date, array_merge($defaults, array('prefix' => "{$this->object_name}[{$this->_column_name}(2)]"))) . DateHelper::select_year($date, array_merge($defaults, array('prefix' => "{$this->object_name}[{$this->_column_name}(1)]")));
 }
Ejemplo n.º 25
0
 protected function _setRecordTimestamps()
 {
     if (!$this->_record_timestamps) {
         return;
     }
     $this->setAttribute($this->isNewRecord() ? 'created_at' : 'updated_at', Ak::getDate());
 }