]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/user/class_User.php
Update of last activitity and action in user added, refresh of auth cookies added
[shipsimu.git] / inc / classes / main / user / class_User.php
index 2221111eabda84589ede9bfc3e360934065fd4a9..49b285fa7c779b43d71268faae44a93cc2978a40 100644 (file)
@@ -285,6 +285,7 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
                        $entry = $this->resultInstance->current();
 
                        // So does the hashes match?
+                       //* DEBUG: */ echo $requestInstance->getRequestElement('pass_hash')."/".$entry['pass_hash'];
                        $matches = ($requestInstance->getRequestElement('pass_hash') === $entry['pass_hash']);
                } // END - if
 
@@ -324,6 +325,60 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable {
                // And return the hash
                return $passHash;
        }
+
+       /**
+        * Updates the last activity timestamp and last performed action in the
+        * database result. You should call flushUpdates() to flush these updates
+        * to the database layer.
+        *
+        * @param       $requestInstance        A requestable class instance
+        * @return      void
+        */
+       public function updateLastActivity (Requestable $requestInstance) {
+               // Set last action
+               $lastAction = $requestInstance->getRequestElement('action');
+
+               // If there is no action use the default on
+               if (is_null($lastAction)) {
+                       $lastAction = $this->getConfigInstance()->readConfig('login_default_action');
+               } // END - if
+
+               // Get a critieria instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add search criteria
+               $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+               $searchInstance->setLimit(1);
+
+               // Now get another criteria
+               $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
+
+               // And add our both entries
+               $updateInstance->addCriteria('last_activity', date("Y-m-d H:i:s", time()));
+               $updateInstance->addCriteria('last_action', $lastAction);
+
+               // Add the search criteria for searching for the right entry
+               $updateInstance->setSearchInstance($searchInstance);
+
+               // Remember the update in database result
+               $this->resultInstance->add2UpdateQueue($updateInstance);
+       }
+
+       /**
+        * Flushs all updated entries to the database layer
+        *
+        * @return      void
+        */
+       public function flushUpdates () {
+               // Get a database wrapper
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
+               // Do we have data to update?
+               if ($this->resultInstance->ifDataNeedsFlush()) {
+                       // Yes, then send the whole result to the database layer
+                       $wrapperInstance->doUpdateByResult($this->resultInstance);
+               } // END - if
+       }
 }
 
 // [EOF]