- 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]"
- }