| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- <?php
- namespace Home\Controller;
- class LoginController extends HomeController
- {
- protected function _initialize()
- {
- parent::_initialize(); $allow_action=array("index","register","upregister","loginsubmit","loginout","findpwd","findpaypwd","webreg","loption","setlang","lhelp","sendcode","findsendcode","resetpwd");
- if(!in_array(ACTION_NAME,$allow_action)){
- $this->error(L("非法操作"));
- }
- }
-
-
- //未登陆状态的选项页面
- public function loption(){
- $this->display();
- }
- //未登陆状态的设置语言
- public function setlang(){
- $this->display();
- }
- //帮助中心
- public function lhelp(){
- $uid = userid();
- $this->assign('uid',$uid);
- $this->display();
- }
-
- // 用户协议
- public function webreg()
- {
- $this->display();
- }
-
- public function index()
- {
- $uid = userid();
- if($uid >= 1){
- $this->redirect("Index/index");
- }
- $this->display();
- }
- //注册页面
- public function register(){
- $qrcode = I("get.qr");
- if($qrcode != ''){
- $this->assign('qrcode',$qrcode);
- }
- $this->display();
- }
- //提交重置密码
- public function resetpwd($email=null,$ecode=null,$lpwd=null){
- // if (checkstr($email) || checkstr($lpwd) || checkstr($ecode)) {
- // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
- // }
- if($email == ''){
- $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
- }
- if($ecode == ''){
- $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱验证码')]);
- }
- if($lpwd == ''){
- $this->ajaxReturn(['code'=>0,'info'=>L('请输入密码')]);
- }
- $findcode = session("findcode");
- if($findcode != $ecode){
- $this->ajaxReturn(['code'=>0,'info'=>L('邮箱验证码错误')]);
- }
-
- $uinfo = M("user")->where(array('username'=>$email))->field("id,username")->find();
- if(empty($uinfo)){
- $this->ajaxReturn(['code'=>0,'info'=>L('邮箱未注册')]);
- }
-
- $password = md5($lpwd);
- $result = M("user")->where(array('username'=>$email))->save(array('password'=>$password));
- if($result){
- $data['uid'] = $uinfo['id'];
- $data['account'] = $uinfo['username'];
- $data['title'] = L('重置密码');
- $data['content'] = L('登陆密码重置成功');
- $data['addtime'] = date("Y-m-d H:i:s",time());
- $data['status'] = 1;
- M("notice")->add($data);
- $this->ajaxReturn(['code'=>1,'info'=>L('登陆密码重置成功')]);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>L('密码重置失败')]);
- }
-
- }
- // 登录提交处理
- public function loginsubmit($email=null,$lpwd=null,$vcode=null){
- // if (checkstr($email) || checkstr($lpwd) || checkstr($vcode)) {
- // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
- // }
-
-
- if (!check_verify(strtoupper($vcode),'1')) {
- $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误!')]);
- }
-
- $user = M('User')->where(array('username' => $email))->find();
-
- if(empty($user)){
- $phone = M('User')->where(array('phone' => $email))->find();
- $user['id'] = $phone['id'];
- if(empty($phone)){
- $this->ajaxReturn(['code'=>0,'info'=> L('用户不存在')]);
- }
- }
- if (md5($lpwd) != $user['password']){
- if (md5($lpwd) != $phone['password']){
- $this->ajaxReturn(['code'=>0,'info'=> L('登录密码错误')]);
- }
- }
- if (isset($phone['status']) && $phone['status'] != 1) {
- if (isset($user['status']) && $user['status'] != 1) {
- $this->ajaxReturn(['code'=>0,'info'=> L('你的账号已冻结请联系管理员')]);
- }
- }
-
- //增加登陆次数
- $incre = M("user")->where(array('id' => $user['id']))->setInc('logins', 1);
-
- //新增登陆记录
- $data['userid'] = $user['id'];
- $data['type'] = L('登录');
- $data['remark'] = L('邮箱登录');
- $data['addtime'] = time();
- $data['addip'] = get_client_ip();
- $data['addr'] = get_city_ip();
- $data['status'] = 1;
- $dre = M("user_log")->add($data);
-
- if($incre && $dre){
- $lgdata['lgtime'] = date("Y-m-d",time());
- M("user")->where(array('id' => $user['id']))->save($lgdata);
- session('userId', $user['id']);
- session('userName', $user['username']);
- $this->ajaxReturn(['code'=>1,'info'=>L('登录成功')]);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>L('登录失败')]);
- }
- }
- //注册处理程序
- public function upregister($email,$lpwd,$invit,$yincang = 1,$ecode){
- if($_POST){
- if ($ecode != session('regcode')) $this->ajaxReturn(['code'=>0,'info'=>L('邮箱验证码错误')]);
- if(!$email) $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
-
- if($yincang == 1){
- $checkus = M('User')->where(array('username' => $email))->find();
- if(!empty($checkus)){
- $this->ajaxReturn(['code'=>0,'info'=>L('账户已存在')]);
- }
- }else{
- // $phones = M('User')->where(array('phone' => $phone))->find();
- // if(!empty($phones)){
- // $this->ajaxReturn(['code'=>0,'info'=>L('手机号已存在')]);
- // }
- }
- if($lpwd == ''){
- $this->ajaxReturn(['code'=>0,'info'=>L('请输入密码')]);
- }
- $config = M("config")->where(array('id'=>1))->field("tymoney")->find();
- if($invit != 0 || $invit != ''){
- $inv_user = M('User')->where(array('invit' => $invit))->field("id,username,invit_1,invit_2,path")->find();
- if(empty($inv_user)){
- $this->ajaxReturn(['code'=>0,'info'=>L('推荐人不存在')]);
- }
- $invit_1 = $inv_user['id'];
- $invit_2 = $inv_user['invit_1'];
- $invit_3 = $inv_user['invit_2'];
- $path = $inv_user['path'].','.$inv_user['id'];
- }else{
- $invit_1 = 0;
- $invit_2 = 0;
- $invit_3 = 0;
- $path = '';
- }
- for (; true; ) {
- $myinvit = tradenoa();
- if (!M('User')->where(array('invit' => $myinvit))->find()) {
- break;
- }
- }
- $mo = M();
- $mo->execute('set autocommit=0');
- $mo->execute('lock tables tw_user write , tw_user_coin write ');
- $rs = array();
- if($yincang == 2){
- $rs[] = $mo->table('tw_user')->add(
- array(
- 'username' => '',
- 'password' => md5($lpwd),
- 'money' => $config['tymoney'],
- 'invit' => $myinvit,
- 'invit_1' => $invit_1,
- 'invit_2' => $invit_2,
- 'invit_3' => $invit_3,
- 'path'=>$path,
- 'addip' => get_client_ip(),
- 'addr' => get_city_ip(),
- 'addtime' => time(),
- 'status' => 1,
- 'txstate' => 1,
- 'phone' => ''
- ));
- }else{
- $rs[] = $mo->table('tw_user')->add(
- array(
- 'username' => $email,
- 'password' => md5($lpwd),
- 'money' => $config['tymoney'],
- 'invit' => $myinvit,
- 'invit_1' => $invit_1,
- 'invit_2' => $invit_2,
- 'invit_3' => $invit_3,
- 'path'=>$path,
- 'addip' => get_client_ip(),
- 'addr' => get_city_ip(),
- 'addtime' => time(),
- 'status' => 1,
- 'txstate' => 1,
- ));
- }
- $user_coin = array('userid' => $rs[0]);
- // 创建用户数字资产档案
- $rs[] = $mo->table('tw_user_coin')->add($user_coin);
- if (check_arr($rs)) {
- $mo->execute('commit');
- $mo->execute('unlock tables');
- session('regcode', null); //初始化动态验证码
- $user = $mo->table('tw_user')->where(array('id'=>$rs[0]))->find();
- $this->ajaxReturn(['code'=>1,'info'=>L('注册成功')]);
- } else {
- $mo->execute('rollback');
- $this->ajaxReturn(['code'=>0,'info'=>L('注册失败')]);
- }
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>L('网络错误')]);
- }
- }
- public function findsendcode($email,$vcode){
- // if(checkstr($email) || checkstr($vcode)) {
- // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
- // }
- $email = I('post.email');
- $vcode = I('post.vcode');
- if (!check_verify(strtoupper($vcode),'1')) {
- $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误')]);
- }
- if($email == ''){
- $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
- }
- $uinfo = M("user")->where(array('username'=>$email))->find();
- if(empty($uinfo)){
- $this->ajaxReturn(['code'=>0,'info'=>L('邮箱未注册')]);
- }
- $code = rand(10000,99999);
- $result = $this->emailsend($code,$email);
- if($result){
- session('findcode',$code);
- $this->ajaxReturn(['code'=>1,'info'=>L('验证码发送成功')]);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>L('验证码发送失败')]);
- }
- }
- //邮箱发送验证码
- public function sendcode($email,$vcode){
- if($_POST){
- // if(checkstr($email) || checkstr($vcode)) {
- // $this->ajaxReturn(['code'=>0,'info'=>L('您输入的信息有误')]);
- // }
- $email = I('post.email');
- $vcode = I('post.vcode');
- if (!check_verify(strtoupper($vcode),'1')) {
- $this->ajaxReturn(['code'=>0,'info'=>L('图形验证码错误')]);
- }
- if($email == ''){
- $this->ajaxReturn(['code'=>0,'info'=>L('请输入邮箱')]);
- }
- $uinfo = M("user")->where(array('username'=>$email))->find();
- if(!empty($uinfo)){
- $this->ajaxReturn(['code'=>0,'info'=>L('账号已存在')]);
- }
- $code = rand(10000,99999);
- $result = $this->emailsend($code,$email);
- if($result){
- session('regcode',$code);
- $this->ajaxReturn(['code'=>1,'info'=>L('验证码发送成功')]);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>L('验证码发送失败')]);
- }
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>L('网络错误')]);
- }
-
- }
- //邮件发送验证码
- public function emailsend($desc_content, $toemail){
- $config = $clist = M("config")->where(array('id'=>1))->field("smsemail,emailcode,smstemple")->find();
- $smsemail = "fj2568204@gmail.com";
- $emailcode = trim($config['emailcode']);
- $smstemple = '你的验证码';
- Vendor('PHPMailer.src.PHPMailer');
- Vendor('PHPMailer.src.SMTP');
- $mail = new \PHPMailer();
- $mail->SMTPDebug = 0;
- $mail->isSMTP();
- //$mail->CharSet = "utf8";
- $mail->Host = "smtp.gmail.com";
- $mail->SMTPAuth = true;
- $mail->Username = $smsemail; //@qq.com此账号仅供测试使用
- $mail->Password = "pfendaslmimputxh";
- $mail->SMTPSecure = "ssl";
- $mail->Port = 465;
- $mail->CharSet = 'UTF-8';
- $mail->setFrom($smsemail,"Verification Code");
- $mail->addAddress($toemail,'');
- $mail->addReplyTo($smsemail,"Reply");
- $mail->Subject = L('Verification Code');
- $mail->Body = $smstemple.":".$desc_content;
- if(!$mail->send()){
- return 0;
- }else{
- return 1;
- }
-
- }
- public function loginout()
- {
- session(null);
- redirect('/');
- }
-
- // 找回密码页面
- public function findpwd(){
- $this->display();
- }
- // 找回交易密码
- public function findpaypwd(){
- $this->display();
- }
- }
- ?>
|