LoginController.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <?php
  2. namespace Mobile\Controller;
  3. class LoginController extends MobileController
  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){
  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([
  126. // 'user' => $user['id'],
  127. // 'expire' => 60
  128. // ]);
  129. session('userName', $user['username']);
  130. $this->ajaxReturn(['code'=>1,'info'=>L('登录成功')]);
  131. }else{
  132. $this->ajaxReturn(['code'=>0,'info'=>L('登录失败')]);
  133. }
  134. }
  135. //注册处理程序
  136. public function upregister($email,$lpwd,$invit,$phone,$yincang,$ecode){
  137. // if($_POST){
  138. if ($ecode != session('regcode')) {
  139. $this->ajaxReturn(['code' => 0, 'info' => L('邮箱验证码错误')]);
  140. exit();
  141. }
  142. if($yincang == 1){
  143. $checkus = M('User')->where(array('username' => $email))->find();
  144. if(!empty($checkus)){
  145. $this->ajaxReturn(['code'=>0,'info'=>L('账户已存在')]);
  146. exit();
  147. }
  148. }else{
  149. $phones = M('User')->where(array('phone' => $phone))->find();
  150. if(!empty($phones)){
  151. $this->ajaxReturn(['code'=>0,'info'=>L('手机号已存在')]);
  152. exit();
  153. }
  154. }
  155. if($lpwd == ''){
  156. $this->ajaxReturn(['code'=>0,'info'=>L('请输入密码')]);
  157. exit();
  158. }
  159. if($invit == ''){
  160. $this->ajaxReturn(['code'=>0,'info'=>L('請輸入推薦人')]);
  161. exit();
  162. }
  163. $config = M("config")->where(array('id'=>1))->field("tymoney")->find();
  164. if($invit != 0 || $invit != ''){
  165. $inv_user = M('User')->where(array('invit' => $invit))->field("id,username,invit_1,invit_2,path")->find();
  166. if(empty($inv_user)){
  167. $this->ajaxReturn(['code'=>0,'info'=>L('推荐人不存在')]);
  168. exit();
  169. }
  170. $invit_1 = $inv_user['id'];
  171. $invit_2 = $inv_user['invit_1'];
  172. $invit_3 = $inv_user['invit_2'];
  173. $path = $inv_user['path'].','.$inv_user['id'];
  174. }else{
  175. $invit_1 = 0;
  176. $invit_2 = 0;
  177. $invit_3 = 0;
  178. $path = '';
  179. }
  180. for (; true; ) {
  181. $myinvit = tradenoa();
  182. if (!M('User')->where(array('invit' => $myinvit))->find()) {
  183. break;
  184. }
  185. }
  186. $mo = M();
  187. $mo->execute('set autocommit=0');
  188. $mo->execute('lock tables tw_user write , tw_user_coin write ');
  189. $rs = array();
  190. if($yincang == 2){
  191. $rs[] = $mo->table('tw_user')->add(
  192. array(
  193. 'username' => $phone,
  194. 'password' => md5($lpwd),
  195. 'money' => $config['tymoney'],
  196. 'invit' => $myinvit,
  197. 'invit_1' => $invit_1,
  198. 'invit_2' => $invit_2,
  199. 'invit_3' => $invit_3,
  200. 'path'=>$path,
  201. 'addip' => get_client_ip(),
  202. 'addr' => get_city_ip(),
  203. 'addtime' => time(),
  204. 'status' => 1,
  205. 'txstate' => 1,
  206. 'phone' => $phone
  207. ));
  208. }else{
  209. $rs[] = $mo->table('tw_user')->add(
  210. array(
  211. 'username' => $email,
  212. 'password' => md5($lpwd),
  213. 'money' => $config['tymoney'],
  214. 'invit' => $myinvit,
  215. 'invit_1' => $invit_1,
  216. 'invit_2' => $invit_2,
  217. 'invit_3' => $invit_3,
  218. 'path'=>$path,
  219. 'addip' => get_client_ip(),
  220. 'addr' => get_city_ip(),
  221. 'addtime' => time(),
  222. 'status' => 1,
  223. 'txstate' => 1,
  224. ));
  225. }
  226. $user_coin = array('userid' => $rs[0]);
  227. // 创建用户数字资产档案
  228. $rs[] = $mo->table('tw_user_coin')->add($user_coin);
  229. if (check_arr($rs)) {
  230. $mo->execute('commit');
  231. $mo->execute('unlock tables');
  232. M('levermoney')->add([
  233. 'uid' => $rs[0],
  234. 'username' => $email,
  235. 'money' => 0,
  236. 'moneyd' => 0,
  237. ]);
  238. session('regcode', null); //初始化动态验证码
  239. $user = $mo->table('tw_user')->where(array('id'=>$rs[0]))->find();
  240. $this->ajaxReturn(['code'=>1,'info'=>L('注册成功')]);
  241. } else {
  242. $mo->execute('rollback');
  243. $this->ajaxReturn(['code'=>0,'info'=>L('注册失败')]);
  244. }
  245. // }else{
  246. // $this->ajaxReturn(['code'=>0,'info'=>L('网络错误')]);
  247. // }
  248. }
  249. public function findsendcode(){
  250. // if(checkstr($email) || checkstr($vcode)) {
  251. // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
  252. // }
  253. $email = I('get.email');
  254. // $vcode = I('get.vcode');
  255. // if (!check_verify(strtoupper($vcode),'1')) {
  256. // $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误')]);
  257. // }
  258. if($email == ''){
  259. $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
  260. }
  261. $uinfo = M("user")->where(array('username'=>$email))->find();
  262. if(empty($uinfo)){
  263. $this->ajaxReturn(['code'=>0,'info'=>L('邮箱未注册')]);
  264. }
  265. $code = rand(10000,99999);
  266. $result = $this->emailsend($code,$email);
  267. if($result){
  268. session('findcode',$code);
  269. $this->ajaxReturn(['code'=>1,'info'=>L('验证码发送成功')]);
  270. }else{
  271. $this->ajaxReturn(['code'=>0,'info'=>L('验证码发送失败')]);
  272. }
  273. }
  274. //邮箱发送验证码
  275. public function sendcode(){
  276. // if($_POST){
  277. $email = I('get.email');
  278. $vcode = I('post.vcode');
  279. if(checkstr($email)) {
  280. $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
  281. }
  282. // if (!check_verify(strtoupper($vcode),'1')) {
  283. // $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误')]);
  284. // }
  285. if($email == ''){
  286. $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
  287. }
  288. $uinfo = M("user")->where(array('username'=>$email))->find();
  289. if(!empty($uinfo)){
  290. $this->ajaxReturn(['code'=>0,'info'=>L('账号已存在')]);
  291. }
  292. $code = rand(10000,99999);
  293. $result = $this->emailsend($code,$email);
  294. if($result){
  295. session('regcode',$code);
  296. $this->ajaxReturn(['code'=>1,'info'=>L('验证码发送成功')]);
  297. }else{
  298. $this->ajaxReturn(['code'=>0,'info'=>L('验证码发送失败')]);
  299. }
  300. //
  301. // }else{
  302. // $this->ajaxReturn(['code'=>0,'info'=>L('网络错误')]);
  303. // }
  304. }
  305. //邮件发送验证码
  306. public function emailsend($desc_content, $toemail){
  307. $config = $clist = M("config")->where(array('id'=>1))->field("smsemail,emailcode,smstemple")->find();
  308. $smsemail = "a79299527315@gmail.com";
  309. $emailcode = trim($config['emailcode']);
  310. $smstemple = '你的验证码';
  311. Vendor('PHPMailer.src.PHPMailer');
  312. Vendor('PHPMailer.src.SMTP');
  313. $mail = new \PHPMailer();
  314. $mail->SMTPDebug = 0;
  315. $mail->isSMTP();
  316. //$mail->CharSet = "utf8";
  317. $mail->Host = "smtp.gmail.com";
  318. $mail->SMTPAuth = true;
  319. $mail->Username = $smsemail; //@qq.com此账号仅供测试使用
  320. $mail->Password = "ojlaqjwjorcitidr";
  321. $mail->SMTPSecure = "ssl";
  322. $mail->Port = 465;
  323. $mail->CharSet = 'UTF-8';
  324. $mail->setFrom($smsemail,"GRAYSCALE Code");
  325. $mail->addAddress($toemail,'');
  326. $mail->addReplyTo($smsemail,"Reply");
  327. $mail->Subject = L('GRAYSCALE Code');
  328. $mail->Body = $smstemple.":".$desc_content;
  329. if(!$mail->send()){
  330. pr($mail->ErrorInfo);
  331. return 0;
  332. }else{
  333. return 1;
  334. }
  335. }
  336. // //邮件发送验证码
  337. // public function emailsend($desc_content, $toemail){
  338. //
  339. // $config = $clist = M("config")->where(array('id'=>1))->field("smsemail,emailcode,smstemple")->find();
  340. // $smsemail = "A1204266633@outlook.com";
  341. // $emailcode = trim($config['emailcode']);
  342. // $smstemple = '你的验证码';
  343. // Vendor('PHPMailer.src.PHPMailer');
  344. // Vendor('PHPMailer.src.SMTP');
  345. // $mail = new \PHPMailer();
  346. // $mail->SMTPDebug = 0;
  347. // $mail->isSMTP();
  348. // //$mail->CharSet = "utf8";
  349. // $mail->Host = "smtp.office365.com";
  350. // $mail->SMTPAuth = true;
  351. // $mail->Username = $smsemail; //@qq.com此账号仅供测试使用
  352. // $mail->Password = "qwer.ooo";
  353. // $mail->SMTPSecure = "TLS";
  354. // $mail->Port = 587;
  355. // $mail->CharSet = 'UTF-8';
  356. // $mail->setFrom($smsemail,"GRAYSCALE Code");
  357. // $mail->addAddress($toemail,'');
  358. // $mail->addReplyTo($smsemail,"Reply");
  359. // $mail->Subject = L('GRAYSCALE Code');
  360. // $mail->Body = $smstemple.":".$desc_content;
  361. // if(!$mail->send()){
  362. // return 0;
  363. // }else{
  364. // return 1;
  365. // }
  366. //
  367. // }
  368. public function loginout()
  369. {
  370. session(null);
  371. $this->ajaxReturn(['code' => 1, 'msg' => '退出成功']);
  372. }
  373. // 找回密码页面
  374. public function findpwd(){
  375. $this->display();
  376. }
  377. // 找回交易密码
  378. public function findpaypwd(){
  379. $this->display();
  380. }
  381. }
  382. ?>