forked from faint32/benhu
/
user.php
4326 lines (3781 loc) · 155 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* ECSHOP 会员中心
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: user.php 17217 2011-01-19 06:29:08Z liubo $
*/
/**
*修改于8月20日
* 在用户中心欢迎页(当前php页面)($action == 'default'):处
* ----增加了vip_name,you_may_favorite ,visit_history,collection_goods,cart_goods
* ----注释了next_rank_name
* 在这个php页面的底部:
* ----增加了函数:insert_history_userCenter(取得用户浏览商品的记录)
* you_may_favorite(取得猜你喜欢的4件商品)
*
*/
/**
*修改于8月21日
* 在用户中心欢迎页 (当前php页面) ($action == 'comment_list'):处
* ----增加了vip_name等
* ----注释了next_rank_name
* 在这个php页面的底部:
* ----增加了一条分支:
* elseif ($action == 'you_may_love')
* 这条分支的作用是:处理猜你喜欢的ajax请求
*
*/
/**
*修改于8月22日
* 在用户中心欢迎页(当前php页面)
* ----增加了 'complain_list'页面,处理用户投诉
* ----增加了 'return_goods'页面,处理用户退换货
* ----增加了 'delete_complain',处理删除投诉的ajax请求
*在includes/lib_clips.php
* ----增加了get_complain_list
*/
/**
*修改于8月25日
* 在用户中心欢迎页(当前php页面)
* ----增加了一条分支:
* elseif ($action == 'cancle_back_order')
* 这条分支的作用是:取消退货申请ajax调用
* elseif ($action == 'sub_return_goods')
* 接受用户的退/换货申请
*/
//var_dump($_SERVER);exit;
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_order.php');
/* 载入语言文件 */
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
$user_id = $_SESSION['user_id'];
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
$smarty->assign('affiliate', $affiliate);
$smarty->assign('script_name', 'user');
$smarty->assign('categories', get_categories_tree_pro()); // 分类树
$back_act='';
// 不需要登录的操作或自己验证是否登录(如ajax处理)的act
$not_login_arr =
array('login','act_login','act_edit_phone_password','check_SMS_code','judge_usrNm','register','get_phone_password','get_email_password','act_register','act_edit_password','get_password','send_pwd_email','password', 'signin', 'add_tag', 'collect', 'return_to_cart', 'logout', 'email_list', 'validate_email', 'send_hash_mail', 'order_query', 'is_registered', 'check_email','clear_history','qpassword_name', 'get_passwd_question', 'check_answer', 'oath' , 'oath_login' , 'oath' , 'oath_login', 'other_login');
/* 显示页面的action列表 */
$ui_arr = array('security_settings','security_edit_psd','my_integral','comment_goods','my_rank','register','login', 'profile', 'order_list','check_SMS_code','get_phone_password','get_email_password', 'order_detail', 'address_list', 'collection_list',
'message_list','complain_list','return_goods', 'tag_list', 'get_password', 'reset_password', 'booking_list', 'add_booking', 'account_raply',
'account_deposit', 'account_log', 'account_detail', 'act_account', 'pay', 'default', 'bonus', 'group_buy', 'group_buy_detail', 'affiliate', 'comment_list', 'coupons', 'validate_email','track_packages', 'transform_points','qpassword_name', 'get_passwd_question', 'check_answer');
$smarty->assign('categories', get_categories_tree_pro()); // 分类树
user_infomation($smarty,$user_id); //chen-0917
/* 未登录处理 */
if (empty($_SESSION['user_id']))
{
if (!in_array($action, $not_login_arr))
{
if (in_array($action, $ui_arr))
{
/* 如果需要登录,并是显示页面的操作,记录当前操作,用于登录后跳转到相应操作
if ($action == 'login')
{
if (isset($_REQUEST['back_act']))
{
$back_act = trim($_REQUEST['back_act']);
}
}
else
{}*/
if (!empty($_SERVER['QUERY_STRING']))
{
$back_act = 'user.php?' . strip_tags($_SERVER['QUERY_STRING']);
}
$action = 'login';
}
else
{
//未登录提交数据。非正常途径提交数据!
die($_LANG['require_login']);
}
}
}
/* 如果是显示页面,对页面进行相应赋值 */
if (in_array($action, $ui_arr))
{
assign_template();
$position = assign_ur_here(0, $_LANG['user_center']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']);
$sql = "SELECT value FROM " . $ecs->table('shop_config') . " WHERE id = 419";
$row = $db->getRow($sql);
$car_off = $row['value'];
$smarty->assign('car_off', $car_off);
/* 是否显示积分兑换 */
if (!empty($_CFG['points_rule']) && unserialize($_CFG['points_rule']))
{
$smarty->assign('show_transform_points', 1);
}
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('data_dir', DATA_DIR); // 数据目录
$smarty->assign('action', $action);
$smarty->assign('lang', $_LANG);
}
//用户中心欢迎页 chen-0915
if ($action == 'default')
{
include_once(ROOT_PATH .'includes/lib_clips.php');
include_once(ROOT_PATH . 'includes/cls_orders.php');
$all_order_list = new order_list();
for($i=0; $i < $all_order_list->elem_count; $i++)
{
$record_count = $db->getOne("SELECT COUNT(*) FROM " .$ecs->table('order_info'). " WHERE user_id = '$user_id'".$all_order_list->where[$i]);
$all_order_list->orders[$i] = get_all_orders($user_id, 0, 0,$all_order_list->where[$i],$all_order_list->comment[$i], 1);
}
$smarty->assign("unpaid_orders", $all_order_list->orders[1]);$smarty->assign("unpaid_count", count($all_order_list->orders[1]));
$smarty->assign("unrecieved_orders", $all_order_list->orders[3]);$smarty->assign("unrecieved_count", count($all_order_list->orders[3]));
$smarty->assign("uncommented_orders", $all_order_list->orders[4]);$smarty->assign("uncommented_count", count($all_order_list->orders[4]));
if ($rank = get_rank_info())
{
$smarty->assign('rank_name', sprintf($_LANG['your_level'], $rank['rank_name']));
//$smarty->assign('vip_name', $rank['rank_name']);
/*if (!empty($rank['next_rank_name']))
{
$smarty->assign('next_rank_name', sprintf($_LANG['next_level'], $rank['next_rank'] ,$rank['next_rank_name']));
}*/
}
$sql = "select chat_validated,email,mobile_phone from ".$GLOBALS['ecs']->table('users')." where user_id = $user_id";
$info_validate = $GLOBALS['db']->getRow($sql);
$smarty->assign('info_validate',$info_validate);
$sql = 'SELECT media_type, ad_code, ad_link FROM ' . $ecs->table("ad") . ' WHERE position_id = 14 and enabled = 1 order by ad_id ';
$ad = $db->getRow($sql, true);
$smarty->assign('ad_userCenter', $ad);
$record_count = $db->getOne("SELECT COUNT(*) FROM " .$ecs->table('collect_goods'). " WHERE user_id='$user_id' ORDER BY add_time DESC");
$smarty->assign('record_count', $record_count); //收藏的商品的总数
$cart_goods=get_cart_goods(); //购物车里的数据
$smarty->assign('you_may_favorite' ,you_may_favorite());//用户浏览记录
$smarty->assign('visit_history' ,insert_history_userCenter());//用户浏览记录
$smarty->assign('collection_goods' ,get_collection_goods($user_id));//收藏的商品(取10个)
$smarty->assign('cart_goods' ,$cart_goods['goods_list']); //获取购物车里的商品列表
$smarty->assign('info', get_user_default($user_id));
$smarty->assign('user_notice', $_CFG['user_notice']);
$smarty->assign('prompt', get_user_prompt($user_id));
$smarty->display('user_clips.dwt');
}
if($action == 'check_SMS_code')
{
$mobile_phone = $_REQUEST['mobilePhone'];
$verify_code = $_REQUEST['verify_code'];
$sql = "SELECT user_id from ecs_users where mobile_phone=$mobile_phone";
$user_id = $db->getOne($sql);
$sql = "SELECT short_message from ecs_verified_sms where user_id=$user_id";
$short_message = $db->getOne($sql);
if($verify_code== $short_message)
{
header("Cache-control:no-cache,no-store,must-revalidate");
header("Pragma:no-cache");
header("Expires:0");
if($_COOKIE['resetpw_success_vph']==$_REQUEST['cookie_value'])
{
$smarty->assign('redrectUrl',"user.php");
$smarty->assign('smalltext','密码已修改,页面失效');
$smarty->assign('content','密码之前已被修改。3秒后将返回登陆页,请用新密码登陆,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
else
{
$smarty->assign('cookie_value', $_REQUEST['cookie_value']);
$smarty->assign('uid', $user_id);
$smarty->assign('action', 'reset2_password');
$smarty->display('user_passport.dwt');
}
}
else{
$user_name=$_REQUEST['mobilePhone'];
$smarty->assign('redrectUrl',"user.php?act=get_phone_password&user_name=$user_name");
$smarty->assign('smalltext','验证码有误!');
$smarty->assign('content','您输入的验证码有误,3秒后自动返回,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
// echo "验证码出错";
// exit();
}
}
/* 验证,修改手机号 chen-0912*/
if($action=="about_verify_phone")
{
$type=!empty($_REQUEST['type'])?$_REQUEST['type']:'verify';
$sms = !empty($_REQUEST['validator'])?$_REQUEST['validator']:'';
$phone = !empty($_REQUEST['phone'])?$_REQUEST['phone']:'';
switch($type)
{
case 'verify':
$sql = "select short_message from ".$GLOBALS['ecs']->table('verified_sms')." where user_id='$user_id' and type=1";
$short_message = $GLOBALS['db']->getOne($sql);
$rec = 0;
if($sms == $short_message)
{
$sql = "select chat_validated from ".$GLOBALS['ecs']->table('users')." where user_id='$user_id' ";
$chat_validated = $GLOBALS['db']->getOne($sql);
switch($chat_validated)
{
case 0:
$sql = "update ".$GLOBALS['ecs']->table('users')." set chat_validated = 2 where user_id='$user_id' ";
break;
case 1:
$sql = "update ".$GLOBALS['ecs']->table('users')." set chat_validated = 3 where user_id='$user_id' ";
break;
}
$flag=$GLOBALS['db']->query($sql);
if($flag) $rec=1;
}
if(!$rec){
$smarty->assign('redrectUrl',"user.php?act=security_edit_psd&type=phone&phone=$phone&validate=0");
$smarty->assign('smalltext','验证码失败');
$smarty->assign('content','输入的短信验证码错误或出现未知错误。3秒后将返回原页面,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
else{
require_once(dirname(__FILE__) . '/includes/lib_integral.php');
$ever_validated = $GLOBALS['db']->getOne("select ever_validated from ".$GLOBALS['ecs']->table('users')." where user_id='$user_id'");
if($ever_validated == '0' || $ever_validated == '1')
{
user_get_point($_CFG['validated_integral'],$user_id,4,'手机验证获得积分',0);
user_has_got_integral('phone',$user_id, $ever_validated);
}
$smarty->assign('redrectUrl',"user.php?act=security_settings");
$smarty->assign('smalltext','验证成功');
$smarty->assign('content','您已成功验证手机。3秒后将返回安全设置页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
break;
case "edit":
$sql = "select short_message,new_shot_msg,new_phone from ".$GLOBALS['ecs']->table('verified_sms')." where user_id=$user_id and type=2";
$row = $GLOBALS['db']->getRow($sql);
$rec = 0;
if($row['short_message']==$_REQUEST['old_capthcha'] && $row['new_shot_msg'] == $_REQUEST['new_capthcha'])
{
$sql = "update ".$GLOBALS['ecs']->table('users')." set mobile_phone = ".$row['new_phone']." where user_id=$user_id";
$flag=$GLOBALS['db']->query($sql);
if($flag) $rec=1;
}
else
{
if($row['short_message']!=$_REQUEST['old_capthcha'])
$rec = 2;
else
$rec = 3;
}
if(!$rec){
$smarty->assign('redrectUrl',"user.php?act=security_edit_psd&type=phone&phone=$phone&validate=3");
$smarty->assign('smalltext','修改绑定手机失败');
$smarty->assign('content','输入的短信验证码有误或出现未知错误。3秒后将返回原页面,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
else{
$smarty->assign('redrectUrl',"user.php?act=security_settings");
$smarty->assign('smalltext','修改成功');
$smarty->assign('content','您已成功修改绑定手机。3秒后将返回安全设置页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
break;
}
}
/* 显示会员注册界面 */
if ($action == 'register')
{
// echo "<br>register<br>";
$smarty->assign('script_name', 'register');
if ((!isset($back_act)||empty($back_act)) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
/* 取出注册扩展字段 */
$sql = 'SELECT * FROM ' . $ecs->table('reg_fields') . ' WHERE type < 2 AND display = 1 ORDER BY dis_order, id';
$extend_info_list = $db->getAll($sql);
$smarty->assign('extend_info_list', $extend_info_list);
/* 验证码相关设置 */
if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
$smarty->assign('enabled_captcha', 1);
$smarty->assign('rand', mt_rand());
}
/* 密码提示问题 */
$smarty->assign('passwd_questions', $_LANG['passwd_questions']);
/* 增加是否关闭注册 */
$smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
// $smarty->assign('back_act', $back_act);
$smarty->display('user_passport.dwt');
}
/* 注册会员的处理 */
elseif ($action == 'act_register')
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$flag=0;
/* 增加是否关闭注册 */
if ($_CFG['shop_reg_closed'])
{
$smarty->assign('action', 'register');
$smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
$smarty->display('user_passport.dwt');
}
else
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$username = "";
$password = "";
$nickname = "";
$type = "";
if(isset($_POST['email']))
{
$username=compile_str(trim($_POST['email']));
}
elseif(isset($_POST['phone']))
{
$username=compile_str(trim($_POST['phone']));
}else{echo "location:user.php error:username(email or phone isn't posted)"; exit();}
if(isset($_POST['email_psd']))
{
$password=compile_str(trim($_POST['email_psd']));
}
elseif(isset($_POST['phone_psd']))
{
$password=compile_str(trim($_POST['phone_psd']));
}else{echo "location:user.php error:password isn't posted"; exit();}
if(isset($_POST['email_nick_name']))
{
$nickname=compile_str(trim($_POST['email_nick_name']));
}
elseif(isset($_POST['phone_nick_name']))
{
$nickname=compile_str(trim($_POST['phone_nick_name']));
}else{echo "location:user.php error:昵称没有填写"; exit();}
/* 验证码检查 */
if(isset($_POST['type']) && ( $_POST['type'] == 'email' || $_POST['type'] == 'phone') )
{
$type=compile_str(trim($_POST['type']));
} else{echo "location:user.php error:既不是邮箱或也不是手机注册。"; exit();}
if($type == 'email') //只有email下才有验证码
{
if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
$flag=1;
$smarty->assign('redrectUrl',"user.php?act=register");
$smarty->assign('smalltext','注册失败');
$smarty->assign('content','验证码为空,请填写验证码后再提交。页面将返回注册页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
exit;
}
else
{
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
if (!$validator->check_word($_POST['captcha']))
{ $flag=1;
$smarty->assign('redrectUrl',"user.php?act=register");
$smarty->assign('smalltext','注册失败');
$smarty->assign('content','验证码不正确,建议点击验证码旁的换一张,来获取新验证码。页面将返回注册页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
exit;
}
}
}
}
else if($type == 'phone') //只有手机注册下,才有验证短信
{
$captcha = compile_str(trim($_POST['captcha']));
$sql = "select short_msm from ".$GLOBALS['ecs']->table('verified_register_SMS')." where phone = '$username'";
$sent_sms = $GLOBALS['db']->getOne($sql);
if($captcha != $sent_sms)
{
$smarty->assign('redrectUrl',"user.php?act=register");
$smarty->assign('smalltext','注册失败');
$smarty->assign('content','输入的短信验证有误!页面将返回注册页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
exit;
}
}
if ($flag==0 && register($username, $password) !== false)
{
/* 判断是否需要自动发送注册邮件 */
/*if($GLOBALS['_CFG']['member_email_validate'] && $GLOBALS['_CFG']['send_verify_email'])
{
send_regiter_hash($_SESSION['user_id']);
}*/
$emailUserValid = ''; //给未验证邮箱的邮箱注册用户做个标记。登陆时,做判断用。不让其登陆。
if($type == 'email')
{
$emailUserValid = ' , chat_validated = -1 ';
send_regiter_hash($_SESSION['user_id'],'emailUserValid');
}
$sql = "update ".$GLOBALS['ecs']->table('users')." set nickname = '$nickname' $emailUserValid where user_id = '".$_SESSION['user_id']."'";
$GLOBALS['db']->query($sql);
if($type == 'email' )
{
$user->logout();
require_once(dirname(__FILE__) . '/includes/lib_passport.php');
$smarty->assign('registerEmail',$username);
$smarty->assign('loginEmail',get_mail_serverAddr($username));
$smarty->assign('registerPoint',$_CFG['register_points']);
$smarty->display('email_register_validate.dwt');
}
else if($type == 'phone')
{
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
require_once(dirname(__FILE__) . '/includes/lib_integral.php');
user_get_point($_CFG['validated_integral'],$_SESSION['user_id'],4,'手机验证获得积分',0);
user_has_got_integral('phone',$_SESSION['user_id']);
$smarty->assign('redrectUrl',"/");
$smarty->assign('smalltext','注册成功');
$smarty->assign('content','您已成功注册,页面将跳转到首页。如果未跳转请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
}
else
{
$smarty->assign('redrectUrl',"user.php?act=register");
$smarty->assign('smalltext','注册失败');
$smarty->assign('content','注册失败,请检查账号和密码是否符合注册要求。页面将返回注册页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
}
}
// 第三方登录接口
elseif($action == 'oath')
{
$type = empty($_REQUEST['type']) ? '' : $_REQUEST['type'];
if($type == "taobao"){
header("location:includes/website/tb_index.php");exit;
}
include_once(ROOT_PATH . 'includes/website/jntoo.php');
$c = &website($type);
if($c)
{
if (empty($_REQUEST['callblock']))
{
if (empty($_REQUEST['callblock']) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? 'index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
else
{
$back_act = 'index.php';
}
}
else
{
$back_act = trim($_REQUEST['callblock']);
}
if($back_act[4] != ':') $back_act = $ecs->url().$back_act;
$open = empty($_REQUEST['open']) ? 0 : intval($_REQUEST['open']);
$url = $c->login($ecs->url().'user.php?act=oath_login&type='.$type.'&callblock='.urlencode($back_act).'&open='.$open);
if(!$url)
{
show_message( $c->get_error() , '首页', $ecs->url() , 'error');
}
header('Location: '.$url);
}
else
{
show_message('服务器尚未注册该插件!' , '首页',$ecs->url() , 'error');
}
}
// 处理第三方登录接口
elseif($action == 'oath_login')
{
$type = empty($_REQUEST['type']) ? '' : $_REQUEST['type'];
include_once(ROOT_PATH . 'includes/website/jntoo.php');
$c = &website($type);
if($c)
{
$access = $c->getAccessToken();
if(!$access)
{
show_message( $c->get_error() , '首页', $ecs->url() , 'error');
}
$c->setAccessToken($access);
$info = $c->getMessage();
if(!$info)
{
show_message($c->get_error() , '首页' , $ecs->url() , 'error' , false);
}
if(!$info['user_id'])
show_message($c->get_error() , '首页' , $ecs->url() , 'error' , false);
$info_user_id = $type .'_'.$info['user_id']; // 加个标识!!!防止 其他的标识 一样 // 以后的ID 标识 将以这种形式 辨认
$info['name'] = str_replace("'" , "" , $info['name']); // 过滤掉 逗号 不然出错 很难处理 不想去 搞什么编码的了
if(!$info['user_id'])
show_message($c->get_error() , '首页' , $ecs->url() , 'error' , false);
$sql = 'SELECT user_name,password,aite_id FROM '.$ecs->table('users').' WHERE aite_id = \''.$info_user_id.'\' OR aite_id=\''.$info['user_id'].'\'';
$count = $db->getRow($sql);
if(!$count) // 没有当前数据
{
if($user->check_user($info['name'])) // 重名处理
{
$info['name'] = $info['name'].'_'.$type.(rand(10000,99999));
}
$user_pass = $user->compile_password(array('password'=>$info['user_id']));
$sql = 'INSERT INTO '.$ecs->table('users').'(user_name , password, aite_id , sex , reg_time , user_rank , is_validated) VALUES '.
"('$info[name]' , '$user_pass' , '$info_user_id' , '$info[sex]' , '".gmtime()."' , 0 , '1')" ;//'$info[rank_id]' , '1')" ;
$db->query($sql);
}
else
{
$sql = '';
if($count['aite_id'] == $info['user_id'])
{
$sql = 'UPDATE '.$ecs->table('users')." SET aite_id = '$info_user_id' WHERE aite_id = '$count[aite_id]'";
$db->query($sql);
}
if($info['name'] != $count['user_name']) // 这段可删除
{
if($user->check_user($info['name'])) // 重名处理
{
$info['name'] = $info['name'].'_'.$type.(rand()*1000);
}
$sql = 'UPDATE '.$ecs->table('users')." SET user_name = '$info[name]' WHERE aite_id = '$info_user_id'";
$db->query($sql);
}
}
$user->set_session($info['name']);
$user->set_cookie($info['name']);
update_user_info();
recalculate_price();
if(!empty($_REQUEST['open']))
{
die('<script>window.opener.window.location.reload(); window.close();</script>');
}
else
{
ecs_header('Location: '.$_REQUEST['callblock']);
}
}
}
// 处理其它登录接口
elseif($action == 'other_login')
{
$type = empty($_REQUEST['type']) ? '' : $_REQUEST['type'];
session_start();
$info = $_SESSION['user_info'];
if(empty($info)){
show_message("非法访问或请求超时!" , '首页' , $ecs->url() , 'error' , false);
}
if(!$info['user_id'])
show_message("非法访问或访问出错,请联系管理员!", '首页' , $ecs->url() , 'error' , false);
$info_user_id = $type .'_'.$info['user_id']; // 加个标识!!!防止 其他的标识 一样 // 以后的ID 标识 将以这种形式 辨认
$info['name'] = str_replace("'" , "" , $info['name']); // 过滤掉 逗号 不然出错 很难处理 不想去 搞什么编码的了
$sql = 'SELECT user_name,password,aite_id FROM '.$ecs->table('users').' WHERE aite_id = \''.$info_user_id.'\' OR aite_id=\''.$info['user_id'].'\'';
$count = $db->getRow($sql);
$login_name = $info['name'];
if(!$count) // 没有当前数据
{
if($user->check_user($info['name'])) // 重名处理
{
$info['name'] = $info['name'].'_'.$type.(rand()*1000);
}
$login_name = $info['name'];
$user_pass = $user->compile_password(array('password'=>$info['user_id']));
$sql = 'INSERT INTO '.$ecs->table('users').'(user_name , password, aite_id , sex , reg_time , user_rank , is_validated) VALUES '.
"('$info[name]' , '$user_pass' , '$info_user_id' , '$info[sex]' , '".gmtime()."' , '$info[rank_id]' , '1')" ;
$db->query($sql);
}
else
{
$login_name = $count['user_name'];
$sql = '';
if($count['aite_id'] == $info['user_id'])
{
$sql = 'UPDATE '.$ecs->table('users')." SET aite_id = '$info_user_id' WHERE aite_id = '$count[aite_id]'";
$db->query($sql);
}
}
$user->set_session($login_name);
$user->set_cookie($login_name);
update_user_info();
recalculate_price();
$redirect_url = "http://".$_SERVER["HTTP_HOST"].str_replace("user.php", "index.php", $_SERVER["REQUEST_URI"]);
header('Location: '.$redirect_url);
}
/* 验证用户注册邮件 chen-0912*/
elseif ($action == 'validate_email')
{
$hash = empty($_GET['hash']) ? '' : trim($_GET['hash']);
$type = empty($_GET['type']) ? '' : trim($_GET['type']);
if ($hash)
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$id = register_hash('decode', $hash);
if ($id > 0)
{
switch($type)
{
case "register":
$sql = "select chat_validated from ".$ecs->table('users')." where user_id = '$id'";
$chat_validated = $db->getOne($sql);
switch($chat_validated)
{
case '0':$chat_validated=1; break;
case '2':$chat_validated=3; break;
}
$sql = "UPDATE " . $ecs->table('users') . " SET chat_validated = $chat_validated WHERE user_id='$id'";
$db->query($sql);
$sql = 'SELECT user_name, email, ever_validated FROM ' . $ecs->table('users') . " WHERE user_id = '$id'";
$row = $db->getRow($sql);
require_once(dirname(__FILE__) . '/includes/lib_integral.php');
if($row['ever_validated'] == '0' || $row['ever_validated'] == '2')
{
user_get_point($_CFG['validated_integral'],$id,4,'邮箱验证获得积分',0);
user_has_got_integral('email',$id,$row['ever_validated']);
}
show_message(sprintf($_LANG['validate_ok'], $row['user_name'], $row['email']),$_LANG['profile_lnk'], 'user.php');
break;
case "disbind":
$sql = "select chat_validated from ".$ecs->table('users')." where user_id = '$id'";
$chat_validated = $db->getOne($sql);
switch($chat_validated)
{
case '1': $chat_validated=0; break;
case '3': $chat_validated=2;break;
}
$sql = "UPDATE " . $ecs->table('users') . " SET chat_validated = $chat_validated WHERE user_id='$id'";
$db->query($sql);
$sql = 'SELECT user_name, email FROM ' . $ecs->table('users') . " WHERE user_id = '$id'";
$row = $db->getRow($sql);
show_message(sprintf('您已成功解除邮箱绑定',$row['user_name'],$row['email']),$_LANG['profile_lnk'],'user.php');
break;
case "emailUserValid":
$sql = "update ".$GLOBALS['ecs']->table('users')." set email=user_name,chat_validated = 1 where user_id='$id'";
$db->query($sql);
$_SESSION['user_id'] = $id;
$row = $db->getRow('SELECT user_name, user_rank FROM ' . $ecs->table('users') . " WHERE user_id = '$id'");
$_SESSION['user_name'] = $row['user_name'];
$_SESSION['user_rank'] = 1;
require_once(dirname(__FILE__) . '/includes/lib_integral.php');
user_get_point($_CFG['validated_integral'],$id,4,'邮箱验证获得积分',0);
user_has_got_integral('email',$id);
show_message('邮箱注册成功!',$_LANG['profile_lnk'],'user.php');
break;
}
}
}
show_message($_LANG['validate_fail']);
}
/* 验证用户注册用户名是否可以注册 */
elseif ($action == 'is_registered')
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$username = trim($_GET['username']);
$username = json_str_iconv($username);
$type = isset($_GET['type']) ? $_GET['type']:'';
if($type != 'email' && $type != 'phone')
{
die(json_encode('register type isn\'t email or phone'));
}
if ($user->check_user($username) || admin_registered($username))
{
echo json_encode(array('type'=>$type,'result'=>'false'));
}
else
{
echo json_encode(array('type'=>$type,'result'=>'true'));
}
exit;
}
/* 验证用户邮箱地址是否被注册 */
elseif($action == 'check_email')
{
$email = trim($_GET['email']);
// echo "email==$email";
if ($user->check_email($email))
{
echo 'false';
}
else
{
echo 'ok';
}
exit;
}
/* 用户登录界面 */
elseif ($action == 'login')
{
$smarty->assign('script_name', 'login');
if (empty($back_act))
{
if (empty($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
else
{
$back_act = 'user.php';
}
}
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
$GLOBALS['smarty']->assign('enabled_captcha', 1);
$GLOBALS['smarty']->assign('rand', mt_rand());
}
$smarty->assign('back_act', $back_act);
$smarty->display('user_passport.dwt');
}
/* 处理会员的登录 */
elseif ($action == 'act_login')
{
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : 'user.php';
//echo "domain===".$_SERVER[REQUEST_URI]."</br>";
// echo $back_act."</br>";
// echo dirname(__FILE__);//."/../";
// exit;
if ($user->login($username, $password,isset($_POST['remember'])))
{
update_user_info();
recalculate_price();
$sql = "select chat_validated from ".$GLOBALS['ecs']->table('users')." where user_id = '" .$_SESSION['user_id']."'";
$chat_validated = $GLOBALS['db']->getOne($sql);
if($chat_validated == -1)
{
// echo '-1';
// echo '<br/>userid=='.$_SESSION['user_id'];
// $user->logout();
// echo '<br/>userid=='.$_SESSION['user_id'];
$user->logout();
require_once(dirname(__FILE__) . '/includes/lib_passport.php');
$smarty->assign('registerEmail',$username);
$smarty->assign('loginEmail',get_mail_serverAddr($username));
$smarty->assign('registerPoint',$_CFG['register_points']);
$smarty->display('email_hasnot_validate.dwt');
}
else
{
// var_dump($_REQUEST);
// echo $back_act;exit;
//ecs_header("Location:$back_act");//该处作用是直接进入登陆状态不提示 guan-0930
$smarty->assign('redrectUrl',$back_act);
$smarty->assign('smalltext','登陆成功');
$smarty->assign('content','您登陆成功了。3秒后页面将跳转,如果未跳转请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
}
else
{
$smarty->assign('redrectUrl',"user.php");
$smarty->assign('smalltext','登陆失败');
$smarty->assign('content','请检查用户名或密码是否有误。3秒后将返回到登陆页,如果未返回请');
$smarty->assign('action', 'pageRedirect');
$smarty->display('user_passport.dwt');
}
}
/*手机,邮箱:验证修改 ajax chen-0912*/
elseif($action == 'set_user_contact')
{
include_once('includes/lib_passport.php');
$type=$_REQUEST['type'];
$is_validate = $_REQUEST['is_validate'];
$user_id = $_SESSION['user_id'];
$value = $_REQUEST['value'];
switch($type)
{
case 'email':
switch($is_validate)
{
case 0: //取消邮箱验证
{
$email_format=get_mail_serverAddr($value);
echo json_encode($email_format);
}
break;
case 1: //邮箱验证
{
$sql = "select user_id from ".$GLOBALS['ecs']->table('users')." where (email = '$value' and chat_validated <> 0 and chat_validated <> 2 and user_id <> $user_id) or user_id=$user_id";
$row = $GLOBALS['db']->getRow($sql);
if(!$row || ($row['user_id']==$user_id && ($row['chat_validated']==0 || $row['chat_validated']==2)))
{
$sql = "update ".$GLOBALS['ecs']->table('users')." set email = '$value' where user_id=$user_id";
$GLOBALS['db']->query($sql);
$email_format=get_mail_serverAddr($value);
//echo $value;
// echo $email_format;
echo json_encode($email_format);
}
else if($row['user_id']==$user_id && ($row['chat_validated']==1 || $row['chat_validated']==3) )
{
echo "1";
}
else
{
// echo json_encode("this email has validated by others");
echo "0";
}
}
break;
}
break;
case 'phone':
switch($is_validate)
{
case 1:
$sql = "select user_id from ".$GLOBALS['ecs']->table('users')." where (mobile_phone = '$value' and chat_validated <> 0 and chat_validated <> 1 and user_id <> $user_id) or user_id=$user_id";
$row = $GLOBALS['db']->getRow($sql);
if(!$row || ($row['user_id']==$user_id && ($row['chat_validated']==0 || $row['chat_validated']==1)))
{
$sql = "update ".$GLOBALS['ecs']->table('users')." set mobile_phone = '$value' where user_id=$user_id";
$GLOBALS['db']->query($sql);
}
else if($row['user_id']==$user_id && ($row['chat_validated']==2 || $row['chat_validated']==3) )
{
echo "1";
}
else
{
// echo json_encode("this email has validated by others");
echo "0";
}
break;
case 0:
break;
case 2:
break;
}
break;
}
}
/* 处理 ajax 的登录请求 */
elseif ($action == 'signin')
{
// var_dump($_POST);
// exit();
include_once('includes/cls_json.php');
$json = new JSON;
$username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : '';
$password = !empty($_POST['password']) ? trim($_POST['password']) : '';
$captcha = !empty($_POST['captcha']) ? json_str_iconv(trim($_POST['captcha'])) : '';
$result = array('error' => 0, 'content' => '');
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
if (empty($captcha))
{
$result['error'] = 1;
$result['content'] = $_LANG['invalid_captcha'];
die($json->encode($result));
}