LoginController.class.php 14 KB

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