public function weibo_login() { $code = $_GET['code']; $redirect_uri = "http://" . $_SERVER['HTTP_HOST'] . __APP__ . "/Api/weibo_login"; $client_id = C('WEIBO_APPKEY'); $client_secret = C('WEIBO_APPSECRET'); $access_token = ''; $expires_in = ''; $api_id = ''; $request_uri = "https://api.weibo.com/oauth2/access_token"; $post_params = array('client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'grant_type' => 'authorization_code', 'code' => $code); if ($result = $this->http_post($request_uri, $post_params)) { //parse param from weibo response $token = json_decode($result, true); $access_token = $token['access_token']; $expires_in = $token['expires_in']; //get weibo id $request_uri = "https://api.weibo.com/2/account/get_uid.json?access_token={$access_token}"; if ($result = file_get_contents($request_uri)) { $param = json_decode($result, true); $api_id = $param['uid']; //save param to session $api = array(); $api['api_vendor'] = 'weibo'; $api['api_id'] = $api_id; $api['api_token'] = $access_token; $_SESSION['api'] = $api; //check if new user $account_model = new AccountsModel(); if ($account_model->login('weibo', $api_id, 'api')) { $this->redirect('User/home'); } else { $this->redirect('User/register'); } } else { die('get weibo id failed'); } } else { die('get access token failed'); } }
public function insert() { $user_model = new UsersModel(); $account_model = new AccountsModel(); //检查验证码是否一致 if ($_SESSION['verify'] != strtolower($_POST['verify'])) { flash('验证码不一致'); $_SESSION['last_form'] = $_POST; redirect($_SERVER['HTTP_REFERER']); return; } if (empty($_POST['work_field']) && empty($_POST['expertise'])) { flash('关注领域不能为空'); $_SESSION['last_form'] = $_POST; redirect($_SERVER['HTTP_REFERER']); return; } if (!check_model()) { flash('您提交的内容中可能有不合适的地方,请重新编辑'); $_SESSION['last_form'] = $_POST; $this->redirect('register'); } if (empty($_POST['type'])) { $_POST['type'] = 'ngo'; } $_POST['create_time'] = date('Y-m-d H:i:s'); if (!$_SESSION['login_user']['is_admin']) { $_POST['is_admin'] = 0; } if ($_POST['type'] == "ind") { $_POST['is_checked'] = 1; } $user_model->create(); $account_id = $account_model->add_user($_POST); if ($account_id) { $user_model->account_id = $account_id; $user_model->password = '******'; // hide password - the real hashed password is stored in account model $user_model->add(); $account_model->login($_POST['email'], $_POST['password']); $this->redirect('home'); } else { $this->redirect('register'); //写好User/home后定位到该目标 } }