member_actfun.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. //加密
  3. function QMReturnCheckPass($userid,$username,$email,$ecms=1){
  4. global $ecms_config;
  5. $r['rnd']=make_password(12);
  6. $r['dotime']=time();
  7. $r['checkpass']=md5(md5($r['rnd'].'-'.$userid.'-'.$r['dotime'].'-'.$ecms).$ecms_config['cks']['ckrnd']);
  8. $r['ecms']=$ecms;
  9. return $r;
  10. }
  11. //验证
  12. function QMReturnCheckThePass($ckuserid,$ckpass,$cktime,$authstr,$ecms=1){
  13. global $empire,$dbtbpre,$ecms_config,$public_r;
  14. $f=$ecms==2?'acttime':'getpasstime';
  15. $time=time();
  16. $pr=$empire->fetch1("select ".$f." from {$dbtbpre}enewspublic limit 1");
  17. $ar=explode('||',$authstr);
  18. if($cktime>$time||$time-$cktime>$pr[$f]*3600||$ar[0]!=$cktime)
  19. {
  20. printerror('GPOutTime',$public_r['newsurl'],1);
  21. }
  22. $pass=md5(md5($ar[2].'-'.$ckuserid.'-'.$ar[0].'-'.$ar[1]).$ecms_config['cks']['ckrnd']);
  23. if('dg'.$pass!='dg'.$ckpass)
  24. {
  25. printerror('GPErrorPass',$public_r['newsurl'],1);
  26. }
  27. }
  28. //替换邮件内容变量
  29. function QMRepEmailtext($userid,$username,$email,$pageurl,$title,$text){
  30. global $empire,$dbtbpre,$public_r;
  31. $date=date("Y-m-d");
  32. $r[text]=str_replace('[!--pageurl--]',$pageurl,$text);
  33. $r[text]=str_replace('[!--username--]',$username,$r[text]);
  34. $r[text]=str_replace('[!--email--]',$email,$r[text]);
  35. $r[text]=str_replace('[!--date--]',$date,$r[text]);
  36. $r[text]=str_replace('[!--sitename--]',$public_r[sitename],$r[text]);
  37. $r[text]=str_replace('[!--news.url--]',$public_r[newsurl],$r[text]);
  38. $r[title]=str_replace('[!--pageurl--]',$pageurl,$title);
  39. $r[title]=str_replace('[!--username--]',$username,$r[title]);
  40. $r[title]=str_replace('[!--email--]',$email,$r[title]);
  41. $r[title]=str_replace('[!--date--]',$date,$r[title]);
  42. $r[title]=str_replace('[!--sitename--]',$public_r[sitename],$r[title]);
  43. $r[title]=str_replace('[!--news.url--]',$public_r[newsurl],$r[title]);
  44. return $r;
  45. }
  46. //--------------- 取回密码 --------------
  47. //发送取回密码邮件
  48. function SendGetPasswordEmail($add){
  49. global $empire,$dbtbpre,$public_r;
  50. if(!$public_r['opengetpass'])
  51. {
  52. printerror('CloseGetPassword','',1);
  53. }
  54. $username=trim($add[username]);
  55. $email=trim($add[email]);
  56. if(!$username||!$email)
  57. {
  58. printerror("EmptyGetPassword","history.go(-1)",1);
  59. }
  60. //验证码
  61. $key=$add['key'];
  62. $keyvname='checkgetpasskey';
  63. ecmsCheckShowKey($keyvname,$key,1);
  64. $username=RepPostVar($username);
  65. $email=addslashes(RepPostStr($email));
  66. $email=RepPostVar($email);
  67. if(!chemail($email))
  68. {
  69. printerror("EmailFail","history.go(-1)",1);
  70. }
  71. $ur=$empire->fetch1("select ".eReturnSelectMemberF('userid,username,email')." from ".eReturnMemberTable()." where ".egetmf('username')."='$username' limit 1");
  72. $useremail=$ur['email'];
  73. if(!$ur['userid']||$useremail!=$email)
  74. {
  75. printerror("ErrorGPUsername","history.go(-1)",1);
  76. }
  77. $passr=QMReturnCheckPass($ur['userid'],$username,$email,1);
  78. $authstr=$passr['dotime'].'||'.$passr['ecms'].'||'.$passr['rnd'];
  79. $sql=DoUpdateMemberAuthstr($ur['userid'],$authstr);
  80. $url=eReturnDomainSiteUrl().'e/member/GetPassword/getpass.php?id='.$ur['userid'].'&cc='.$passr[checkpass].'&tt='.$passr['dotime'];
  81. //发送邮件
  82. $pr=$empire->fetch1("select getpasstext,getpasstitle from {$dbtbpre}enewspublic limit 1");
  83. @include(ECMS_PATH.'e/class/SendEmail.inc.php');
  84. $textr=QMRepEmailtext($ur['userid'],$username,$email,$url,$pr['getpasstitle'],$pr['getpasstext']);
  85. $sm=EcmsToSendMail($email,$textr['title'],$textr['text']);
  86. ecmsEmptyShowKey($keyvname);//清空验证码
  87. printerror("SendGetPasswordEmailSucess",$public_r['newsurl'],1);
  88. }
  89. //接收验证信息
  90. function CheckGetPassword($add,$ecms=1){
  91. global $empire,$dbtbpre,$public_r;
  92. $r['id']=(int)$add['id'];
  93. $r['tt']=(int)$add['tt'];
  94. $r['cc']=RepPostVar($add['cc']);
  95. if(!$r[id]||!$r[tt]||!$r[cc])
  96. {
  97. printerror('GPErrorPass',$public_r['newsurl'],1);
  98. }
  99. $ur=$empire->fetch1("select ".eReturnSelectMemberF('userid,username,checked,groupid')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$r[id]' limit 1");
  100. if(empty($ur['userid']))
  101. {
  102. printerror('GPErrorPass',$public_r['newsurl'],1);
  103. }
  104. $addur=$empire->fetch1("select authstr from {$dbtbpre}enewsmemberpub where userid='$r[id]' limit 1");
  105. if(!$addur['authstr'])
  106. {
  107. printerror('GPErrorPass',$public_r['newsurl'],1);
  108. }
  109. QMReturnCheckThePass($r['id'],$r['cc'],$r['tt'],$addur['authstr'],$ecms);
  110. $r['username']=$ur['username'];
  111. $r['checked']=$ur['checked'];
  112. $r['groupid']=$ur['groupid'];
  113. return $r;
  114. }
  115. //修改密码
  116. function DoGetPassword($add){
  117. global $empire,$dbtbpre,$public_r;
  118. if(!$public_r['opengetpass'])
  119. {
  120. printerror('CloseGetPassword','',1);
  121. }
  122. $r=CheckGetPassword($add,1);
  123. $password=RepPostVar($add['newpassword']);
  124. $add['renewpassword']=RepPostVar($add['renewpassword']);
  125. if($password!=$add['renewpassword'])
  126. {
  127. printerror('NotRepassword','',1);
  128. }
  129. //密码
  130. $salt=eReturnMemberSalt();
  131. $password=eDoMemberPw($password,$salt);
  132. $sql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('password')."='$password',".egetmf('salt')."='$salt' where ".egetmf('userid')."='$r[id]'");
  133. $usql=$empire->query("update {$dbtbpre}enewsmemberpub set authstr='' where userid='$r[id]'");
  134. printerror('GetPasswordSuccess',$public_r['newsurl'],1);
  135. }
  136. //--------------- 帐号激活 --------------
  137. //发送激活帐号邮件
  138. function SendActUserEmail($userid,$username,$email){
  139. global $empire,$dbtbpre,$public_r;
  140. $email=addslashes($email);
  141. $passr=QMReturnCheckPass($userid,$username,$email,2);
  142. $authstr=$passr['dotime'].'||'.$passr['ecms'].'||'.$passr['rnd'];
  143. $sql=DoUpdateMemberAuthstr($userid,$authstr);
  144. $url=eReturnDomainSiteUrl().'e/member/doaction.php?enews=DoActUser&id='.$userid.'&cc='.$passr[checkpass].'&tt='.$passr['dotime'];
  145. //发送邮件
  146. $pr=$empire->fetch1("select acttext,acttitle from {$dbtbpre}enewspublic limit 1");
  147. @include(ECMS_PATH.'e/class/SendEmail.inc.php');
  148. $textr=QMRepEmailtext($userid,$username,$email,$url,$pr['acttitle'],$pr['acttext']);
  149. $sm=EcmsToSendMail($email,$textr['title'],$textr['text']);
  150. printerror("SendActUserEmailSucess",$public_r['newsurl'],1);
  151. }
  152. //激活帐号
  153. function DoActUser($add){
  154. global $empire,$dbtbpre,$public_r;
  155. $r=CheckGetPassword($add,2);
  156. if(!$r['checked'])
  157. {
  158. $checked=ReturnGroupChecked($r[groupid]);
  159. if($checked)
  160. {
  161. $sql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('checked')."=1 where ".egetmf('userid')."='$r[id]'");
  162. }
  163. }
  164. $usql=$empire->query("update {$dbtbpre}enewsmemberpub set authstr='' where userid='$r[id]'");
  165. printerror('ActUserSuccess',$public_r['newsurl'],1);
  166. }
  167. //重新发送帐号激活邮件
  168. function DoRegSend($add){
  169. global $empire,$dbtbpre,$public_r;
  170. if($public_r['regacttype']!=1)
  171. {
  172. printerror('CloseRegAct','',1);
  173. }
  174. $username=trim($add[username]);
  175. $password=trim($add[password]);
  176. $email=trim($add[email]);
  177. $newemail=trim($add[newemail]);
  178. if(!$username||!$password||!$email)
  179. {
  180. printerror("EmptyRegAct","history.go(-1)",1);
  181. }
  182. //验证码
  183. $key=$add['key'];
  184. $keyvname='checkregsendkey';
  185. ecmsCheckShowKey($keyvname,$key,1);
  186. $username=RepPostVar($username);
  187. $password=RepPostVar($password);
  188. $username=RepPostStr($username);
  189. $email=addslashes(RepPostStr($email));
  190. $newemail=addslashes(RepPostStr($newemail));
  191. $email=RepPostVar($email);
  192. $newemail=RepPostVar($newemail);
  193. if(!chemail($email))
  194. {
  195. printerror("EmailFail","history.go(-1)",1);
  196. }
  197. if($newemail)
  198. {
  199. if(!chemail($newemail))
  200. {
  201. printerror("EmailFail","history.go(-1)",1);
  202. }
  203. $sendemail=$newemail;
  204. }
  205. else
  206. {
  207. $sendemail=$email;
  208. }
  209. //密码
  210. $ur=$empire->fetch1("select ".eReturnSelectMemberF('userid,salt,password')." from ".eReturnMemberTable()." where ".egetmf('username')."='$username' limit 1");
  211. if(!$ur['userid'])
  212. {
  213. printerror("ErrorRegActUser","history.go(-1)",1);
  214. }
  215. if(!eDoCkMemberPw($password,$ur['password'],$ur['salt']))
  216. {
  217. printerror("ErrorRegActUser","history.go(-1)",1);
  218. }
  219. $r=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('username')."='$username' limit 1");
  220. $useremail=$r['email'];
  221. if(!$r['userid']||$useremail!=$email)
  222. {
  223. printerror("ErrorRegActUser","history.go(-1)",1);
  224. }
  225. if($r['checked'])
  226. {
  227. printerror("HaveRegActUser",'',1);
  228. }
  229. $addr=$empire->fetch1("select userid,authstr from {$dbtbpre}enewsmemberpub where userid='".$r['userid']."' limit 1");
  230. $ar=explode('||',$addr['authstr']);
  231. if(!$addr['userid']||!$addr['authstr']||$ar[1]!=2)
  232. {
  233. printerror("HaveRegActUser",'',1);
  234. }
  235. ecmsEmptyShowKey($keyvname);//清空验证码
  236. SendActUserEmail($r['userid'],$username,$sendemail);
  237. }
  238. ?>