標籤:str min 儲存 ecc 更新 使用者名稱 通過 類比post track
discuz 本身提供UCENTER使用者中心能夠實現單點登入。
可是其它應用要單點登入到discuz還是存在若干問題:
須要2次啟用。可能造成server無響應,論壇顯示的最新注冊使用者無法同步更新,官網沒有提供其它語言的api
等
這裡提供了段代碼。在bbs根資料夾下儲存例如以下php代碼go.php
<?php/**
* zj53hao 20140418 外部程式單點登入到discuz(同步注冊和登入到discuz) http://blog.csdn.net/zj53hao */define(‘NOROBOT‘, FALSE);define(‘ADMINSCRIPT‘, basename(__FILE__));define(‘CURSCRIPT‘, ‘admin‘);define(‘HOOKTYPE‘, ‘hookscript‘);define(‘APPTYPEID‘, 0);//define(‘CURMODULE‘, $mod);require ‘./source/class/class_core.php‘;$discuz = C::app();$discuz->init();require libfile(‘function/member‘);require libfile(‘class/member‘);runhooks();$newusername = trim($_GET[‘newusername‘]);$newpassword = ‘www.xxxx.com‘;//trim($_GET[‘newpassword‘]);$newemail = isset($_GET[‘newemail‘])? strtolower(trim($_GET[‘newemail‘])):$newusername.‘@xxx.com‘;if(!$newusername || !$newemail) { showmessage(‘您眼下未登入xxx網,臨時以遊客身份僅僅讀訪問論壇‘);}// 下面幾句防止第3方偽造$time= (int)($_GET["time"]);$curdate= time();$seckey=$time.$newusername.‘www.xxx.com‘;$seckey= md5($seckey);if($curdate-$time>1200 || $seckey!=$_GET[‘code‘]){ showmessage(‘submit_invalid‘);} $_G[‘uid‘]=‘‘;$userid=C::t(‘common_member‘)->fetch_uid_by_username($newusername); $_SERVER[‘REQUEST_METHOD‘] = ‘POST‘;//注冊須要類比POST防止2次校正不通過 $_GET[‘formhash‘] = formhash();// 防止 2次校正不通過 $_G[‘group‘][‘seccode‘]=‘‘;// 防止 2次校正不通過 if(!$userid){// 沒有找到相應使用者則調用注冊 $_GET[‘regsubmit‘]=‘yes‘; $_GET[‘infloat‘]=‘yes‘; $_GET[‘lssubmit‘]=‘yes‘; $ctl_obj = new register_ctl(); $ctl_obj->setting = $_G[‘setting‘]; $ctl_obj->template = ‘member/register‘; $_GET[‘‘.$ctl_obj->setting[‘reginput‘][‘username‘]]=$newusername; $_GET[‘‘.$ctl_obj->setting[‘reginput‘][‘password‘]]= $newpassword; $_GET[‘‘.$ctl_obj->setting[‘reginput‘][‘password2‘]]= $newpassword; $_GET[‘‘.$ctl_obj->setting[‘reginput‘][‘email‘]] =$newemail; $ctl_obj->on_register();}//uc_user_synlogout();$_G[‘groupid‘] = $_G[‘member‘][‘groupid‘] = 7;$_G[‘uid‘] = $_G[‘member‘][‘uid‘] = 0;$_G[‘username‘] = $_G[‘member‘][‘username‘] = $_G[‘member‘][‘password‘] = ‘‘; // 登陸 $_GET[‘loginsubmit‘]=‘yes‘;$_GET[‘lssubmit‘]=‘‘;$_GET[‘username‘]=$newusername;$_GET[‘password‘]= $newpassword; $ctl_obj = new logging_ctl();$ctl_obj->setting = $_G[‘setting‘];$ctl_obj->template = ‘member/login‘;$ctl_obj->on_login();?
>
主要原理是其它WEB應用跳轉該URL並帶上username。和登入檢驗串。如
http://xxx。
com/bbs/go.php?newusername=yyyyy&time=1397870932&code=d525745a6c196cb44049c7624bd28ece
在論壇裡推斷使用者是否存在。
不存在則調用注冊模組。存在則登入新使用者,假設之前登入過別的使用者也會被切換該使用者。
當中 使用自己的防止第3方的惡意提交的代碼,並通過暫時開關去掉論壇本身的檢驗代碼。
$seckey=$time.$newusername.‘www.xxx.com‘;
主要用linux時間戳記和使用者名稱。加兩方協商好的一個秘鑰傳再md5加密。匹配後才算驗證通過。同樣的串僅僅能在1200秒內有效
眼下對discuzX3有效。其它版本號碼未測試。
discuz新的單點論壇(不依賴UCenter)