Example #1
0
 function process(Mobile_API_Request $request)
 {
     $response = new Mobile_API_Response();
     $username = $request->get('username');
     $password = $request->get('password');
     $current_user = CRMEntity::getInstance('Users');
     $current_user->column_fields['user_name'] = $username;
     if (vtlib_isModuleActive('Mobile') === false) {
         $response->setError(1501, 'Service not available');
         return $response;
     }
     if (!$current_user->load_user($password) || !$current_user->authenticated) {
         global $mod_strings;
         $response->setError(1210, $mod_strings['ERR_INVALID_PASSWORD']);
     } else {
         // Start session now
         $sessionid = Mobile_API_Session::init();
         if ($sessionid === false) {
             echo "Session init failed {$sessionid}\n";
         }
         include_once 'config.php';
         global $application_unique_key;
         $current_user->id = $current_user->retrieve_user_id($username);
         $this->setActiveUser($current_user);
         $_SESSION["authenticated_user_id"] = $current_user->id;
         $_SESSION["app_unique_key"] = $application_unique_key;
         $result = array();
         $result['login'] = array('userid' => $current_user->id, 'crm_tz' => DateTimeField::getDBTimeZone(), 'user_tz' => $current_user->time_zone, 'session' => $sessionid, 'language' => $current_user->language, 'vtiger_version' => Mobile_WS_Utils::getVtigerVersion(), 'mobile_module_version' => Mobile_WS_Utils::getVersion());
         $response->setResult($result);
         $this->postProcess($response);
     }
     return $response;
 }
Example #2
0
 function process(Mobile_API_Request $request)
 {
     $response = new Mobile_API_Response();
     $username = $request->get('username');
     $password = $request->get('password');
     $current_user = CRMEntity::getInstance('Users');
     $current_user->column_fields['user_name'] = $username;
     if (vtlib_isModuleActive('Mobile') === false) {
         $response->setError(1501, 'Service not available');
         return $response;
     }
     if (!$current_user->doLogin($password)) {
         $response->setError(1210, 'Authentication Failed');
     } else {
         // Start session now
         $sessionid = Mobile_API_Session::init();
         if ($sessionid === false) {
             echo "Session init failed {$sessionid}\n";
         }
         $current_user->id = $current_user->retrieve_user_id($username);
         $current_user->retrieveCurrentUserInfoFromFile($current_user->id);
         $this->setActiveUser($current_user);
         $result = array();
         $result['login'] = array('userid' => $current_user->id, 'crm_tz' => DateTimeField::getDBTimeZone(), 'user_tz' => $current_user->time_zone, 'user_currency' => $current_user->currency_code, 'session' => $sessionid, 'vtiger_version' => Mobile_WS_Utils::getVtigerVersion(), 'date_format' => $current_user->date_format, 'mobile_module_version' => Mobile_WS_Utils::getVersion());
         $response->setResult($result);
         $this->postProcess($response);
     }
     return $response;
 }
Example #3
0
 static function process(Mobile_API_Request $request)
 {
     $operation = $request->getOperation();
     $sessionid = HTTP_Session::detectId();
     //$request->getSession();
     if (empty($operation)) {
         $operation = 'login';
     }
     $response = false;
     if (isset(self::$opControllers[$operation])) {
         $operationFile = self::$opControllers[$operation]['file'];
         $operationClass = self::$opControllers[$operation]['class'];
         include_once dirname(__FILE__) . $operationFile;
         $operationController = new $operationClass();
         $operationSession = false;
         if ($operationController->requireLogin()) {
             $operationSession = Mobile_API_Session::init($sessionid);
             if ($operationController->hasActiveUser() === false) {
                 $operationSession = false;
             }
             //Mobile_WS_Utils::initAppGlobals();
         } else {
             // By-pass login
             $operationSession = true;
         }
         if ($operationSession === false) {
             $response = new Mobile_API_Response();
             $response->setError(1501, 'Login required');
         } else {
             try {
                 $response = $operationController->process($request);
             } catch (Exception $e) {
                 $response = new Mobile_API_Response();
                 $response->setError($e->getCode(), $e->getMessage());
             }
         }
     } else {
         $response = new Mobile_API_Response();
         $response->setError(1404, 'Operation not found: ' . $operation);
     }
     if ($response !== false) {
         if ($response->hasError()) {
             include_once dirname(__FILE__) . '/ui/Error.php';
             $errorController = new Mobile_UI_Error();
             $errorController->setError($response->getError());
             echo $errorController->process($request)->emitHTML();
         } else {
             echo $response->emitHTML();
         }
     }
 }
Example #4
0
 function initController($className, $handlerPath, $user)
 {
     include_once dirname(__FILE__) . "/{$handlerPath}";
     $this->controller = new $className();
     Mobile_API_Session::init(session_id());
     $this->controller->initActiveUser($user);
     return $this->controller;
 }