public function callback($type = null, $code = null)
 {
     header("Content-type: text/html; charset=utf-8");
     (empty($type) || empty($code)) && $this->error('参数错误');
     import('Org.ThinkSDK.ThinkOauth');
     $sns = ThinkOauth::getInstance($type);
     //腾讯微博需传递的额外参数
     $extend = null;
     if ($type == 'tencent') {
         $extend = array('openid' => $this->_get('openid'), 'openkey' => $this->_get('openkey'));
     }
     $tokenArr = $sns->getAccessToken($code, $extend);
     $openid = $tokenArr['openid'];
     $token = $tokenArr['access_token'];
     setSessionCookie("openid", $openid);
     setSessionCookie("access_token", $token);
     //        $con = "openid:".$openid."\n"."token".$token;
     //	file_put_contents("1.txt", $con);
     //获取当前登录用户信息
     if ($openid) {
         $field = strtolower($type);
         setSessionCookie("field", $field);
         $userinfo = M("user")->field('id,name')->where("" . $field . "= '" . $openid . "'")->find();
         if ($userinfo) {
             //若是有该账号就登录
             setSessionCookie("userid", $userinfo['id']);
             setSessionCookie("username", $userinfo['name']);
             echo "<script>document.location.href='" . __APP__ . "';</script>";
             exit;
         } else {
             //没有的话绑定
             $userid = getSessionCookie('userid');
             $username = getSessionCookie('username');
             if ($userid != '' && $username != '') {
                 //用户已登录,自动绑定
                 //绑定账号
                 M('user')->where("id = " . $userid . "")->save(array($field => $openid));
                 emptySessionCookie('type');
                 emptySessionCookie('openid');
                 $this->success("绑定成功!", "/");
             } else {
                 //用户未登录,跳转到绑定页面
                 if ($filed == 'qq') {
                     //针对新版qq互联在绑定页,要显示昵称,否则不通过***
                     $data = $sns->call('user/get_user_info');
                     $nickname = $data['nickname'];
                 } else {
                     $userinfo = A('Type', 'Event')->{$type}($tokenArr);
                     $nickname = $userinfo['name'];
                 }
                 setSessionCookie('nickname', $nickname);
                 $this->redirect("Index/bind");
             }
         }
     } else {
         echo "<script>alert('系统出错;请稍后再试!');document.location.href='" . __APP__ . "';</script>";
     }
 }
Example #2
0
 public function bind()
 {
     if (IS_POST) {
         $username = I('username');
         $password = I('password', 0, 'md5');
         $field = getSessionCookie('field');
         $openid = getSessionCookie('openid');
         $id = M('user')->where(array('username' => $username, 'password' => $password))->getField('id');
         if ($id) {
             M('user')->where(array('id' => $id))->setField($field, $openid);
             emptySessionCookie('type');
             emptySessionCookie('openid');
             setSessionCookie('userid', $id);
             $this->redirect('Index/user');
         } else {
             E('用户不存在');
         }
     } else {
         $this->nickname = getSessionCookie('nickname');
         $this->display('bind');
     }
 }
 public function checkLogin()
 {
     $is_bind = I("post.is_bind", 0, 'int');
     $pwd = I('post.pwd');
     $username = I('post.username');
     if (checkEmail($username) == 'true') {
         $info = M("user")->field("id,nickname")->where("email = '" . $username . "'  AND pwd = '" . md5($pwd) . "'")->find();
     } else {
         $info = M("user")->field("id,nickname")->where("name = '" . $username . "'  AND pwd = '" . md5($pwd) . "'")->find();
     }
     if (empty($info)) {
         echo json_encode(array("error" => "您输入的用户名/邮箱/密码无效。"));
         exit;
     } else {
         $userid = $info['id'];
     }
     $nickname = $info['nickname'];
     $tip = "登录成功!";
     if ($is_bind == 1) {
         //若是绑定
         $openid = getSessionCookie("openid");
         if ($openid) {
             $field = getSessionCookie("field");
             $userinfo = M("user")->field('id,name')->where("" . $field . "= '" . $openid . "'")->find();
             if (!$userinfo) {
                 //没有的话绑定账号,送积分和发广告,有绑定的话直接登录
                 // 绑定账号
                 M('user')->where("id = " . $userid . "")->save(array($field => $openid));
                 emptySessionCookie('type');
                 emptySessionCookie('openid');
             }
         }
     }
     setSessionCookie("userid", $userid);
     setSessionCookie("username", getNickname($username, $nickname));
     echo json_encode(array("username" => $username, "userid" => $userid, "avatar" => getUserAvatar($userid), "tip" => $tip, "error" => ""));
 }
Example #4
0
/* ___ _     _           _ 
  / __\ |__ (_)_ __ ___ (_)
 / /  | '_ \| | '_ ` _ \| |
/ /___| | | | | | | | | | |
\____/|_| |_|_|_| |_| |_|_|
Course Scheduling System
CS499 Fall 2013

Team 3
James Parkes, Jarrod Parkes, 
Suzanna Vellacott-Ford, Richard Burks
*/
// include general functions
include "functions.php";
// get the session ID
$sessionID = getSessionCookie();
// connect to database
mysql_connect("localhost", "root", "thebigredmachine") or die(mysql_error());
mysql_select_db("chimi") or die(mysql_error());
// fetch rooms, periods, courses, and instructors from database
$room_result = mysql_query("SELECT roomNo, buildingID FROM Room WHERE sessionID='" . $sessionID . "' ORDER BY roomNo");
$rooms = mysql_fetch_all($room_result);
$period_result = mysql_query("SELECT startTime, endTime FROM Period WHERE sessionID='" . $sessionID . "'");
$periods = mysql_fetch_all($period_result);
$course_result = mysql_query("SELECT courseID, courseNo, creditHours, courseName FROM Course WHERE sessionID='" . $sessionID . "' ORDER BY courseID");
$courses = mysql_fetch_all($course_result);
$instructor_result = mysql_query("SELECT instructorID, firstName, lastName FROM Instructor WHERE sessionID='" . $sessionID . "' ORDER BY lastName");
$instructors = mysql_fetch_all($instructor_result);
// the number of days
$num_of_days = 5;
// calculate the number of slots per room