public function ajaxloginAction() { if (!$this->security->checkToken()) { echo "检查到跨域攻击!"; $this->view->disable(); return; } $email = $_POST["email"]; $password = $_POST["password"]; $db_user = model\userOriginal::findFirstByEmail($email); if ($db_user) { if (!password_verify($password, $db_user->pwd_hash)) { echo '密码错误'; $this->view->disable(); return; } else { $user = model\user::findFirstById($db_user->user_id); //将user表中的数据存入session $this->session->set("current_user", serialize($user)); session_write_close(); if (isset($_POST["rm"]) && $_POST["rm"] == "true") { $selector = bin2hex(openssl_random_pseudo_bytes(12)); $token = bin2hex(openssl_random_pseudo_bytes(12)); $token_hash = hash('sha256', $token); //确定当前数据库中是否有该user的记录 $db_auth = model\rmAuthToken::findFirstByUser_id($db_user->id); if ($db_auth) { //有,就更新 $db_auth->selector = $selector; $db_auth->token_hash = $token_hash; $db_auth->update(); } else { //没有,就创建 $rm_auth_token = new model\rmAuthToken(); $rm_auth_token->selector = $selector; $rm_auth_token->token_hash = $token_hash; $rm_auth_token->user_id = $db_user->id; $rm_auth_token->create(); } setcookie("login_auth", $selector . ":" . $token, time() + 60 * 60 * 24 * 30); } echo 'ok'; $this->view->disable(); return; } } else { echo '用户尚未注册,点击下方链接开始注册'; $this->view->disable(); return; } }
/** * 微信个人中心 * URL:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe5cc657d28788f78&redirect_uri=http%3a%2f%2fcssv.anneijia.com%2Flogin%2FwechatLogin&response_type=code&scope=snsapi_userinfo&state=ik#wechat_redirect * */ public function wechatMeAction() { require_once "/../../utility/wechat.class.php"; $weObj = new \UtillYou\Utility\Wechat(); $OAuthToken = $weObj->getOauthAccessToken(); if (!$OAuthToken) { echo '请通过微信客户端进入'; $this->view->disable(); return; } $O_user_info = $weObj->getOauthUserinfo($OAuthToken['access_token'], $OAuthToken['openid']); $sql = "call p_wechat_user_login(?,?,?,?,?,?,?,?,?)"; $common = new model\common(); $result = $common->getReadConnection()->query($sql, array($O_user_info['openid'], $O_user_info['nickname'], $O_user_info['sex'], $O_user_info['province'], $O_user_info['city'], $O_user_info['country'], $O_user_info['privilege'], $O_user_info['headimgurl'], isset($O_user_info['unionid']) ? $O_user_info['unionid'] : ''))->fetchAll(); $db_user = (object) $result[0]; $this->session->set("current_user", serialize($db_user)); $db_auth = model\rmAuthToken::findFirstByUser_id($db_user->id); if ($db_auth) { //有,就更新 $db_auth->selector = $selector; $db_auth->token_hash = $token_hash; $db_auth->update(); } else { //没有,就创建 $rm_auth_token = new model\rmAuthToken(); $rm_auth_token->selector = $selector; $rm_auth_token->token_hash = $token_hash; $rm_auth_token->user_id = $db_user->id; $rm_auth_token->create(); } setcookie("login_auth", $selector . ":" . $token, time() + 60 * 60 * 24 * 30); return $this->response->redirect("user/me/" . $db_user->id); }