- require_once DISCUZ_ROOT.'./config.inc.php';
- require_once DISCUZ_ROOT.'./include/db_mysql.class.php';
- require_once DISCUZ_ROOT.'./uc_client/lib/db.class.php';
- $GLOBALS['db'] = new dbstuff;
- $GLOBALS['db']->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
- $GLOBALS['tablepre'] = $tablepre;
- 修改爲
- $GLOBALS['db'] = new ucclient_db;
- $GLOBALS['db']->connect(UC_DBHOST, UC_DBUSER, UC_DBPW, UC_DBNAME, UC_DBCONNECT, true, UC_DBCHARSET);
- $GLOBALS['tablepre'] = UC_DBTABLEPRE;//關鍵
- class UcService{
- public function __construct(){
- include_once(WBLOG_ROOT_PATH . 'W3note/Conf/config_ucenter.php');
- include_once(WBLOG_ROOT_PATH . 'uc_client/client.php');
- }
- /**
- * 會員註冊
- */
- public function register($username, $password, $email){
- $uid = uc_user_register($username, $password, $email);//UCenter的註冊驗證函數
- if($uid <= 0) {
- if($uid == -1) {
- return '用戶名不合法';
- } elseif($uid == -2) {
- return '包含不允許註冊的詞語';
- } elseif($uid == -3) {
- return '用戶名已經存在';
- } elseif($uid == -4) {
- return 'Email 格式有誤';
- } elseif($uid == -5) {
- return 'Email 不允許註冊';
- } elseif($uid == -6) {
- return '該 Email 已經被註冊';
- } else {
- return '未定義';
- }
- } else {
- return intval($uid);//返回一個非負數
- }
- }
- }
- /*
- 用戶名:$username,
- 密碼:$password,
- 郵箱:$email
- */
- public function addmember(){
- if($this->isPost()){
- $username = $_POST['username'];
- $email = $_POST['email'];
- $password = trim($_POST['password']);
- import("@.ORG.UcService");//導入UcService.class.php類
- $ucService = new UcService;//實例化UcService類
- $uid = $ucService->register($username, $password, $email);//註冊到UCenter
- if($uid){//如果上面註冊成功將返回一個int類型的數字
- $M = D('Member');
- if ($vo = $M->create()) {
- if ($M->add()) {
- $this->success('註冊成功!');
- } else {
- $this->error('註冊失敗!');
- }
- } else {
- $this->error();
- }
- }else{
- exit($uid);
- }
- }else{
- $this->error('非法數據!');
- }
- }
- public function uc_login($username, $password){
- list($uid, $username, $password, $email) = uc_user_login($username, $password);
- if($uid > 0) {
- return array(
- 'uid' => $uid,
- 'username' => $username,
- 'password' => $password,
- 'email' => $email
- );
- } elseif($uid == -1) {
- return '用戶不存在,或者被刪除';
- } elseif($uid == -2) {
- return '密碼錯誤';
- } elseif($uid == -3) {
- return '安全提問錯誤';
- } else {
- return '未定義';
- }
- }
- public function uc_synlogin($uid){
- return uc_user_synlogin($uid);
- }
- public function checkLogin() {
- if(!$_POST['username']) $this->error('帳號錯誤!');
- if(!$_POST['password']) $this->error('密碼錯誤!');
- if(empty($_POST['verify'])) $this->error('驗證碼必須!');
- import("@.ORG.UcService");//導入UcService.class.php類
- $ucService = new UcService;
- $uidarray = $ucService->uc_login($_POST['username'], $_POST['password']);
- //dump($uidarray);
- $loginurl=$ucService->uc_synlogin($uidarray);
- echo $loginurl;//輸出同步登錄代碼,否則無法同步登錄
- if(!is_string($uidarray)){
- //生成認證條件
- $map = array();
- // 支持使用綁定帳號登錄
- $map['username'] = $_POST['username'];
- $map["status"] = array('gt',0);
- if($_SESSION['verify'] != md5($_POST['verify'])) {
- $this->error('驗證碼錯誤!');
- }
- $memberinfo=$this->Member->where($map)->find();
- if(false === $memberinfo) {
- $this->error('帳號不存在或已禁用!');
- }elseif($memberinfo['status']==0){
- $this->error('帳號已禁用!');
- }else {
- $password = pwdHash($_POST['password']);
- if($memberinfo['password'] != $password) {
- $this->error('密碼錯誤!');
- }
- session(C('USER_AUTH_KEY'), $memberinfo['id']);
- session('email', $memberinfo['email'] );
- session('loginUserName', $memberinfo['loginUserName']);
- session('lastLoginTime', $memberinfo['lastLoginTime']);
- session('loginnum', $memberinfo['loginnum']);
- session('lastloginip', $memberinfo['lastloginip']);
- //保存登錄信息(相當於更新信息)
- $data = array();
- $data['id'] = $memberinfo['id'];
- $data['lastlogintime'] = time();
- $data['loginnum'] = array('exp','loginnum+1');
- $data['lastloginip'] = get_client_ip();
- //$data['verify'] = $authInfo['verify'];
- $this->Member->save($data);
- $this->success('登錄成功!',U('Member/index'));
- }
- }
- }
- array(4) {
- ["uid"] => string(1) "1"
- ["username"] => string(5) "qqabc"
- ["password"] => string(6) "123456"
- ["email"] => string(9) "[email protected]"
- }