PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/changleqi/core/shop/controller/ctl.passport.php

http://phpfor.googlecode.com/
PHP | 778 lines | 670 code | 65 blank | 43 comment | 111 complexity | 0b006c854144fcfa340ea33fa1fece32 MD5 | raw file
  1. <?php
  2. /**
  3. * ctl_passport
  4. *
  5. * @uses shopPage
  6. * @package
  7. * @version $Id: ctl.passport.php 2035 2008-04-28 14:06:13Z alex $
  8. * @copyright 2003-2007 ShopEx
  9. * @author Wanglei <flaboy@zovatech.com>
  10. * @license Commercial
  11. */
  12. class ctl_passport extends shopPage{
  13. var $noCache = true;
  14. function ctl_passport(&$system){
  15. parent::shopPage($system);
  16. $this->header .= "<meta name=\"robots\" content=\"noindex,noarchive,nofollow\" />\n";
  17. $this->pagedata['redirectInfo'] = '';
  18. if(isset($_POST['form'])){
  19. $form = get_magic_quotes_gpc()?stripcslashes($_POST['form']):$_POST['form'];
  20. $this->pagedata['redirectInfo'].='<input type="hidden" name="form" value="'.htmlspecialchars($form).'" />';
  21. }if(isset($_REQUEST['url'])){
  22. $this->pagedata['redirectInfo'].='<input type="hidden" name="url" value="'.htmlspecialchars($_REQUEST['url']).'" />';
  23. }
  24. if(constant('DEBUG_JS')){
  25. $script_dir='script_src';
  26. }else{
  27. $script_dir='script';
  28. }
  29. $this->pagedata['scriptplus']='<script type="text/javascript" src="statics/'.$script_dir.'/formplus.js"></script>';
  30. }
  31. function verifyCode($type=''){
  32. $oVerifyCode = &$this->system->loadModel('utility/verifyCode');
  33. $oVerifyCode->type = $type;
  34. $oVerifyCode->Output(60,16,true);
  35. }
  36. function namecheck(){
  37. $member=&$this->system->loadModel('member/account');
  38. $name = trim($_POST['name']);
  39. if($member->check_uname($name,$message)){
  40. echo '<span class="fontcolorGreen">&nbsp;'.__('????').'</span>';
  41. }else{
  42. echo '<span class="fontcolorRed">&nbsp;'.$message.'</span>';
  43. }
  44. }
  45. function showValideCode($tp=''){
  46. switch ($tp){
  47. case "login":
  48. if($this->system->getConf('site.login_valide')){
  49. $this->pagedata['valideCode'] = true;
  50. }
  51. break;
  52. case "signup":
  53. if($this->system->getConf('site.register_valide')){
  54. $this->pagedata['valideCode'] = true;
  55. }
  56. break;
  57. }
  58. }
  59. function other_login(){
  60. $this->output();
  61. }
  62. function other_login_verify(){
  63. $sign = $_GET['sign'];
  64. unset($_GET['passport-other_login_verify_html']);
  65. unset($_GET['passport-1-other_login_verify_html']);
  66. unset($_GET['sign']);
  67. $make_sign = $this->get_ce_sign($_GET,$this->system->getConf('certificate.token'));
  68. if($make_sign!=$sign){
  69. echo "sign is error";
  70. exit;
  71. }
  72. $account = $this->system->loadModel('member/account');
  73. $result_m = $account->createotherlogin($_GET);
  74. if($result_m['redirect_url']){
  75. echo "<script>window.location=decodeURIComponent('".$result_m['redirect_url']."');</script>";
  76. exit;
  77. }else{
  78. echo "<script>(location.hash)?window.location=decodeURIComponent(location.hash).substr(1):location.reload();</script>";
  79. }
  80. }
  81. function get_ce_sign($params,$token){
  82. $arg="";
  83. ksort($params);
  84. reset($params);
  85. while (list ($key, $val) = each ($params)) {
  86. $arg.=$key."=".urlencode($val)."&";
  87. }
  88. $sign = md5(substr($arg,0,count($arg)-2).$token);//????????
  89. return $sign;
  90. }
  91. function index($url){
  92. $this->pagedata['_MAIN_'] = 'passport/login.html';
  93. return $this->login($url);
  94. if(count($_POST['form'])>0 && !$this->member && !$this->system->getConf('security.guest.enabled',false)){
  95. $this->pagedata['mustMember'] = true;
  96. }
  97. $this->showValideCode();
  98. switch($url){
  99. case 'checkout':
  100. $options['url'] = $this->system->mkUrl("cart","checkout");
  101. break;
  102. }
  103. $this->pagedata['options'] = $options;
  104. $this->output();
  105. }
  106. function login($url,$error_msg=''){
  107. $this->system->toUcApp('login');
  108. //$error_msg = urldecode( $error_msg );
  109. $passport = $this->system->loadModel('member/passport');
  110. if ($obj=$passport->function_judge('ServerClient')){
  111. $type = $obj->ServerClient('login');
  112. }
  113. $this->showValideCode('login');
  114. switch($url){
  115. case 'checkout':
  116. $options['url'] = $this->system->mkUrl("cart","checkout");
  117. break;
  118. }
  119. $this->pagedata['LogInvalideCode'] = $this->pagedata['valideCode'];
  120. $this->title = __('????');
  121. $this->pagedata['ref_url'] = str_replace(array('_',',','~'),array('+','/','='),base64_decode($url));
  122. $baseurl='http://'.$_SERVER['HTTP_HOST'].substr(PHP_SELF, 0, strrpos(PHP_SELF, '/') + 1);
  123. if(!strpos($baseurl.'?member',$_SERVER['HTTP_REFERER'])&&$url==""){
  124. $this->pagedata['ref_url'] = $_SERVER['HTTP_REFERER'];
  125. }
  126. if(($_SERVER['HTTP_REFERER']==$this->system->mkUrl("passport","login")&&$error_msg=="")||$_SERVER['HTTP_REFERER']==$this->system->mkUrl("passport","sendPSW")||$_SERVER['HTTP_REFERER'] ==$this->system->mkUrl("passport","signup")||$_SERVER['HTTP_REFERER']==""){
  127. $this->pagedata['ref_url'] = $this->system->mkUrl('member');
  128. }
  129. if($error_msg!=''){
  130. $this->pagedata['err_msg'] =str_replace(array('_',',','~'),array('+','/','='),base64_decode($error_msg));
  131. }
  132. $this->pagedata['options'] = $options;
  133. $this->pagedata['forward'] = $_REQUEST['forward'];
  134. $this->pagedata['loginName'] = $_COOKIE['loginName'];
  135. $appmgr = $this->system->loadModel('system/appmgr');
  136. if($appmgr->openid_loglist()){
  137. $this->pagedata['openid_open'] = true;
  138. }
  139. if($_GET['mini_passport']){
  140. $this->pagedata['mini']=1;
  141. $this->__tmpl = 'passport/index/login.html';
  142. $login_plugin = $appmgr->getloginplug();
  143. foreach($login_plugin as $key =>$value){
  144. $object = $appmgr->instance_loginplug($value);
  145. if(method_exists($object,'getMiniHtml')){
  146. $this->pagedata['mini_login_content'][] = $object->getMiniHtml();
  147. }
  148. }
  149. }else{
  150. $login_plugin = $appmgr->getloginplug();
  151. foreach($login_plugin as $key =>$value){
  152. $object = $appmgr->instance_loginplug($value);
  153. if(method_exists($object,'getHtml')){
  154. $this->pagedata['login_content'][] = $object->getHtml();
  155. }
  156. }
  157. }
  158. $this->output();
  159. }
  160. function signup($url,$forward=''){
  161. $this->system->toUcApp('register');
  162. $passport = &$this->system->loadModel('member/passport');
  163. if ($obj=$passport->function_judge('ServerClient')){
  164. $type = $obj->ServerClient('signup');
  165. }
  166. $this->showValideCode('signup');
  167. switch($url){
  168. case 'checkout':
  169. $options['url'] = $this->system->mkUrl("cart","checkout");
  170. break;
  171. }
  172. $this->title = __('????');
  173. $this->pagedata['options'] = $options;
  174. $this->pagedata['forward'] = $_REQUEST['forward'];
  175. $this->pagedata['SignUpvalideCode'] = $this->pagedata['valideCode'];
  176. if($_GET['mini_passport']){
  177. $this->__tmpl = 'passport/index/signup_fast.html';
  178. $appmgr = $this->system->loadModel('system/appmgr');
  179. $login_plugin = $appmgr->getloginplug();
  180. foreach($login_plugin as $key =>$value){
  181. $object = $appmgr->instance_loginplug($value);
  182. if(method_exists($object,'getRegistHtml')){
  183. $this->pagedata['regist_content'][] = $object->getRegistHtml();
  184. }
  185. }
  186. }
  187. $this->output();
  188. }
  189. function lost($url){
  190. $this->showValideCode();
  191. switch($url){
  192. case 'checkout':
  193. $options['url'] = $this->system->mkUrl("cart","checkout");
  194. break;
  195. }
  196. $this->pagedata['options'] = $options;
  197. $this->output();
  198. }
  199. function splash($status, $url, $msg, $links='', $wait=1, $json=false){
  200. if($json){
  201. echo json_encode(array('status'=>$status, 'url'=>$url, 'msg'=>$msg));
  202. exit();
  203. }else{
  204. parent::splash($status, $url, $msg, $links, $wait);
  205. }
  206. }
  207. function testApp(){
  208. echo $this->system->getConf('coupon.code.count_len');exit;
  209. $pObj = &$this->system->loadModel('member/passport');
  210. if ($obj = $pObj->function_judge('userLoginToApp')){
  211. $loginfo = $obj->userLoginToApp(70,'testname','889900','sdfsd@dd.com');
  212. //error_log()
  213. //echo $loginfo;exit;
  214. }
  215. }
  216. function create(){
  217. $account = &$this->system->loadModel('member/account');
  218. $passport=&$this->system->loadModel('member/passport');
  219. if ($obj=$passport->function_judge('getPlugCookie')){
  220. if ($ck=$obj->getPlugCookie()){
  221. $common = 1;
  222. if ($_REQUEST['plugUrl']){
  223. $common=0;
  224. }
  225. }else{
  226. $common = 1;
  227. }
  228. }else{
  229. $common = 1;
  230. }
  231. if ($common){
  232. if($this->system->getConf('site.register_valide')){
  233. if($_COOKIE["S_RANDOM_CODE"]!=md5($_POST['signupverifycode'])){
  234. $this->splash('failed','back',__('?????????????'),'','',$_POST['from_minipassport']);
  235. }
  236. }
  237. $passwdLen=strlen($_POST['passwd']);
  238. if($_POST['license']!='agree'){
  239. $this->splash('failed','back',__('???????????'),'','',$_POST['from_minipassport']);
  240. }elseif(!preg_match('/\S+@\S+/',$_POST['email'])){
  241. $this->splash('failed','back',__('???????'),'','',$_POST['from_minipassport']);
  242. }elseif($passwdLen<4){
  243. $this->splash('failed','back',__('????????4'),'','',$_POST['from_minipassport']);
  244. }elseif($passwdLen>20){
  245. $this->splash('failed','back',__('????????20'),'','',$_POST['from_minipassport']);
  246. }
  247. if($sCheck = $account->checkMember($_POST)){
  248. // if($sCheck == 1)
  249. $sError = __('????????');
  250. // else
  251. // $sError = __('?Email????');
  252. $this->splash('failed','back',$sError,'','',$_POST['from_minipassport']);
  253. exit;
  254. }else{
  255. $o_passwd= $_POST['passwd'];
  256. $o_email= $_POST['email'];
  257. $pObj = &$this->system->loadModel('member/passport');
  258. if ($obj = $pObj->function_judge('checkuserregister')){
  259. $sRes = $obj->checkuserregister($_POST['uname'],$_POST['passwd'],$_POST['email'],$uid,$message);
  260. if ($sRes){
  261. if (!empty($message)){
  262. $this->splash('failed','back',$message,'','',$_POST['from_minipassport']);
  263. exit;
  264. }else{
  265. if($_REQUEST['forward']) $url = $_REQUEST['forward'].DEFAULT_INDEX;
  266. else $url = $this->system->request['base_url'].DEFAULT_INDEX;
  267. if ($info = $account->createUserFromPluin($_POST,$message,$uid)){
  268. // BEGIN ???? by yangbing 2010-8-17 19:47
  269. if($_COOKIE['CLQ_R_ID']){
  270. $inviter_mid = intval($_COOKIE['CLQ_R_ID']);
  271. $rid = $this->db->selectrow('SELECT member_id FROM sdb_members where member_id='.$inviter_mid);
  272. if($rid){
  273. $data['inviter_mid'] = $inviter_mid;
  274. }
  275. }
  276. // END
  277. $this->system->setCookie('MEMBER',$info['secstr'],null);
  278. $this->system->setCookie('UNAME',$info['uname'],null);
  279. $this->system->setCookie('MLV',$info['member_lv_id'],null);
  280. $GLOBALS['runtime']['member_lv'] = $info['member_lv_id'];
  281. $this->system->setCookie('CUR',$info['cur'],null);
  282. $this->system->setCookie('LANG',$info['lang'],null);
  283. //$oPassport = $this->system->loadModel('member/passport');
  284. $login_info = $info;
  285. //userLoginToApp($uid,$uname,$password,$email){
  286. $info['member_id']=$info['foreign_id']?$info['foreign_id']:$info['member_id'];
  287. $loginfo = $obj->userLoginToApp($uid,$_POST['uname'],$_POST['passwd'],$_POST['email']); // ???????? by yangbing 2010-8-17 9:15
  288. $this->header .= $loginfo;
  289. $oCart = &$this->system->loadModel('trading/cart');
  290. $oCart->memberLogin = false;
  291. $cartCookie = $oCart->getCart();
  292. $oCart->checkMember($login_info);
  293. $oCart->memberLogin = true;
  294. $oCart->save('all', $cartCookie);
  295. $this->system->setcookie($oCart->cookiesName,'');
  296. if ($_POST['regType']=='buy'){
  297. $mem_obj_m = $this->system->loadModel('member/member');
  298. $tmp_mem = $mem_obj_m->getMemIdByName($_POST['uname']);
  299. $info['member_id']= $tmp_mem[0]['member_id'];
  300. if($_POST['isfastbuy'])$redi_url = $this->system->mkUrl('cart','checkout',array(1));
  301. else $redi_url = $this->system->mkUrl('cart','checkout');
  302. $this->splash('success',$redi_url,__('??????????'),'',1,$_POST['from_minipassport']);
  303. }
  304. }
  305. else
  306. $this->splash('failed','back',$message,'','',$_POST['from_minipassport']);
  307. }
  308. }
  309. }else{
  310. if($_REQUEST['forward']) $url = $_REQUEST['forward'].DEFAULT_INDEX;
  311. else $url = $this->system->request['base_url'].DEFAULT_INDEX;
  312. if($info = $account->create($_POST,$message)){
  313. // BEGIN ???? by yangbing 2010-8-17 19:47
  314. if($_COOKIE['CLQ_R_ID']){
  315. $inviter_mid = intval($_COOKIE['CLQ_R_ID']);
  316. $rid = $this->db->selectrow('SELECT member_id FROM sdb_members where member_id='.$inviter_mid);
  317. if($rid){
  318. $data['inviter_mid'] = $inviter_mid;
  319. }
  320. }
  321. // END
  322. $this->system->setCookie('MEMBER',$info['secstr'],null);
  323. $this->system->setCookie('UNAME',$info['uname'],null);
  324. $this->system->setCookie('MLV',$info['member_lv_id'],null);
  325. $GLOBALS['runtime']['member_lv'] = $info['member_lv_id'];
  326. $this->system->setCookie('CUR',$info['cur'],null);
  327. $this->system->setCookie('LANG',$info['lang'],null);
  328. $oCart = &$this->system->loadModel('trading/cart');
  329. $cartCookie = $oCart->getCart();
  330. $oCart->checkMember($info);
  331. $oCart->memberLogin = true;
  332. $oCart->save('all', $cartCookie);
  333. $this->system->setcookie($oCart->cookiesName,'');
  334. if($_POST['regType'] == 'buy'){
  335. $this->system->setcookie($oCart->cookiesName,'');
  336. if($_POST['isfastbuy'])$redi_url = $this->system->mkUrl('cart','checkout',array(1));
  337. else $redi_url = $this->system->mkUrl('cart','checkout');
  338. $this->splash('success',$redi_url,__('??????????'),'',1,$_POST['from_minipassport']);
  339. }
  340. else{
  341. $oPassport = &$this->system->loadModel('member/passport');
  342. if ($opbj = $oPassport->function_judge('setPlugCookie'))
  343. $opbj->setPlugCookie(0);
  344. if ($_REQUEST['forward']){
  345. $registinfo = $oPassport->regist($info['member_id'],$url);
  346. $this->nowredirect('plugin_passport', $registinfo,'',$_POST['from_minipassport']);
  347. }else{
  348. if ($_POST['forward']){
  349. $url='';
  350. }
  351. $registinfo = $oPassport->regist($info['member_id'],$url);
  352. //$this->nowredirect('plugin_passport', $registinfo,'',$_POST['from_minipassport']);
  353. }
  354. }
  355. }else{
  356. $this->splash('failed','back',$message,'','',$_POST['from_minipassport']);
  357. }
  358. }
  359. }
  360. }else{
  361. if ($obj=$passport->function_judge('setPlugCookie'))
  362. $obj->setPlugCookie(0);
  363. if($_POST['from_minipassport']){
  364. echo 'success';
  365. exit;
  366. }
  367. }
  368. $oMem = &$this->system->loadModel('member/member');
  369. $mematt = &$this->system->loadModel('member/memberattr');
  370. //???????
  371. $filter['attr_show'] = 'true';
  372. $tmpdate =$mematt->getList('*',$filter,0,-1,array('attr_order','asc'));
  373. for($i=0;$i<count($tmpdate);$i++){
  374. if($tmpdate[$i]['attr_type'] == 'select'||$tmpdate[$i]['attr_type'] == 'checkbox'){
  375. $tmpdate[$i]['attr_option'] = unserialize($tmpdate[$i]['attr_option']);
  376. }
  377. }
  378. if($_POST['from_minipassport']){
  379. echo 'success';
  380. }else{
  381. $this->pagedata['passwd'] = $o_passwd;
  382. $this->pagedata['email'] = $o_email;
  383. $this->pagedata['tree'] = $tmpdate;
  384. $this->pagedata['plugUrl'] = $_REQUEST['plugUrl']?$_REQUEST['plugUrl']:$_COOKIE['plugUrl'];
  385. $this->output();
  386. }
  387. }
  388. function recover(){
  389. $member=&$this->system->loadModel('member/member');
  390. $this->pagedata['data']=$member->getMemberByUser($_POST['login']);
  391. if(empty($this->pagedata['data']['member_id'])){
  392. $this->splash('failed','back',__('???????'));
  393. }
  394. if($this->pagedata['data']['disabled'] == "true"){
  395. $this->splash('failed','back',__('???????????'));
  396. }
  397. $this->output();
  398. }
  399. function sendPSW(){
  400. $this->begin($this->system->mkUrl('passport','lost'));
  401. $member=&$this->system->loadModel('member/member');
  402. $data=$member->getMemberByUser($_POST['uname']);
  403. if(($data['pw_answer']!=$_POST['pw_answer']) || ($data['email']!=$_POST['email'])){
  404. $this->end(false,__('??????????????????'),$this->system->mkUrl('passport','lost'));
  405. }
  406. if( $data['member_id'] < 1 ){
  407. $this->end(false,__('??????'),$this->system->mkUrl('passport','lost'));
  408. }
  409. $messenger = &$this->system->loadModel('system/messenger');echo microtime()."<br/>";
  410. $passwd = substr(md5(print_r(microtime(),true)),0,6);
  411. $pObj=$this->system->loadModel('member/passport');
  412. if ($obj=$pObj->function_judge('edituser')){
  413. $res = $obj->edituser($data['uname'],'',$passwd,$data['email'], '1');
  414. if ($res>0){
  415. $member->update(array('password'=>md5($passwd)),array('member_id'=>intval($data['member_id'])));
  416. }
  417. else{
  418. trigger_error('?????????????', E_USER_ERROR);
  419. return false;
  420. }
  421. }else{
  422. $member->update(array('password'=>md5($passwd)),array('member_id'=>intval($data['member_id'])));
  423. }
  424. $data['passwd'] = $passwd;
  425. $memberObj = &$this->system->loadModel('member/account');
  426. $memberObj->fireEvent('lostPw',$data,$data['member_id']);
  427. $this->end(true,__('??????'),$this->system->mkUrl('passport','index'));
  428. }
  429. /*???????????*/
  430. function error(){
  431. $url = $this->system->request['url_prefix'];
  432. $this->pagedata['nexturl'] = $url;
  433. $this->header.="\n<meta http-equiv=\"refresh\" content=\"3; url={$url}\">\n";
  434. $this->output();
  435. }
  436. //??
  437. function logout(){
  438. $this->system->toUcApp('logout');
  439. $passport = &$this->system->loadModel('member/passport');
  440. if ($obj=$passport->function_judge('ServerClient')){
  441. $obj->ServerClient('logout');
  442. }
  443. $this->_verifyMember(false);
  444. $this->system->setCookie('MEMBER', '', time()-1000);
  445. $this->system->setCookie('MLV', '', time()-1000);
  446. $GLOBALS['runtime']['member_lv'] = -1;
  447. $this->system->setCookie('CART', '', time()-1000);
  448. $this->system->setCookie('CART_COUNT', '', time()-1000);
  449. $this->system->setCookie('UNAME', '', time()-1000);
  450. if($_COOKIE['LOGIN_TYPE']){
  451. $appmgr = $this->system->loadModel("system/appmgr");
  452. $app_model = $appmgr->load("openid_".$_COOKIE['LOGIN_TYPE']);
  453. if(method_exists($app_model,'openid_logout')){
  454. $app_model->openid_logout($user);
  455. }
  456. $this->system->setCookie('LOGIN_TYPE', '', time()-1000);
  457. }
  458. if($_REQUEST['forward']) $url = $_REQUEST['forward'].DEFAULT_INDEX;
  459. else $url = $this->system->request['base_url'].DEFAULT_INDEX;
  460. if ($_REQUEST['forward']) $url='';
  461. $oPassport = &$this->system->loadModel('member/passport');
  462. $logoutinfo = $oPassport->logout($this->member['member_id'],$url);
  463. if ($logoutinfo){
  464. $this->header.=$logoutinfo;
  465. $this->splash('success',$this->system->base_url().DEFAULT_INDEX,__('????????????'));
  466. }else{
  467. $baseurl='http://'.$_SERVER['HTTP_HOST'].substr(PHP_SELF, 0, strrpos(PHP_SELF, '/') + 1);
  468. $this->system->location($this->system->base_url());
  469. }
  470. }
  471. function nowredirect($status='success',$url,$msg="",$json=false){
  472. if($status!='failed'){
  473. if($json){
  474. echo json_encode(array('status'=>$status, 'url'=>$url));
  475. }else{
  476. header('Location: '.$url);
  477. }
  478. }else{
  479. if($json){
  480. echo json_encode(array('status'=>'failed', 'msg'=>$msg));
  481. exit;
  482. }else{
  483. $url = $this->system->mkUrl('passport','login',array($url,base64_encode(str_replace(array('+','/','='),array('_',',','~'),$msg))));
  484. header('Location: '.$url);
  485. exit;
  486. }
  487. }
  488. }
  489. function verify($passport='local'){
  490. if($passport!='local'){
  491. $appmgr = $this->system->loadModel('system/appmgr');
  492. $pass = $appmgr ->getlgplugbyname($passport);
  493. if($pass){
  494. $p_object = $appmgr->instance_loginplug($pass);
  495. if(method_exists($p_object,'callback')){
  496. $p_object->callback();
  497. }else{
  498. echo '????????????';
  499. exit;
  500. }
  501. }
  502. }
  503. if($this->system->getConf('site.login_valide')&&$passport=='local'){
  504. if($_COOKIE["L_RANDOM_CODE"]!=md5($_POST['loginverifycode'])){
  505. $this->nowredirect('failed',base64_encode(str_replace(array('+','/','='),array('_',',','~'),$_POST['ref_url'])),__('?????????????'),$_POST['from_minipassport']);
  506. }
  507. }
  508. $memberObj = &$this->system->loadModel('member/account');
  509. $this->system->setCookie('loginName',$_POST['login']);
  510. $pObj=&$this->system->loadModel('member/passport');
  511. if ($obj=$pObj->function_judge('check_login')){
  512. $uinfo = $obj->check_login($_POST['login'],$_POST['passwd'],2);
  513. if($uinfo[0]>0){
  514. return $this->_checkusername($uinfo[1],$uinfo[2],$_POST['forward'],$uinfo[0],$uinfo[3]);
  515. }elseif($uinfo[0] == '-1'){
  516. $msg = '?????';
  517. }elseif($uinfo[0] == '-2'){
  518. $msg = '??????????????';
  519. }elseif($uinfo[0] == '-3'){
  520. $msg = '??????';
  521. }
  522. $this->nowredirect('failed',base64_encode(str_replace(array('+','/','='),array('_',',','~'),$_POST['ref_url'])),__($msg));
  523. exit();
  524. /*
  525. var_dump($uinfo);exit;
  526. if ((is_array($uinfo)&&intval($uinfo[0])>0)||$info = $memberObj->verifyLogin($_POST['login'],$_POST['passwd'],$message)){
  527. return $this->_checkusername($_POST['login'],$_POST['passwd'],$_POST['forward'],$uinfo[0],$uinfo[3]);
  528. }else{
  529. $this->nowredirect('failed',base64_encode(str_replace(array('+','/','='),array('_',',','~'),$_POST['ref_url'])),__('??????????????'),$_POST['from_minipassport']);
  530. }
  531. */
  532. }
  533. $this->title = '';
  534. if($info = $memberObj->verifyLogin($_POST['login'],$_POST['passwd'],$message)){
  535. if(isset($_REQUEST['forward']) && $_REQUEST['forward']){
  536. $url = $_REQUEST['forward'].DEFAULT_INDEX;
  537. }elseif(isset($_POST['ref_url']) && $_POST['ref_url']){
  538. $url = $_POST['ref_url'];
  539. }else{
  540. $url = $this->system->base_url();
  541. }
  542. $cart_count = unserialize($info['addon']);
  543. $cart_count = count(explode(',',$cart_count['cart']));
  544. $this->system->setCookie('MEMBER',$info['secstr'],null);
  545. $this->system->setCookie('UNAME',$info['uname'],null);
  546. $this->system->setCookie('MLV',$info['member_lv_id'],null);
  547. $GLOBALS['runtime']['member_lv'] = $info['member_lv_id'];
  548. $this->system->setCookie('CUR',$info['cur'],null);
  549. $this->system->setCookie('LANG',$info['lang'],null);
  550. $this->system->setCookie('CART_COUNT',$cart_count,null);
  551. // ?????
  552. $oCart = &$this->system->loadModel('trading/cart');
  553. $cartCookie = $oCart->getCart();
  554. $oPassport = &$this->system->loadModel('member/passport');
  555. if($_COOKIE['CART_COUNT']){ //Cookie ?????
  556. //cookie????
  557. $oCart->checkMember($info);
  558. $cartDb = $oCart->getCart();
  559. if($cartDb){ //DB ?????
  560. if($this->system->mkUrl('cart','checkout')==$url){
  561. $url = $this->system->mkUrl('cart','index');
  562. }
  563. if($_POST['from_minipassport']){
  564. $aCart = $oCart->mergeCart($cartCookie, $cartDb);
  565. $oCart->save('all',$aCart);
  566. }
  567. $this->nowredirect('success',$this->system->mkUrl('cart','merge',array(1)).'?forward='.urlencode($url),'',$_POST['from_minipassport']);
  568. }else{
  569. $oCart->save('all', $cartCookie);
  570. $this->system->setcookie($oCart->cookiesName,'');
  571. if ($oPassport->forward){
  572. $loginfo = $oPassport->login($info['member_id'],$url);
  573. $this->nowredirect('plugin_passport', $loginfo,'',$_POST['from_minipassport']);
  574. //$this->header.=$loginfo;
  575. }else{
  576. // if ($_POST['forward']){
  577. $loginfo = $oPassport->login($info['member_id'],$url);
  578. $this->nowredirect('plugin_passport', $loginfo,'',$_POST['from_minipassport']);
  579. //$this->header.=$loginfo;
  580. // }
  581. }
  582. $this->nowredirect('success',$url,'',$_POST['from_minipassport']);
  583. }
  584. }else{
  585. $oCart->checkMember($info);
  586. $cartDb = $oCart->getCart();
  587. if ($oPassport->forward){
  588. $loginfo = $oPassport->login($info['member_id'],$url);
  589. $this->nowredirect('plugin_passport', $loginfo,'',$_POST['from_minipassport']);
  590. $this->header.=$loginfo;
  591. }else{
  592. $loginfo = $oPassport->login($info['member_id'],$url);
  593. $this->nowredirect('plugin_passport', $loginfo,'',$_POST['from_minipassport']);
  594. //$this->header.=$loginfo;
  595. }
  596. $this->nowredirect('success',$url,'',$_POST['from_minipassport']);
  597. }
  598. }else{
  599. $this->nowredirect('failed',base64_encode(str_replace(array('+','/','='),array('_',',','~'),$_POST['ref_url'])),__('??????????????'),$_POST['from_minipassport']);
  600. }
  601. }
  602. function ssoSignin()
  603. {
  604. $oPassport = &$this->system->loadModel('member/passport');
  605. return $oPassport->ssoSignin();
  606. }
  607. function _setLoginCookie($info)
  608. {
  609. if($info){
  610. $option = time()+60*60*24*30;//null;
  611. }else{
  612. $option = time() - 1000;
  613. }
  614. $this->system->setCookie('MEMBER',$info['secstr'],$option);
  615. $this->system->setCookie('UNAME',$info['uname'],$option);
  616. $this->system->setCookie('MLV',$info['member_lv_id'],$option);
  617. $GLOBALS['runtime']['member_lv'] = $info['member_lv_id'];
  618. $this->system->setCookie('CUR',$info['cur'],$option);
  619. $this->system->setCookie('LANG',$info['lang'],$option);
  620. return true;
  621. }
  622. function callback($type){
  623. $oPassport = &$this->system->loadModel('member/passport');
  624. $info = $oPassport->ssoSignin($type);
  625. $this->_succ = true;
  626. switch($_GET['action']){
  627. case 'login':
  628. if(!$info){
  629. header("location: ".$_GET['forward']);
  630. exit;
  631. }
  632. $this->_setLoginCookie($info);
  633. header("location: ".$_GET['forward']);
  634. exit;
  635. case 'logout':
  636. $this->_setLoginCookie($info);
  637. header("location: ".$_GET['forward']);
  638. exit;
  639. }
  640. }
  641. function getMsg(){
  642. return array(
  643. 'login'=>array('succ'=>__('????'),'fail'=>__('????')),
  644. 'logout'=>array('succ'=>__('????'),'fail'=>__('????'))
  645. );
  646. }
  647. function _checkusername($uname='',$passwd='',$forward='',$uid='',$email=''){
  648. $mem_info = $this->system->loadModel('member/member');
  649. $account = &$this->system->loadModel("member/account");
  650. $data=array(
  651. "uname"=>$uname,
  652. "passwd"=>$passwd,
  653. "email"=>$email
  654. );
  655. $oCart = &$this->system->loadModel('trading/cart');
  656. $cartCookie = $oCart->getCart();
  657. if($_REQUEST['forward']) $url = $_REQUEST['forward'].DEFAULT_INDEX;
  658. else $url = $this->system->request['base_url'].DEFAULT_INDEX;
  659. $row = $account->getMemberPluginUser($uname);
  660. if (!$row){
  661. $row = $account->createUserFromPluin($data,$message,$uid);
  662. }else{
  663. if ($row['foreign_id']<>$uid){
  664. $account->UpdateForeignId(array($row['member_id']=>$uid));
  665. }
  666. }
  667. $oMsg = $this->system->loadModel('resources/msgbox');
  668. $row['unreadmsg'] = $oMsg->getNewMessageNum($row['member_id']);
  669. $cart_count = unserialize($row['addon']);
  670. $cart_count = count(explode(',',$cart_count['cart']));
  671. $this->system->setCookie('CART_COUNT',$cart_count,null);
  672. $this->system->setCookie('MEMBER',$row['secstr'],null);
  673. $this->system->setCookie('UNAME',$row['uname'],null);
  674. $this->system->setCookie('MLV',$row['member_lv_id'],null);
  675. $GLOBALS['runtime']['member_lv'] = $row['member_lv_id'];
  676. $this->system->setCookie('CUR',$row['cur'],null);
  677. $this->system->setCookie('LANG',$row['lang'],null);
  678. $oPassport = &$this->system->loadModel('member/passport');
  679. $row['foreign_id']?$row['member_id'] = $row['foreign_id']:'';
  680. $loginfo = $oPassport->login($row['member_id'],$url);
  681. //error_log($row['member_id'].$loginfo,3,HOME_DIR.'/login.txt');
  682. $this->header.= $loginfo;
  683. $tmp_mem = $mem_info->getMemIdByName($uname);
  684. $row['member_id']= $tmp_mem[0]['member_id'];
  685. $oCart->checkMember($row);
  686. if($_POST['ref_url']) $url=$_POST['ref_url'];
  687. if ($_COOKIE['CART_COUNT']){
  688. $cartCookie = $oCart->getCart();
  689. if($_POST['from_minipassport']){
  690. $cartDb = $oCart->getCart();
  691. $oCart->memberLogin = false;
  692. $cartCookie = $oCart->getCart();
  693. $aCart = $oCart->mergeCart($cartCookie, $cartDb);
  694. $oCart->memberLogin = true;
  695. $oCart->save('all',$aCart);
  696. $this->system->setcookie($oCart->cookiesName,'');
  697. $oCart->setCartNum($aCart);
  698. }
  699. $this->nowredirect('success',$this->system->mkUrl('cart','merge',array(1)).'?forward='.urlencode($url),'',$_POST['from_minipassport']);
  700. //exit;
  701. }else{
  702. $oCart->save('all', $cartCookie);
  703. }
  704. $this->splash('success',$this->system->base_url().DEFAULT_INDEX,__('????????????'));
  705. if($_POST['from_minipassport']){
  706. return true;
  707. }else{
  708. $this->nowredirect('success',$url,'',$_POST['from_minipassport']);
  709. $this->_succ=true;
  710. }
  711. }
  712. }
  713. ?>