/**
  * Initial connect function to get the user details and also to check the user tocken
  */
 public function connectAction()
 {
     $this->_getSession()->unsSignup();
     $token = $this->getRequest()->getParam('token');
     $host = $this->getRequest()->getParam('host');
     //Load the user object with the bc-token
     $user = App_Main::getModel('stages/user')->load($token, 'bc_auth_token');
     //login and redirect to homepage if the user is already registered
     if ($user->getId()) {
         $user->setSessionUser($user);
         echo Zend_Json::encode(array('redirect' => App_Main::getUrl('')));
         return;
     }
     //Get the Basecamp connect object
     $bcConnect = new Connect_Basecamp($host, $token, 'X', 'xml');
     $userXml = $bcConnect->getMe();
     if (!empty($userXml['body']) && $userXml['status'] == '200 OK') {
         $userArray = App_Main::getHelper('stages')->XMLToArray($userXml['body']);
         $return = array('success' => 1, 'username' => $userArray['user-name'], 'firstname' => $userArray['first-name'], 'lastname' => $userArray['last-name'], 'avatar' => $userArray['avatar-url'], 'token' => $userArray['token']);
         $signUp = App_Main::getModel('core/object');
         $signUp->setMode('bc_token_connect');
         $signUp->setToken($token);
         $signUp->setHost($host);
         $this->_getSession()->setSignup($signUp);
     } else {
         $return = array('success' => 0);
     }
     echo Zend_Json::encode($return);
 }
Exemple #2
0
 /**
  * Initialize visitor information from server data
  *
  * @return Core_Model_Visitor
  */
 public function initServerData()
 {
     /* @var $helper Core_Helper_Http */
     $helper = App_Main::getHelper('core/http');
     $this->addData(array('server_addr' => $helper->getServerAddr(true), 'remote_addr' => $helper->getRemoteAddr(true), 'http_secure' => false, 'http_host' => $helper->getHttpHost(true), 'http_user_agent' => $helper->getHttpUserAgent(true), 'http_accept_language' => $helper->getHttpAcceptLanguage(true), 'http_accept_charset' => $helper->getHttpAcceptCharset(true), 'request_uri' => $helper->getRequestUri(true), 'session_id' => $this->_getSession()->getSessionId(), 'http_referer' => $helper->getHttpReferer(true)));
     return $this;
 }
Exemple #3
0
 /**
  * Get the helper object instace
  * 
  * @return Stages_Helper_Data 
  */
 public function _getHelper()
 {
     if (!$this->_helperStages) {
         $this->_helperStages = App_Main::getHelper('stages');
     }
     return $this->_helperStages;
 }
Exemple #4
0
 /**
  * get the helper object
  *
  * @param   string $name
  * @return  Core_Helper_Abstract
  */
 public function helper($name)
 {
     $helper = App_Main::getHelper($name);
     if (!$helper) {
         return false;
     }
     return $helper->setLayout($this);
 }
Exemple #5
0
 /**
  * Prepare the milestone data for JSON
  * 
  * - type
  * - title
  * - ms_user
  * - ms_date
  * - bc_id
  * 
  * @return array 
  */
 public function prepareDataForJson()
 {
     $msData = array();
     $msData['type'] = $this->getType() ? $this->getType() : 'd';
     $msData['title'] = $this->getTitle();
     $msData['ms_user'] = $this->getUserResponsible();
     $msData['ms_date'] = App_Main::getHelper('stages')->formatDateForJs(strtotime($this->getMilestoneDate()));
     $msData['bc_id'] = $this->getBcId();
     return $msData;
 }
Exemple #6
0
 /**
  * Returns the REQUEST_URI taking into account
  * platform differences between Apache and IIS
  *
  * @param boolean $clean clean non UTF-8 characters
  * @return string
  */
 public function getRequestUri($clean = false)
 {
     $uri = $this->_getRequest()->getRequestUri();
     if ($clean) {
         $uri = App_Main::getHelper('core/string')->cleanString($uri);
     }
     return $uri;
 }
Exemple #7
0
 /**
  * Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param)
  *
  * @return string
  */
 protected function _getRefererUrl()
 {
     $refererUrl = $this->getRequest()->getServer('HTTP_REFERER');
     if ($url = $this->getRequest()->getParam(self::PARAM_NAME_REFERER_URL)) {
         $refererUrl = $url;
     }
     if ($url = $this->getRequest()->getParam(self::PARAM_NAME_BASE64_URL)) {
         $refererUrl = App_Main::getHelper('core')->urlDecode($url);
     }
     if ($url = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
         $refererUrl = App_Main::getHelper('core')->urlDecode($url);
     }
     if (!$this->_isUrlInternal($refererUrl)) {
         $refererUrl = App_Main::getBaseUrl();
     }
     return $refererUrl;
 }
Exemple #8
0
 /**
  * Get the helper class for the module tyepe
  * 
  * @param string module
  * @return Core_Helper_Abstract
  */
 public function helper($name)
 {
     if ($this->getLayout()) {
         return $this->getLayout()->helper($name);
     }
     return App_Main::getHelper($name);
 }
Exemple #9
0
 /**
  * Returns the base url confogurd for the current website, if not return the default url
  *
  * @param string $type
  * @param bool $secure
  * @return string url
  */
 public function getBaseUrl($type = self::URL_TYPE_LINK, $secure = null)
 {
     $cacheKey = $type . '/' . (is_null($secure) ? 'null' : ($secure ? 'true' : 'false'));
     if (!isset($this->_baseUrlCache[$cacheKey])) {
         switch ($type) {
             case self::URL_TYPE_WEB:
                 $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool) $secure;
                 $url = $this->getConfig('web-' . ($secure ? 'secure' : 'unsecure') . '-base-url');
                 break;
             case self::URL_TYPE_LINK:
                 $secure = (bool) $secure;
                 $url = $this->getConfig('web-' . ($secure ? 'secure' : 'unsecure') . '-base-url');
                 break;
             case self::URL_TYPE_SKIN:
             case self::URL_TYPE_MEDIA:
             case self::URL_TYPE_JS:
                 $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool) $secure;
                 $url = $this->getConfig('web-' . ($secure ? 'secure' : 'unsecure') . '-base-' . $type . '-url');
                 break;
             default:
                 throw App_Main::exception('Core', App_Main::getHelper('core')->__('Invalid base url type'));
         }
         //load the default url from App_Main if the url is not set
         if (empty($url)) {
             $url = !$secure ? SERVER_URI : SECURE_SERVER_URI;
         }
         $this->_baseUrlCache[$cacheKey] = rtrim($url, '/') . '/';
     }
     return $this->_baseUrlCache[$cacheKey];
 }
Exemple #10
0
 /**
  * Prepare the project data array for passing in JSON format
  *  - id
  *  - title
  *  - bc_id
  *  - leads [m]
  *  - leads [d]
  *  - start_date
  *  - end_date
  * IF $incTime include time-entries @todo not implemented
  * IF $incMilestonee include milestone and todolist information
  *  Milestone 
  *      - title
  *      - type
  *      - user
  *      - date
  *      - bc_id
  *      - todo_stats
  *              - lists
  *              - count (total todos)
  *              - completed
  *              - uncomplted
  *              - comments
  *              - hours
  *      
  * 
  * @param bool $incMilestone
  * @param bool $incTime
  * @return type 
  */
 public function prepareDataForJson($incMilestone = false, $incTime = false, $refreshBc = false)
 {
     if (!$this->getId()) {
         return false;
     }
     $data = array();
     $data['id'] = $this->getId();
     $data['title'] = $this->getTitle();
     $data['bc_id'] = $this->getBcId();
     $data['bc_link'] = $this->getProfileUrl();
     $data['leads']['m'] = $this->getMLead();
     $data['leads']['d'] = $this->getDLead();
     $data['start_date'] = App_Main::getHelper('stages')->formatDateForJs(strtotime($this->getStartDate()));
     $data['end_date'] = App_Main::getHelper('stages')->formatDateForJs(strtotime($this->getEndDate()));
     if ($incTime) {
         $times = $this->getTimeEntries();
     }
     if ($incMilestone) {
         $milestones = $this->getMilestones($refreshBc);
         $todoLists = $this->getTodoLists($refreshBc);
         if (!$todoLists) {
             $todoLists = array();
         }
         $todos = $this->getTodos($refreshBc);
         //todos are loaded to record the time entries and comments, other stats like total, completed, uncompleted are retrived along with todolist
         if (empty($milestones) && !$refreshBc) {
             $milestones = $this->getMilestones(true);
         }
         if (!empty($milestones) && empty($todoLists) && !$refreshBc) {
             $todoLists = $this->getTodoLists(true);
         }
         $msArray = array();
         foreach ($milestones as $milestone) {
             $msData = $milestone->prepareDataForJson();
             //add todo list status
             $todoData = array('lists' => 0, 'count' => 0, 'completed' => 0, 'uncompleted' => 0, 'comments' => 0, 'hours' => 0);
             foreach ($todoLists as $todoList) {
                 //continue if the todolist is not assiged under the current processed milestone
                 if ($milestone->getBcId() != $todoList->getMilestoneId()) {
                     continue;
                 }
                 $todoData['lists'] += 1;
                 $todoData['count'] += $todoList->getTodoCount();
                 $todoData['completed'] += $todoList->getTodoCompleted();
                 $todoData['uncompleted'] += $todoList->getTodoUncompleted();
                 //add the todo comments and hour status
                 $todos = $todoList->getTodos();
                 //add the todo specific info into the todo stats (total comments and total hours)
                 if (!empty($todos) && is_array($todos)) {
                     foreach ($todos as $todo) {
                         $todoData['comments'] += $todo->getCommentCount();
                         $todoData['hours'] += $this->getTimeEntryForTodo($todo->getBcId());
                         //$todo->getTimeEntry();
                     }
                 }
             }
             $msData['todo_stats'] = $todoData;
             $msData['ms_status_display'] = App_Main::getHelper('stages')->processMilestoneStats($milestone, $todoData);
             $msArray[] = $msData;
         }
         $data['milestones'] = $msArray;
     }
     return $data;
 }
Exemple #11
0
 /**
  * Get the encripted password string 
  * 
  * @param string $pwd
  * @return string 
  */
 protected function _getEncodedPassword($pwd)
 {
     return App_Main::getHelper('core')->getHash($pwd, 2);
 }
Exemple #12
0
 /**
  * Retrieve unique user data for validator
  *
  * @return array
  */
 public function getValidatorData()
 {
     $parts = array(self::VALIDATOR_REMOTE_ADDR_KEY => '', self::VALIDATOR_HTTP_VIA_KEY => '', self::VALIDATOR_HTTP_X_FORVARDED_FOR_KEY => '', self::VALIDATOR_HTTP_USER_AGENT_KEY => '');
     // collect ip data
     if (App_Main::getHelper('core/http')->getRemoteAddr()) {
         $parts[self::VALIDATOR_REMOTE_ADDR_KEY] = App_Main::getHelper('core/http')->getRemoteAddr();
     }
     if (isset($_ENV['HTTP_VIA'])) {
         $parts[self::VALIDATOR_HTTP_VIA_KEY] = (string) $_ENV['HTTP_VIA'];
     }
     if (isset($_ENV['HTTP_X_FORWARDED_FOR'])) {
         $parts[self::VALIDATOR_HTTP_X_FORVARDED_FOR_KEY] = (string) $_ENV['HTTP_X_FORWARDED_FOR'];
     }
     // collect user agent data
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
         $parts[self::VALIDATOR_HTTP_USER_AGENT_KEY] = (string) $_SERVER['HTTP_USER_AGENT'];
     }
     return $parts;
 }
Exemple #13
0
 /**
  * Get Session Form Key
  *
  * @return string 16 bit unique key for forms
  */
 public function getFormKey()
 {
     if (!$this->getData('_form_key')) {
         $this->setData('_form_key', App_Main::getHelper('core')->getRandomString(16));
     }
     return $this->getData('_form_key');
 }
Exemple #14
0
 /**
  * Save url information
  *
  * @param   Core_Model_Visitor $visitor
  * @return  Core_Model_Resource_Visitor
  */
 protected function _saveUrlInfo(Core_Model_Abstract $visitor)
 {
     $this->_getWriteAdapter()->insert($this->tbl_url_info, array('url' => $this->_prepareValueForSave(App_Main::getHelper('core/string')->substr($visitor->getUrl(), 0, 250)), 'referer' => $this->_prepareValueForSave(App_Main::getHelper('core/string')->substr($visitor->getHttpReferer(), 0, 250))));
     $visitor->setLastUrlId($this->_getWriteAdapter()->lastInsertId());
     return $this;
 }
Exemple #15
0
 /**
  * Submit the new passowrd from the user and update the same after validation
  * @return type 
  */
 public function change_passwordAction()
 {
     $currPass = $this->getRequest()->getParam('password');
     $newPass = $this->getRequest()->getParam('new_password');
     //check for user session
     if (!($user = $this->_getSession()->getUser())) {
         echo Zend_Json::encode(array('redirect' => App_Main::getUrl('init_login')));
         return;
     }
     //validate the current password
     if (!App_Main::getHelper('core')->validateHash($currPass, $user->getPassword())) {
         echo Zend_Json::encode(array('success' => 0, 'error' => 'Please enter your correct password'));
         return;
     }
     $success = array('success' => 1);
     if ($this->getRequest()->getParam('forced_from_login')) {
         $user->resetPassword($newPass, false, false);
         //check whether the signup object is defined in the session else redirect to the user profile page
         $success['redirect'] = $this->_getSession()->getSignup() ? App_Main::getUrl('init_signup_continue') : $user->getProfileUrl();
     } else {
         $user->resetPassword($newPass, false, false);
     }
     echo Zend_Json::encode($success);
     return;
 }
Exemple #16
0
 /**
  * Reset the current password
  * If no arguments are passed the password will be reset by the system and 
  * a mail will be sent to the registered email address, so that the user can 
  * reset the autogenerated password on next login
  * 
  * @param string $pass
  * @param bool $sendEmail
  * @param bool $changeOnNextLogin
  * @return Stages_Model_User 
  */
 public function resetPassword($pass = null, $sendEmail = true, $changeOnNextLogin = true)
 {
     if (!$this->getUserId()) {
         App_Main::getSession()->addError('Unable to find your email in our database');
         return false;
     }
     $passwordNew = !empty($pass) ? $pass : App_Main::getHelper('core')->getRandomString(8);
     $passwordHash = App_Main::getHelper('core')->gethash($passwordNew, 2);
     $this->setPassword($passwordHash);
     //Update the password into the user table
     $this->_getResource()->resetPassword($this->getId(), $passwordHash, $changeOnNextLogin);
     if ($sendEmail) {
         $this->sendNewPasswordEmail($passwordNew);
     }
     return $this;
 }