diff --git a/framework/router.class.php b/framework/router.class.php index 4c482fa6b9..935aed0eb4 100755 --- a/framework/router.class.php +++ b/framework/router.class.php @@ -1425,6 +1425,12 @@ class router $view->methodVar = $this->config->methodVar; $view->viewVar = $this->config->viewVar; $view->sessionVar = $this->config->sessionVar; + + $this->session->set('rand', mt_rand(0, 10000)); + $view->sessionName = session_name(); + $view->sessionID = session_id(); + $view->rand = $this->session->rand; + $view->expiredTime = ini_get('session.gc_maxlifetime'); echo json_encode($view); } diff --git a/module/user/control.php b/module/user/control.php index 73c6d398af..05fd4066a3 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -588,9 +588,22 @@ class user extends control $loginLink = $this->createLink('user', 'login'); $denyLink = $this->createLink('user', 'deny'); + /* Reload lang by lang of get when viewType is json. */ + if($this->app->getViewType() == 'json' and $this->get->lang) + { + $this->app->setClientLang($this->get->lang); + $this->app->loadLang('user'); + } + /* If user is logon, back to the rerferer. */ if($this->user->isLogon()) { + if($this->app->getViewType() == 'json') + { + $data = $this->user->getDataInJSON($this->app->user); + die(json_encode(array('status' => 'success') + $data)); + } + if(strpos($this->referer, $loginLink) === false and strpos($this->referer, $denyLink) === false ) @@ -613,7 +626,12 @@ class user extends control if($this->post->password) $password = $this->post->password; if($this->get->password) $password = $this->get->password; - if($this->user->checkLocked($account)) die(js::error(sprintf($this->lang->user->loginLocked, $this->config->user->lockMinutes))); + if($this->user->checkLocked($account)) + { + $failReason = sprintf($this->lang->user->loginLocked, $this->config->user->lockMinutes); + if($this->app->getViewType() == 'json') die(json_encode(array('status' => 'failed', 'reason' => $failReason))); + die(js::error($failReason)); + } $user = $this->user->identify($account, $password); @@ -636,7 +654,11 @@ class user extends control strpos($this->post->referer, $denyLink) === false ) { - if($this->app->getViewType() == 'json') die(json_encode(array('status' => 'success'))); + if($this->app->getViewType() == 'json') + { + $data = $this->user->getDataInJSON($user); + die(json_encode(array('status' => 'success') + $data)); + } /* Get the module and method of the referer. */ if($this->config->requestType == 'PATH_INFO') @@ -666,14 +688,18 @@ class user extends control } else { - if($this->app->getViewType() == 'json') die(json_encode(array('status' => 'success'))); + if($this->app->getViewType() == 'json') + { + $data = $this->user->getDataInJSON($user); + die(json_encode(array('status' => 'success') + $data)); + } die(js::locate($this->createLink($this->config->default->module), 'parent')); } } else { - if($this->app->getViewType() == 'json') die(json_encode(array('status' => 'failed'))); - $fails = $this->user->failPlus($account); + $fails = $this->user->failPlus($account); + if($this->app->getViewType() == 'json') die(json_encode(array('status' => 'failed', 'reason' => $this->lang->user->loginFailed))); $remainTimes = $this->config->user->failTimes - $fails; if($remainTimes <= 0) { @@ -739,6 +765,8 @@ class user extends control session_destroy(); setcookie('za', false); setcookie('zp', false); + + if($this->app->getViewType() == 'json') die(json_encode(array('status' => 'success'))); $vars = !empty($referer) ? "referer=$referer" : ''; $this->locate($this->createLink('user', 'login', $vars)); } diff --git a/module/user/model.php b/module/user/model.php index 39777b4b70..6d6cd0fae7 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -773,4 +773,35 @@ class userModel extends model { return $this->dao->delete()->from(TABLE_USERCONTACT)->where('id')->eq($listID)->exec(); } + + /** + * Get data in JSON. + * + * @param object $user + * @access public + * @return array + */ + public function getDataInJSON($user) + { + $data = array(); + $data['user'] = new stdclass(); + $data['user']->id = $user->id; + $data['user']->account = $user->account; + $data['user']->email = $user->email; + $data['user']->realname = $user->realname; + $data['user']->gender = $user->gender; + $data['user']->dept = $user->dept; + $data['user']->role = $user->role; + + $this->app->loadLang('todo'); + $this->app->loadLang('task'); + $this->app->loadLang('bug'); + $this->app->loadLang('story'); + $data['todoStatus'] = $this->lang->todo->statusList; + $data['taskStatus'] = $this->lang->task->statusList; + $data['bugStatus'] = $this->lang->bug->statusList; + $data['storyStatus'] = $this->lang->story->statusList; + + return $data; + } } diff --git a/www/index.php b/www/index.php index f60cf290c4..13b6985b42 100644 --- a/www/index.php +++ b/www/index.php @@ -29,8 +29,7 @@ $startTime = getTime(); /* Instance the app. */ $app = router::createApp('pms', dirname(dirname(__FILE__))); -/* Check the reqeust is getconfig or not. Check installed or not. */ -if(isset($_GET['mode']) and $_GET['mode'] == 'getconfig') die($app->exportConfig()); // +/* installed or not. */ if(!isset($config->installed) or !$config->installed) die(header('location: install.php')); /* Detect mobile. */ @@ -44,6 +43,9 @@ if(!$mobile->isTablet() and $mobile->isMobile()) /* Run the app. */ $common = $app->loadCommon(); +/* Check the reqeust is getconfig or not. */ +if(isset($_GET['mode']) and $_GET['mode'] == 'getconfig') die($app->exportConfig()); // + /* Check for need upgrade. */ $config->installedVersion = $common->loadModel('setting')->getVersion(); if(!(!is_numeric($config->version{0}) and $config->version{0} != $config->installedVersion{0}) and version_compare($config->version, $config->installedVersion, '>')) die(header('location: upgrade.php'));