/** * 显示用户登录页面,并获取授权code */ public function authorize() { $this->oauth_server(); $server = $this->server_all; $request = \OAuth2\Request::createFromGlobals(); $response = new \OAuth2\Response(); //验证授权请求 if (!$server->validateAuthorizeRequest($request, $response)) { $response->send(); die; } // 显示登录页面 if (empty($_POST)) { if (is_login()) { echo " <meta charset=\"UTF-8\"><script>alert('不能重复登录!');window.history.go(-1);</script>"; exit; } else { $this->assign('iptype', checkUserIp()); //显示登录页面 $this->display(); } } //如果用户是授权用户就输出授权验证码 if ($_POST) { if (empty($_POST['logintype'])) { //集团登录 $result = A('Ucenter/Login', 'Widget')->company_dologin(); } else { //普通用户登录 $result = A('Ucenter/Login', 'Widget')->doLogin(); } if ($result['status']) { $is_authorized = $_POST['authorized'] === 'yes'; $userid = session('user_auth.uid'); $server->handleAuthorizeRequest($request, $response, $is_authorized, $userid); if ($is_authorized) { //跳转到回调地址,并携带code码 $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); header("Location: " . $response->getHttpHeader('Location')); } } else { $this->error($result['info']); } } $response->send(); }
public function login() { echo get_client_ip(); $this->setTitle('用户登录'); //通过ip地址获取平台域名 if (IS_POST) { if (empty($_POST['logintype'])) { //集团登录 $result = A('Ucenter/Login', 'Widget')->company_dologin(); } else { //普通用户登录 $result = A('Ucenter/Login', 'Widget')->doLogin(); } if ($result['status']) { $domain = $domain . '?code=' . $result['sessid']; $this->success('登录成功', $domain); } else { $this->error($result['info']); } } else { $this->assign('iptype', checkUserIp()); //显示登录页面 $this->display(); } }