示例#1
0
 /**
  * (non-PHPdoc)
  * @see TAuthManager::onAuthorize()
  */
 public function onAuthorize($param)
 {
     $application = $this->getApplication();
     //if this is a call back function and its session timed out/invalid, then redirect the page to homepage
     if ($this->getRequest()->contains(TPage::FIELD_CALLBACK_TARGET) && !$application->getAuthorizationRules()->isUserAllowed($application->getUser(), $application->getRequest()->getRequestType(), $application->getRequest()->getUserHostAddress())) {
         // Create a callback adapter which counstructor will set up TCallbackReponseAdapter in the HttpResponse class adapter property
         $callbackAdapter = new TActivePageAdapter(new TPage());
         // Redirect (now the adapter is not null)
         $this->Response->redirect('/');
         // Create a html writer
         $writer = $this->Response->createHtmlWriter();
         // Render the response
         $callbackAdapter->renderCallbackResponse($writer);
         //Flush the output
         $application->flushOutput();
         //exit application do not process the futher part
         exit;
     }
     parent::onAuthorize($param);
     $u = Core::getUser();
     if ($u instanceof UserAccount) {
         $r = Core::getRole();
         Core::setUser($u, $r);
     }
 }
示例#2
0
 /**
  * getting the response
  * 
  * @param UDate $time
  * 
  * @return SimpleXMLElement
  */
 protected function _getResponse(UDate $time)
 {
     Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
     //TODO
     $response = new SimpleXMLElement('<Response />');
     $response->addAttribute('Time', trim($time));
     $response->addAttribute('TimeZone', trim($time->getTimeZone()->getName()));
     return $response;
 }
示例#3
0
 /**
  * constructor
  */
 public function __construct()
 {
     parent::__construct();
     if (!Core::getUser() instanceof UserAccount && get_class($this) !== 'LoginController') {
         if (isset($_REQUEST['user']) && isset($_REQUEST['pass']) && in_array(get_class($this), array('OrderPrintController', 'POPrintController')) && ($userAccount = UserAccount::getUserByUsernameAndPassword(trim($_REQUEST['user']), trim($_REQUEST['pass']), true)) instanceof UserAccount) {
             Core::setUser($userAccount);
         } else {
             $this->getResponse()->Redirect('/login.html');
         }
     }
 }
 /**
  * login a user
  *
  * @param array $params
  *
  * @throws Exception
  * @return multitype:
  */
 private function _login($params)
 {
     if (!isset($params['username']) || ($username = trim($params['username'])) === '') {
         throw new Exception('username is empty!');
     }
     if (!isset($params['password']) || ($password = trim($params['password'])) === '') {
         throw new Exception('password is empty!');
     }
     $userAccount = UserAccount::getUserByUsernameAndPassword($username, $password, true);
     $role = null;
     if (count($roles = $userAccount->getRoles()) > 0) {
         $role = $roles[0];
     }
     Core::setUser($userAccount, $role);
     return array();
 }
示例#5
0
 /**
  * validate a user providing $username and $password
  *
  * @param string $username
  * @param string $password
  * @return true, if there is such a userAccount in the database;otherwise, false;
  */
 public function validateUser($username, $password)
 {
     if (!Core::getUser() instanceof UserAccount) {
         $userAccount = UserAccount::getUserByUsernameAndPassword($username, $password);
         if (!$userAccount instanceof UserAccount) {
             return false;
         }
         $role = null;
         if (!Core::getRole() instanceof Role) {
             if (count($roles = $userAccount->getRoles()) > 0) {
                 $role = $roles[0];
             }
         }
         Core::setUser($userAccount, $role);
     }
     return true;
 }
示例#6
0
 private static function _setRunningUser($preFix = '', $debug = false)
 {
     self::_log('== Set Running User : '******'', $preFix);
     Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
     self::_log('UserAccount(ID=' . Core::getUser()->getId() . ')', '', $preFix . self::TAB);
     if (!isset(self::$_api['URL']) || ($apiUrl = trim(self::$_api['URL'])) === '') {
         throw new Exception('No API URL set!');
     }
     if (!isset(self::$_api['token']) || ($token = trim(self::$_api['token'])) === '') {
         self::_log('!! no token yet, need to get token.', '', $preFix . self::TAB);
         $url = $apiUrl . 'UserAccount/login';
         $data = json_encode(array('username' => Core::getUser()->getUserName(), 'password' => Core::getUser()->getPassword()));
         self::_postJson($url, $data, $preFix . self::TAB, $debug);
         if (trim(self::$_api['token']) === '') {
             throw new Exception('Invalid token');
         }
     }
 }
示例#7
0
 public function changePersonInfo($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->firstName) || ($firstName = trim($param->CallbackParameter->firstName)) === '') {
             throw new Exception("Invalid firstName!");
         }
         if (!isset($param->CallbackParameter->lastName) || ($lastName = trim($param->CallbackParameter->lastName)) === '') {
             throw new Exception("Invalid lastName!");
         }
         Core::getUser()->getPerson()->setFirstName($firstName)->setLastName($lastName)->save();
         Core::setUser(UserAccount::get(Core::getUser()->getId()), Core::getRole());
         $results['succ'] = true;
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
示例#8
0
 /**
  * runner
  * @param string $debug
  */
 public static function run($debug = false)
 {
     try {
         self::$_debug = $debug;
         Dao::beginTransaction();
         Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
         $start = self::_debug("Start to run " . __CLASS__ . ' =================== ');
         $assetIds = self::_findAllOverdueAssets();
         $assetIds = array_merge($assetIds, self::_findAllZombieAssets());
         self::_deleteAssets($assetIds);
         self::_debug("Finished to run " . __CLASS__ . ' =================== ', self::NEW_LINE, "", $start);
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         self::_debug("***** ERROR: " . $ex->getMessage());
         self::_debug($ex->getTraceAsString());
     }
 }
示例#9
0
 /**
  * The runner
  *
  * @param string $preFix
  * @param string $debug
  */
 public static function run($outputFileDir, $preFix = '', $debug = false)
 {
     $start = self::_log('## START ##############################', __CLASS__ . '::' . __FUNCTION__, $preFix);
     self::$_outputFileDir = trim($outputFileDir);
     self::_log('GEN FILE TO: ' . self::$_outputFileDir, '', $preFix . self::TAB);
     self::$_imageDirName = self::$_imageDirName . '_' . UDate::now()->format('Y_m_d_H_i_s');
     Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
     $now = UDate::now();
     $settings = self::_getSettings($preFix . self::TAB, $debug);
     $lastUpdatedTime = UDate::zeroDate();
     if (isset($settings['lastUpdatedTime']) && trim($settings['lastUpdatedTime']) !== '') {
         $lastUpdatedTime = new UDate(trim($settings['lastUpdatedTime']));
     }
     self::_log('GOT LAST SYNC TIME: ' . trim($lastUpdatedTime), '', $preFix);
     $products = self::_getData($lastUpdatedTime, $preFix . self::TAB, $debug);
     if (count($products) > 0) {
         $files = self::_genCSV($lastUpdatedTime, array_values($products), $preFix . self::TAB, $debug);
         self::_zipFile($files, $preFix, $debug);
         self::_setSettings('lastUpdatedTime', trim($now), $preFix, $debug);
     } else {
         self::_log('NO changed products found after: "' . trim($lastUpdatedTime) . '".', '', $preFix);
     }
     self::_log('## FINISH ##############################', __CLASS__ . '::' . __FUNCTION__, $preFix, $start);
 }
示例#10
0
<?php

require_once dirname(__FILE__) . '/../../bootstrap.php';
Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
$productIds = Dao::getResultsNative('select distinct id from product where active = 1', array(), PDO::FETCH_ASSOC);
foreach ($productIds as $row) {
    try {
        $output = '';
        $cmd = 'php ' . dirname(__FILE__) . '/pricematch.php ' . $row['id'];
        $output = ExecWaitTimeout($cmd, 10);
        // 	exec($cmd, $output);
        echo print_r($output, true) . "\n";
    } catch (Exception $e) {
        echo $e->getMessage() . "\n";
    }
}
/**
 * Execute a command and kill it if the timeout limit fired to prevent long php execution
 * 
 * @see http://stackoverflow.com/questions/2603912/php-set-timeout-for-script-with-system-call-set-time-limit-not-working
 * 
 * @param string $cmd Command to exec (you should use 2>&1 at the end to pipe all output)
 * @param integer $timeout
 * @return string Returns command output 
 */
function ExecWaitTimeout($cmd, $timeout = 5)
{
    echo $cmd . "\n";
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $pipes = array();
    $timeout += time();
示例#11
0
 /**
  * validates the token
  *
  * @param unknown $token
  * @param bool    $showHeader
  *
  * @throws Exception
  * @return APIService
  */
 private function _validateToken($token, $showHeader = false)
 {
     if ($showHeader) {
         header("WWW-Authenticate: Basic realm=\"" . $this->_realm . "\"");
     }
     if (($token = trim($token)) === '') {
         throw new Exception('Invalid access, please login first!', 401);
     }
     $key = $this->_getTokenKey();
     $ciphertext_dec = base64_decode($token);
     $iv_size = $this->_getTokenVISize();
     $iv_dec = substr($ciphertext_dec, 0, $iv_size);
     $ciphertext_dec = substr($ciphertext_dec, $iv_size);
     $plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);
     $this->log('decrypted token: "' . $plaintext_dec . '"', __CLASS__ . '::' . __FUNCTION__, '## ');
     $information = explode('|', $plaintext_dec);
     $this->log('got information: "' . preg_replace("/[\n\r]/", " ", print_r($information, true)), __CLASS__ . '::' . __FUNCTION__, self::TAB);
     if (!isset($information[1]) || preg_match('/^\\d{4}-\\d{2}-\\d{2}\\ \\d{2}:\\d{2}:\\d{2}$/', $fromDate = trim($information[1])) !== 1) {
         $this->log('invalid fromDate!', '', self::TAB);
         throw new Exception('Invalid token, please login first!');
     }
     $fromDate = new UDate($fromDate);
     $this->log('Got fromDate: ' . $fromDate, '', self::TAB);
     if (!isset($information[2]) || preg_match('/^\\d{4}-\\d{2}-\\d{2}\\ \\d{2}:\\d{2}:\\d{2}$/', $toDate = trim($information[2])) !== 1) {
         $this->log('invalid toDate!', '', self::TAB);
         throw new Exception('Invalid token, please login first!!');
     }
     $toDate = new UDate($toDate);
     $this->log('Got toDate: ' . $toDate, '', self::TAB);
     $now = UDate::now();
     $this->log('Got NOW: ' . $now, '', self::TAB);
     if ($now->after($toDate) || $now->before($fromDate)) {
         $this->log('Token expired.', '', self::TAB);
         throw new Exception('Token expired.');
     }
     if (!isset($information[0]) || !($userAccount = UserAccount::get(trim($information[0]))) instanceof UserAccount) {
         $this->log('Invalid useraccount.', '', self::TAB);
         throw new Exception('Invalid token, please login first.');
     }
     $role = null;
     if (count($roles = $userAccount->getRoles()) > 0) {
         $role = $roles[0];
     }
     $this->log('Got User: '******'', self::TAB);
     Core::setUser($userAccount, $role);
     return $this;
 }
示例#12
0
 /**
  * unserialize all the components and store them in Core
  * 
  * @param string $string The serialized core storage string
  */
 public static function unserialize($string)
 {
     self::$_storage = unserialize($string);
     Core::setUser(self::$_storage['user'], self::$_storage['role']);
     return self::$_storage;
 }
示例#13
0
 /**
  * get category info by magento-b2b productCategory id
  *
  * @param string $systemid
  *
  * @return string
  * @soapmethod
  */
 public function getCategory($systemid)
 {
     $response = $this->_getResponse(UDate::now());
     try {
         $systemid = intval(trim($systemid));
         Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
         //TODO
         $obj = ProductCategory::get($systemid);
         if (!$obj instanceof ProductCategory) {
             throw new Exception('category with system id "' . $systemid . '" does not exist.');
         }
         $response['status'] = self::RESULT_CODE_SUCC;
         $this->addCData('category', json_encode($obj->getJson()), $response);
     } catch (Exception $e) {
         $response['status'] = self::RESULT_CODE_FAIL;
         $this->addCData('error', $e->getMessage(), $response);
     }
     return trim($response->asXML());
 }
示例#14
0
 /**
  * Writting the Session Data
  *
  * @param string $sessionId   The sesison ID
  * @param string $sessionData The sesison data
  *
  * @return Session|null
  */
 public static function write($sessionId, $sessionData)
 {
     $user = ($user = Core::getUser()) instanceof UserAccount ? $user : UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT);
     Core::setUser($user, Core::getRole());
     $session = ($session = self::getSession($sessionId)) instanceof Session ? $session : new Session();
     return $session->setKey($sessionId)->setData($sessionData)->save();
 }