diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 2601283e..cfec11f1 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,6 +1,7 @@ _getParam('type'); + $client = new Client(); + $url = $client->makeRequestCodeUrl($type); + + view::Post($this,"为您转入科技网登录入口",$url); + } + + //oauth2登录回调地址 + public function callbackAction() + { + $type = $this->_getParam('type'); + $code = $this->_getParam('code'); + + $client = new Client($type); + + $client->initSource(); + $target = $client->getSource()->getTarget($type); + $this->view->target_name = $target['name']; + + //$token = $client->requestToken($code); + + $token = array( + "expires_in"=>(int)432000, + "refresh_token"=>(string)"eb40e792e05a21e779aa89d71066fa61", + "userInfo"=>(string)'{"passwordType":"password_umt","securityEmail":"liujin834@live.com","cstnetIdStatus":"active","umtId":"10247308","truename":"李建轩","cstnetId":"liujin834@live.com","type":"umt"}', + "access_token"=>(string)"48415c56215f5cd26baabe403864aaf7" + ); + + if(is_string($token)) + { + view::Post($this,$token,'/account/login'); + } + + $status = $client->storageTokenData($type,$token); + + if($status === true) + { + echo ""; + }else{ + echo $status; + } + } } diff --git a/application/default/controllers/OpenController.php b/application/default/controllers/OpenController.php new file mode 100644 index 00000000..65805abe --- /dev/null +++ b/application/default/controllers/OpenController.php @@ -0,0 +1,165 @@ +view->config = $this->config = \Zend_Registry::get('config'); + $this->db = \Zend_Registry::get('db'); + $this->view->theme = new Theme(); + $this->_helper->layout->setLayout('layout-open'); + } + + function indexAction() + { + $this->view->pageID = "open-index"; + } + + //我的应用 + function myappAction() + { + $this->view->pageID = "open-myapp"; + + $app = new App(); + + $user_state = $app->checkinfo(); + if( $user_state !== true) + { + view::post($this,$user_state,"/account/edit"); + } + + $ac = $this->_getParam('ac'); + $id = $this->_getParam('id'); + $submit = $this->_getParam('submit'); + + if(empty($ac)) + { + $this->view->myapp = $app->getUserApp(); + return true; + } + + if($ac == "create") + { + $this->_helper->viewRenderer('myapp-create'); + + $this->view->appStatus = $app->appStatus(); + + if(!empty($id)) + { + $this->view->info = $app->getAppInfo($id); + } + + if(!empty($submit)) + { + if(empty($id)) + { + $status = $app->appCreate(); + }else{ + $this->view->info = $app->getAppCreateParam(); + $status = $app->appCreate($id); + } + + if($status !== true && !is_numeric($status)) + { + $this->view->error = view::Error($status); + }else{ + if(!empty($id)) + view::Post($this,"修改成功!",'/open/myapp/ac/view/id/'.$id); + else + view::Post($this,"添加成功!","/open/myapp/ac/view/id/".$status); + } + + } + return true; + } + + if($ac == "delete") + { + $status = $app->delete($id); + if($status !== true) + { + view::Post($this,$status,"/open/myapp"); + }else{ + view::Post($this,'删除成功',"/open/myapp"); + } + return false; + } + + if($ac == "view") + { + $this->_helper->viewRenderer('myapp-view'); + $this->view->data = $app->getAppInfo($id); + $this->view->appStatus = $app->appStatus(); + return true; + } + + } + + function authenticateAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = array( + 'client_id' => $this->_getParam('client_id'), + 'redirect_uri' => $this->_getParam('redirect_uri'), + 'client_secret' => $this->_getParam('client_secret'), + 'host' => $_SERVER['HTTP_HOST'], + 'ip' => $_SERVER['REMOTE_ADDR'] + ); + + $server = new Server(); + + $status = $server->clientCredentials($data['client_id'],$data['client_secret']); + + if($status !== true) + { + echo $status; + }else{ + + } + + } + + function authorizeAction() + { + $submit = $this->_getParam('submit'); + + if(empty($submit)) + { + return true; + } + + $sv = new open\server(); + $server = $sv->bootstrap(); + + $request = OAuth2\Request::createFromGlobals(); + $response = new OAuth2\Response(); + + // validate the authorize request + if (!$server->validateAuthorizeRequest($request, $response)) { + $response->send(); + die; + } + + // print the authorization code if the user has authorized your client + $is_authorized = ($_POST['authorized'] === 'yes'); + $server->handleAuthorizeRequest($request, $response, $is_authorized); + if ($is_authorized) { + // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); + exit("SUCCESS! Authorization Code: $code"); + } + $response->send(); + } + +} + diff --git a/application/default/views/scripts/account/application-add.phtml b/application/default/views/scripts/account/application-add.phtml new file mode 100644 index 00000000..192d78b2 --- /dev/null +++ b/application/default/views/scripts/account/application-add.phtml @@ -0,0 +1,43 @@ +headTitle($this->config->title->site); + $this->headTitle('网站接入'); + $this->headTitle()->setSeparator(' - '); +?> +
+
+ +
+
+

应用接入

+
+ msg)) { ?> + msg ?> + + error)) { ?> + error ?> + +
+
+ +
+ info['name']; ?>" /> +
+
+
+ +
+ info['uri']; ?>" /> +
+
+ +
+ + + +
+
+ +
+
diff --git a/application/default/views/scripts/account/application.phtml b/application/default/views/scripts/account/application.phtml new file mode 100644 index 00000000..699fad4d --- /dev/null +++ b/application/default/views/scripts/account/application.phtml @@ -0,0 +1,25 @@ +headTitle($this->config->title->site); + $this->headTitle('我的账户'); + $this->headTitle()->setSeparator(' - '); +?> +
+
+ +
+
+ 应用接入 +

应用管理

+
+ msg)) { ?> + msg ?> + + error)) { ?> + error ?> + + + +
+
diff --git a/application/default/views/scripts/account/callback.phtml b/application/default/views/scripts/account/callback.phtml new file mode 100644 index 00000000..2c476ed5 --- /dev/null +++ b/application/default/views/scripts/account/callback.phtml @@ -0,0 +1,46 @@ +headTitle($this->config->title->site); + $this->headTitle('用户登录'); + $this->headTitle()->setSeparator(' - '); + $this->breadcrumb('首页'); + $this->breadcrumb('用户登录'); + $this->breadcrumb()->setSeparator(' > '); +?> + +
+
+ target_name) ? "":"您已经使用 ".$this->target_name." 账号登录
" ?> +
+
+
+ + +
+ \ No newline at end of file diff --git a/application/default/views/scripts/account/left.phtml b/application/default/views/scripts/account/left.phtml index 8608f255..c219e4d7 100644 --- a/application/default/views/scripts/account/left.phtml +++ b/application/default/views/scripts/account/left.phtml @@ -2,6 +2,7 @@ + diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index e53bd83d..a362a769 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -64,6 +64,9 @@ +
+
其它账号登录
+中国科技网通行证