LoginController.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?php
  2. namespace Home\Controller;
  3. class LoginController extends HomeController
  4. {
  5. protected function _initialize()
  6. {
  7. parent::_initialize(); $allow_action=array("index","register","upregister","loginsubmit","loginout","findpwd","findpaypwd","webreg","loption","setlang","lhelp","sendcode","findsendcode","resetpwd");
  8. if(!in_array(ACTION_NAME,$allow_action)){
  9. $this->error(L("非法操作"));
  10. }
  11. }
  12. //未登陆状态的选项页面
  13. public function loption(){
  14. $this->display();
  15. }
  16. //未登陆状态的设置语言
  17. public function setlang(){
  18. $this->display();
  19. }
  20. //帮助中心
  21. public function lhelp(){
  22. $uid = userid();
  23. $this->assign('uid',$uid);
  24. $this->display();
  25. }
  26. // 用户协议
  27. public function webreg()
  28. {
  29. $this->display();
  30. }
  31. public function index()
  32. {
  33. $uid = userid();
  34. if($uid >= 1){
  35. $this->redirect("Index/index");
  36. }
  37. $this->display();
  38. }
  39. //注册页面
  40. public function register(){
  41. $qrcode = I("get.qr");
  42. if($qrcode != ''){
  43. $this->assign('qrcode',$qrcode);
  44. }
  45. $this->display();
  46. }
  47. //提交重置密码
  48. public function resetpwd($email=null,$ecode=null,$lpwd=null){
  49. // if (checkstr($email) || checkstr($lpwd) || checkstr($ecode)) {
  50. // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
  51. // }
  52. if($email == ''){
  53. $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
  54. }
  55. if($ecode == ''){
  56. $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱验证码')]);
  57. }
  58. if($lpwd == ''){
  59. $this->ajaxReturn(['code'=>0,'info'=>L('请输入密码')]);
  60. }
  61. $findcode = session("findcode");
  62. if($findcode != $ecode){
  63. $this->ajaxReturn(['code'=>0,'info'=>L('邮箱验证码错误')]);
  64. }
  65. $uinfo = M("user")->where(array('username'=>$email))->field("id,username")->find();
  66. if(empty($uinfo)){
  67. $this->ajaxReturn(['code'=>0,'info'=>L('邮箱未注册')]);
  68. }
  69. $password = md5($lpwd);
  70. $result = M("user")->where(array('username'=>$email))->save(array('password'=>$password));
  71. if($result){
  72. $data['uid'] = $uinfo['id'];
  73. $data['account'] = $uinfo['username'];
  74. $data['title'] = L('重置密码');
  75. $data['content'] = L('登陆密码重置成功');
  76. $data['addtime'] = date("Y-m-d H:i:s",time());
  77. $data['status'] = 1;
  78. M("notice")->add($data);
  79. $this->ajaxReturn(['code'=>1,'info'=>L('登陆密码重置成功')]);
  80. }else{
  81. $this->ajaxReturn(['code'=>0,'info'=>L('密码重置失败')]);
  82. }
  83. }
  84. // 登录提交处理
  85. public function loginsubmit($email=null,$lpwd=null,$vcode=null){
  86. // if (checkstr($email) || checkstr($lpwd) || checkstr($vcode)) {
  87. // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
  88. // }
  89. if (!check_verify(strtoupper($vcode),'1')) {
  90. $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误!')]);
  91. }
  92. $user = M('User')->where(array('username' => $email))->find();
  93. if(empty($user)){
  94. $phone = M('User')->where(array('phone' => $email))->find();
  95. $user['id'] = $phone['id'];
  96. if(empty($phone)){
  97. $this->ajaxReturn(['code'=>0,'info'=> L('用户不存在')]);
  98. }
  99. }
  100. if (md5($lpwd) != $user['password']){
  101. if (md5($lpwd) != $phone['password']){
  102. $this->ajaxReturn(['code'=>0,'info'=> L('登录密码错误')]);
  103. }
  104. }
  105. if (isset($phone['status']) && $phone['status'] != 1) {
  106. if (isset($user['status']) && $user['status'] != 1) {
  107. $this->ajaxReturn(['code'=>0,'info'=> L('你的账号已冻结请联系管理员')]);
  108. }
  109. }
  110. //增加登陆次数
  111. $incre = M("user")->where(array('id' => $user['id']))->setInc('logins', 1);
  112. //新增登陆记录
  113. $data['userid'] = $user['id'];
  114. $data['type'] = L('登录');
  115. $data['remark'] = L('邮箱登录');
  116. $data['addtime'] = time();
  117. $data['addip'] = get_client_ip();
  118. $data['addr'] = get_city_ip();
  119. $data['status'] = 1;
  120. $dre = M("user_log")->add($data);
  121. if($incre && $dre){
  122. $lgdata['lgtime'] = date("Y-m-d",time());
  123. M("user")->where(array('id' => $user['id']))->save($lgdata);
  124. session('userId', $user['id']);
  125. session('userName', $user['username']);
  126. $this->ajaxReturn(['code'=>1,'info'=>L('登录成功')]);
  127. }else{
  128. $this->ajaxReturn(['code'=>0,'info'=>L('登录失败')]);
  129. }
  130. }
  131. //注册处理程序
  132. public function upregister($email,$lpwd,$invit,$yincang = 1,$ecode){
  133. if($_POST){
  134. if ($ecode != session('regcode')) $this->ajaxReturn(['code'=>0,'info'=>L('邮箱验证码错误')]);
  135. if(!$email) $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
  136. if($yincang == 1){
  137. $checkus = M('User')->where(array('username' => $email))->find();
  138. if(!empty($checkus)){
  139. $this->ajaxReturn(['code'=>0,'info'=>L('账户已存在')]);
  140. }
  141. }else{
  142. // $phones = M('User')->where(array('phone' => $phone))->find();
  143. // if(!empty($phones)){
  144. // $this->ajaxReturn(['code'=>0,'info'=>L('手机号已存在')]);
  145. // }
  146. }
  147. if($lpwd == ''){
  148. $this->ajaxReturn(['code'=>0,'info'=>L('请输入密码')]);
  149. }
  150. $config = M("config")->where(array('id'=>1))->field("tymoney")->find();
  151. if($invit != 0 || $invit != ''){
  152. $inv_user = M('User')->where(array('invit' => $invit))->field("id,username,invit_1,invit_2,path")->find();
  153. if(empty($inv_user)){
  154. $this->ajaxReturn(['code'=>0,'info'=>L('推荐人不存在')]);
  155. }
  156. $invit_1 = $inv_user['id'];
  157. $invit_2 = $inv_user['invit_1'];
  158. $invit_3 = $inv_user['invit_2'];
  159. $path = $inv_user['path'].','.$inv_user['id'];
  160. }else{
  161. $invit_1 = 0;
  162. $invit_2 = 0;
  163. $invit_3 = 0;
  164. $path = '';
  165. }
  166. for (; true; ) {
  167. $myinvit = tradenoa();
  168. if (!M('User')->where(array('invit' => $myinvit))->find()) {
  169. break;
  170. }
  171. }
  172. $mo = M();
  173. $mo->execute('set autocommit=0');
  174. $mo->execute('lock tables tw_user write , tw_user_coin write ');
  175. $rs = array();
  176. if($yincang == 2){
  177. $rs[] = $mo->table('tw_user')->add(
  178. array(
  179. 'username' => '',
  180. 'password' => md5($lpwd),
  181. 'money' => $config['tymoney'],
  182. 'invit' => $myinvit,
  183. 'invit_1' => $invit_1,
  184. 'invit_2' => $invit_2,
  185. 'invit_3' => $invit_3,
  186. 'path'=>$path,
  187. 'addip' => get_client_ip(),
  188. 'addr' => get_city_ip(),
  189. 'addtime' => time(),
  190. 'status' => 1,
  191. 'txstate' => 1,
  192. 'phone' => ''
  193. ));
  194. }else{
  195. $rs[] = $mo->table('tw_user')->add(
  196. array(
  197. 'username' => $email,
  198. 'password' => md5($lpwd),
  199. 'money' => $config['tymoney'],
  200. 'invit' => $myinvit,
  201. 'invit_1' => $invit_1,
  202. 'invit_2' => $invit_2,
  203. 'invit_3' => $invit_3,
  204. 'path'=>$path,
  205. 'addip' => get_client_ip(),
  206. 'addr' => get_city_ip(),
  207. 'addtime' => time(),
  208. 'status' => 1,
  209. 'txstate' => 1,
  210. ));
  211. }
  212. $user_coin = array('userid' => $rs[0]);
  213. // 创建用户数字资产档案
  214. $rs[] = $mo->table('tw_user_coin')->add($user_coin);
  215. if (check_arr($rs)) {
  216. $mo->execute('commit');
  217. $mo->execute('unlock tables');
  218. session('regcode', null); //初始化动态验证码
  219. $user = $mo->table('tw_user')->where(array('id'=>$rs[0]))->find();
  220. $this->ajaxReturn(['code'=>1,'info'=>L('注册成功')]);
  221. } else {
  222. $mo->execute('rollback');
  223. $this->ajaxReturn(['code'=>0,'info'=>L('注册失败')]);
  224. }
  225. }else{
  226. $this->ajaxReturn(['code'=>0,'info'=>L('网络错误')]);
  227. }
  228. }
  229. public function findsendcode($email,$vcode){
  230. // if(checkstr($email) || checkstr($vcode)) {
  231. // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
  232. // }
  233. $email = I('post.email');
  234. $vcode = I('post.vcode');
  235. if (!check_verify(strtoupper($vcode),'1')) {
  236. $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误')]);
  237. }
  238. if($email == ''){
  239. $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
  240. }
  241. $uinfo = M("user")->where(array('username'=>$email))->find();
  242. if(empty($uinfo)){
  243. $this->ajaxReturn(['code'=>0,'info'=>L('邮箱未注册')]);
  244. }
  245. $code = rand(10000,99999);
  246. $result = $this->emailsend($code,$email);
  247. if($result){
  248. session('findcode',$code);
  249. $this->ajaxReturn(['code'=>1,'info'=>L('验证码发送成功')]);
  250. }else{
  251. $this->ajaxReturn(['code'=>0,'info'=>L('验证码发送失败')]);
  252. }
  253. }
  254. //邮箱发送验证码
  255. public function sendcode($email,$vcode){
  256. if($_POST){
  257. // if(checkstr($email) || checkstr($vcode)) {
  258. // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
  259. // }
  260. $email = I('post.email');
  261. $vcode = I('post.vcode');
  262. if (!check_verify(strtoupper($vcode),'1')) {
  263. $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误')]);
  264. }
  265. if($email == ''){
  266. $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
  267. }
  268. $uinfo = M("user")->where(array('username'=>$email))->find();
  269. if(!empty($uinfo)){
  270. $this->ajaxReturn(['code'=>0,'info'=>L('账号已存在')]);
  271. }
  272. $code = rand(10000,99999);
  273. $result = $this->emailsend($code,$email);
  274. if($result){
  275. session('regcode',$code);
  276. $this->ajaxReturn(['code'=>1,'info'=>L('验证码发送成功')]);
  277. }else{
  278. $this->ajaxReturn(['code'=>0,'info'=>L('验证码发送失败')]);
  279. }
  280. }else{
  281. $this->ajaxReturn(['code'=>0,'info'=>L('网络错误')]);
  282. }
  283. }
  284. //邮件发送验证码
  285. public function emailsend($desc_content, $toemail){
  286. $config = $clist = M("config")->where(array('id'=>1))->field("smsemail,emailcode,smstemple")->find();
  287. $smsemail = "fj2568204@gmail.com";
  288. $emailcode = trim($config['emailcode']);
  289. $smstemple = '你的验证码';
  290. Vendor('PHPMailer.src.PHPMailer');
  291. Vendor('PHPMailer.src.SMTP');
  292. $mail = new \PHPMailer();
  293. $mail->SMTPDebug = 0;
  294. $mail->isSMTP();
  295. //$mail->CharSet = "utf8";
  296. $mail->Host = "smtp.gmail.com";
  297. $mail->SMTPAuth = true;
  298. $mail->Username = $smsemail; //@qq.com此账号仅供测试使用
  299. $mail->Password = "pfendaslmimputxh";
  300. $mail->SMTPSecure = "ssl";
  301. $mail->Port = 465;
  302. $mail->CharSet = 'UTF-8';
  303. $mail->setFrom($smsemail,"Verification Code");
  304. $mail->addAddress($toemail,'');
  305. $mail->addReplyTo($smsemail,"Reply");
  306. $mail->Subject = L('Verification Code');
  307. $mail->Body = $smstemple.":".$desc_content;
  308. if(!$mail->send()){
  309. return 0;
  310. }else{
  311. return 1;
  312. }
  313. }
  314. public function loginout()
  315. {
  316. session(null);
  317. redirect('/');
  318. }
  319. // 找回密码页面
  320. public function findpwd(){
  321. $this->display();
  322. }
  323. // 找回交易密码
  324. public function findpaypwd(){
  325. $this->display();
  326. }
  327. }
  328. ?>