| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 | 
							- <?php
 
- /**
 
-  * @copyright (C)2016-2099 Hnaoyun Inc.
 
-  * @author XingMeng
 
-  * @email hnxsh@foxmail.com
 
-  * @date 2020年06月26日
 
-  *  会员前台控制器
 
-  */
 
- namespace app\home\controller;
 
- use core\basic\Controller;
 
- use app\home\model\MemberModel;
 
- use core\basic\Url;
 
- class MemberController extends Controller
 
- {
 
-     protected $parser;
 
-     protected $model;
 
-     protected $htmldir;
 
-     public function __construct()
 
-     {
 
-         $this->model = new MemberModel();
 
-         $this->parser = new ParserController();
 
-         $this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
 
-     }
 
-     // 会员登录页面
 
-     public function login()
 
-     {
 
-         // 已经登录时跳转到用户中心
 
-         if (session('pboot_uid')) {
 
-             location(Url::home('member/ucenter'));
 
-         }
 
-         
 
-         // 执行登录验证
 
-         if ($_POST) {
 
-             if ($this->config('login_status') === '0') {
 
-                 error('系统已经关闭登录功能,请到后台开启再试!');
 
-             }
 
-             
 
-             // 验证码验证
 
-             $checkcode = strtolower(post('checkcode', 'var'));
 
-             if ($this->config('login_check_code') !== '0') {
 
-                 if (! $checkcode) {
 
-                     alert_back('验证码不能为空!');
 
-                 }
 
-                 
 
-                 if ($checkcode != session('checkcode')) {
 
-                     alert_back('验证码错误!');
 
-                 }
 
-             }
 
-             
 
-             $username = post('username');
 
-             $password = post('password');
 
-             
 
-             if (! $username) {
 
-                 alert_back('用户账号不能为空!');
 
-             }
 
-             
 
-             // 检查用户名
 
-             if (! $this->model->checkUsername("username='$username' or useremail='$username' or usermobile='$username'")) {
 
-                 alert_back('用户账号不存在!');
 
-             }
 
-             
 
-             // 检查密码
 
-             if (! $password) {
 
-                 alert_back('用户密码不能为空!');
 
-             } else {
 
-                 $password = md5(md5($password));
 
-             }
 
-             
 
-             // 登录验证
 
-             if (! ! $login = $this->model->login("(username='$username' or useremail='$username' or usermobile='$username') AND password='$password'")) {
 
-                 if (! $login->status) {
 
-                     alert_back('您的账号待审核,请联系管理员!');
 
-                 }
 
-                 session('pboot_uid', $login->id);
 
-                 session('pboot_ucode', $login->ucode);
 
-                 session('pboot_username', $login->username);
 
-                 session('pboot_useremail', $login->seremail);
 
-                 session('pboot_usermobile', $login->usermobile);
 
-                 session('pboot_gid', $login->gid);
 
-                 session('pboot_gcode', $login->gcode);
 
-                 session('pboot_gname', $login->gname);
 
-                 
 
-                 if (! ! $backurl = get('backurl')) {
 
-                     alert_location('登录成功!', $backurl, 1);
 
-                 } else {
 
-                     alert_location('登录成功!', Url::home('member/ucenter'), 1);
 
-                 }
 
-             } else {
 
-                 alert_back('账号密码错误,请核对后重试!', 0);
 
-             }
 
-         } else {
 
-             $content = parent::parser($this->htmldir . 'member/login.html'); // 框架标签解析
 
-             $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
 
-             $content = str_replace('{pboot:pagetitle}', $this->config('login_title') ?: '会员登录-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
 
-             $content = $this->parser->parserPositionLabel($content, 0, '会员登录', Url::home('member/login')); // CMS当前位置标签解析
 
-             $content = $this->parser->parserSpecialPageSortLabel($content, - 2, '会员登录', Url::home('member/login')); // 解析分类标签
 
-             $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
 
-             echo $content;
 
-             exit();
 
-         }
 
-     }
 
-     // 会员注册页面
 
-     public function register()
 
-     {
 
-         // 已经登录时跳转到用户中心
 
-         if (session('pboot_uid')) {
 
-             location(Url::home('member/ucenter'));
 
-         }
 
-         
 
-         // 执行注册
 
-         if ($_POST) {
 
-             if ($this->config('register_status') === '0') {
 
-                 error('系统已经关闭注册功能,请到后台开启再试!');
 
-             }
 
-             
 
-             if (time() - session('lastreg') < 10) {
 
-                 alert_back('您注册太频繁了,请稍后再试!');
 
-             }
 
-             
 
-             // 验证码验证
 
-             $checkcode = strtolower(post('checkcode', 'var'));
 
-             if ($this->config('register_check_code') !== '0') {
 
-                 if (! $checkcode) {
 
-                     alert_back('验证码不能为空!');
 
-                 }
 
-                 
 
-                 if ($checkcode != session('checkcode')) {
 
-                     alert_back('验证码错误!');
 
-                 }
 
-             }
 
-             
 
-             $ucode = get_auto_code($this->model->getLastUcode(), 1);
 
-             $username = post('username'); // 接受用户名、邮箱、手机三种方式
 
-             $nickname = post('nickname');
 
-             $password = post('password');
 
-             $rpassword = post('rpassword');
 
-             
 
-             $useremail = '';
 
-             $usermobile = '';
 
-             // 注册类型判断
 
-             if ($this->config('register_type') == 2) { // 邮箱注册
 
-                 $useremail = $username;
 
-                 if (! $useremail) {
 
-                     alert_back('账号不能为空,请输入注册的邮箱账号!');
 
-                 }
 
-                 if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
 
-                     alert_back('账号格式不正确,请输入正确的邮箱账号!');
 
-                 }
 
-                 if ($this->model->checkUsername("useremail='$useremail' OR username='$useremail'")) {
 
-                     alert_back('您输入的邮箱已被注册!');
 
-                 }
 
-             } elseif ($this->config('register_type') == 3) { // 手机注册
 
-                 $usermobile = $username;
 
-                 if (! $usermobile) {
 
-                     alert_back('账号不能为空,请输入注册的手机号码!');
 
-                 }
 
-                 if (! preg_match('/^1[0-9]{10}$/', $usermobile)) {
 
-                     alert_back('账号格式不正确,请输入正确的手机号码!');
 
-                 }
 
-                 if ($this->model->checkUsername("usermobile='$usermobile' OR username='$usermobile'")) {
 
-                     alert_back('您输入的手机号码已被注册!');
 
-                 }
 
-             } else { // 账号注册
 
-                 if (! $username) {
 
-                     alert_back('用户名不能为空!');
 
-                 }
 
-                 if (! preg_match('/^[\w\@\.]+$/', $username)) {
 
-                     alert_back('用户账号含有不允许的特殊字符!');
 
-                 }
 
-                 // 检查用户名
 
-                 if ($this->model->checkUsername("username='$username' OR useremail='$username' OR usermobile='$username'")) {
 
-                     alert_back('您输入的账号已被注册!');
 
-                 }
 
-             }
 
-             
 
-             if ($password != $rpassword) {
 
-                 alert_back('确认密码不正确!');
 
-             }
 
-             
 
-             if (! $password) {
 
-                 alert_back('密码不能为空!');
 
-             } else {
 
-                 $password = md5(md5($password));
 
-             }
 
-             
 
-             // 默认值设置
 
-             $status = $this->config('register_verify') ? 0 : 1; // 默认不需要审核
 
-             $score = $this->config('register_score') ?: 0;
 
-             
 
-             $group = $this->model->getFirstGroup();
 
-             $gid = $this->model->getGroupID($this->config('register_gcode')) ?: $group->id;
 
-             
 
-             // 构建数据
 
-             $data = array(
 
-                 'ucode' => $ucode,
 
-                 'username' => $username,
 
-                 'useremail' => $useremail,
 
-                 'usermobile' => $usermobile,
 
-                 'nickname' => $nickname,
 
-                 'password' => $password,
 
-                 'headpic' => '',
 
-                 'status' => $status,
 
-                 'gid' => $gid,
 
-                 'wxid' => '',
 
-                 'qqid' => '',
 
-                 'wbid' => '',
 
-                 'activation' => 1,
 
-                 'score' => $score,
 
-                 'register_time' => get_datetime(),
 
-                 'login_count' => 0,
 
-                 'last_login_ip' => 0,
 
-                 'last_login_time' => 0
 
-             );
 
-             
 
-             // 读取字段
 
-             if (! ! $field = $this->model->getField()) {
 
-                 foreach ($field as $value) {
 
-                     $field_data = post($value->name);
 
-                     if (is_array($field_data)) { // 如果是多选等情况时转换
 
-                         $field_data = implode(',', $field_data);
 
-                     }
 
-                     $field_data = preg_replace_r('pboot:if', '', $field_data);
 
-                     if ($value->required && ! $field_data) {
 
-                         alert_back($value->description . '不能为空!');
 
-                     } else {
 
-                         $data[$value->name] = $field_data;
 
-                     }
 
-                 }
 
-             }
 
-             
 
-             // 执行注册
 
-             if ($this->model->register($data)) {
 
-                 session('lastreg', time()); // 记录最后提交时间
 
-                 if ($status) {
 
-                     alert_location('注册成功!', Url::home('member/login'), 1);
 
-                 } else {
 
-                     alert_location('注册成功,请等待管理员审核!', Url::home('member/login'), 1);
 
-                 }
 
-             } else {
 
-                 error('会员注册失败!', - 1);
 
-             }
 
-         } else {
 
-             $content = parent::parser($this->htmldir . 'member/register.html'); // 框架标签解析
 
-             $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
 
-             $content = str_replace('{pboot:pagetitle}', $this->config('register_title') ?: '会员注册-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
 
-             $content = $this->parser->parserPositionLabel($content, 0, '会员注册', Url::home('member/register')); // CMS当前位置标签解析
 
-             $content = $this->parser->parserSpecialPageSortLabel($content, - 3, '会员注册', Url::home('member/register')); // 解析分类标签
 
-             $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
 
-             echo $content;
 
-             exit();
 
-         }
 
-     }
 
-     //找回密码
 
-     public function retrieve(){
 
-         if($_POST){
 
-             // 验证码验证
 
-             $checkcode = strtolower(post('checkcode', 'var'));
 
-             $email = post('email');
 
-             $username = post('username');
 
-             $password = post('password');
 
-             if (! $checkcode) {
 
-                 alert_back('验证码不能为空!');
 
-             }
 
-             if ($checkcode != session('checkcode')) {
 
-                 alert_back('验证码错误!');
 
-             }
 
-             $where = ['username' => $username];
 
-             $userInfo = object_to_array($this->model->checkUsername($where));
 
-             if(!$userInfo){
 
-                 alert_back('该用户不存在!');
 
-             }
 
-             if(!empty($userInfo['useremail']) && $userInfo['useremail'] != $email){
 
-                 alert_back('与注册邮箱不匹配,请联系管理员!');
 
-             }
 
-             $data = [
 
-                 'useremail' => $email,
 
-                 'password' => md5(md5($password))
 
-             ];
 
-             $this->model->updatePassword($where,$data);
 
-             alert_location('修改成功!', Url::home('member/login'), 1);
 
-         } else {
 
-             $content = parent::parser($this->htmldir . 'member/retrieve.html'); // 框架标签解析
 
-             $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
 
-             $content = str_replace('{pboot:pagetitle}', $this->config('register_title') ?: '找回密码-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
 
-             $content = $this->parser->parserPositionLabel($content, 0, '找回密码', Url::home('member/retrieve')); // CMS当前位置标签解析
 
-             $content = $this->parser->parserSpecialPageSortLabel($content, - 3, '找回密码', Url::home('member/retrieve')); // 解析分类标签
 
-             $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
 
-             echo $content;
 
-             exit();
 
-         }
 
-     }
 
-     // 用户中心
 
-     public function ucenter()
 
-     {
 
-         // 未登录时跳转到用户登录
 
-         if (! session('pboot_uid')) {
 
-             location(Url::home('member/login'));
 
-         }
 
-         
 
-         $content = parent::parser($this->htmldir . 'member/ucenter.html'); // 框架标签解析
 
-         $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
 
-         $content = str_replace('{pboot:pagetitle}', $this->config('ucenter_title') ?: '个人中心-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
 
-         $content = $this->parser->parserPositionLabel($content, 0, '个人中心', Url::home('member/ucenter')); // CMS当前位置标签解析
 
-         $content = $this->parser->parserSpecialPageSortLabel($content, - 4, '个人中心', Url::home('member/ucenter')); // 解析分类标签
 
-         $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
 
-         echo $content;
 
-         exit();
 
-     }
 
-     // 用户修改
 
-     public function umodify()
 
-     {
 
-         // 未登录时跳转到用户登录
 
-         if (! session('pboot_uid')) {
 
-             location(Url::home('member/login'));
 
-         }
 
-         
 
-         // 执行资料修改
 
-         if ($_POST && session('pboot_uid')) {
 
-             $nickname = post('nickname');
 
-             $useremail = post('useremail');
 
-             $usermobile = post('usermobile');
 
-             $opassword = post('opassword');
 
-             $password = post('password');
 
-             $rpassword = post('rpassword');
 
-             $headpic = str_replace(SITE_DIR, '', post('headpic'));
 
-             
 
-             if (! $opassword) {
 
-                 alert_back('请输入当前密码!');
 
-             } else {
 
-                 if (! $this->model->checkUsername(" password='" . md5(md5($opassword)) . "' AND id='" . session('pboot_uid') . "'")) {
 
-                     alert_back('您输入的当前密码不正确!');
 
-                 }
 
-             }
 
-             
 
-             if ($useremail) { // 邮箱校验
 
-                 if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
 
-                     alert_back('邮箱格式不正确,请输入正确的邮箱账号!');
 
-                 }
 
-                 if ($this->model->checkUsername("(useremail='$useremail' OR username='$useremail') AND id<>'" . session('pboot_uid') . "'")) {
 
-                     alert_back('您输入的邮箱已被注册!');
 
-                 }
 
-             }
 
-             
 
-             if ($usermobile) { // 手机检验
 
-                 if (! preg_match('/^1[0-9]{10}$/', $usermobile)) {
 
-                     alert_back('手机格式不正确,请输入正确的手机号码!');
 
-                 }
 
-                 if ($this->model->checkUsername("(usermobile='$usermobile' OR username='$usermobile') AND id<>'" . session('pboot_uid') . "'")) {
 
-                     alert_back('您输入的手机号码已被注册!');
 
-                 }
 
-             }
 
-             
 
-             // 构建数据
 
-             $data = array(
 
-                 'nickname' => $nickname,
 
-                 'useremail' => $useremail,
 
-                 'usermobile' => $usermobile,
 
-                 'headpic' => $headpic
 
-             );
 
-             
 
-             // 密码修改
 
-             if ($password) {
 
-                 if ($password != $rpassword) {
 
-                     alert_back('确认密码不正确!');
 
-                 } else {
 
-                     $data['password'] = md5(md5($password));
 
-                 }
 
-             }
 
-             
 
-             // 读取字段
 
-             if (! ! $field = $this->model->getField()) {
 
-                 foreach ($field as $value) {
 
-                     $field_data = post($value->name);
 
-                     if (is_array($field_data)) { // 如果是多选等情况时转换
 
-                         $field_data = implode(',', $field_data);
 
-                     }
 
-                     $field_data = preg_replace_r('pboot:if', '', $field_data);
 
-                     if ($value->required && ! $field_data) {
 
-                         alert_back($value->description . '不能为空!');
 
-                     } else {
 
-                         $data[$value->name] = $field_data;
 
-                     }
 
-                 }
 
-             }
 
-             
 
-             // 不允许修改的字段
 
-             unset($data['id']);
 
-             unset($data['ucode']);
 
-             unset($data['username']);
 
-             unset($data['status']);
 
-             unset($data['gid']);
 
-             unset($data['wxid']);
 
-             unset($data['qqid']);
 
-             unset($data['wbid']);
 
-             unset($data['score']);
 
-             unset($data['register_time']);
 
-             unset($data['login_count']);
 
-             unset($data['last_login_ip']);
 
-             unset($data['last_login_time']);
 
-             
 
-             // 执行修改
 
-             if ($this->model->modUser($data)) {
 
-                 alert_location('修改成功!', Url::home('member/umodify'), 1);
 
-             } else {
 
-                 error('资料修改失败!', - 1);
 
-             }
 
-         } else {
 
-             $content = parent::parser($this->htmldir . 'member/umodify.html'); // 框架标签解析
 
-             $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
 
-             $content = str_replace('{pboot:pagetitle}', $this->config('umodify_title') ?: '资料修改-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
 
-             $content = $this->parser->parserPositionLabel($content, 0, '资料修改', Url::home('member/umodify')); // CMS当前位置标签解析
 
-             $content = $this->parser->parserSpecialPageSortLabel($content, - 5, '资料修改', Url::home('member/umodify')); // 解析分类标签
 
-             $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
 
-             echo $content;
 
-             exit();
 
-         }
 
-     }
 
-     // 退出登录
 
-     public function logout()
 
-     {
 
-         session('pboot_uid', '');
 
-         session('pboot_ucode', '');
 
-         session('pboot_username', '');
 
-         session('pboot_useremail', '');
 
-         session('pboot_usermobile', '');
 
-         session('pboot_gid', '');
 
-         session('pboot_gcode', '');
 
-         session('pboot_gname', '');
 
-         location(Url::home('member/login'));
 
-     }
 
-     // 文件上传方法(Ajax)
 
-     public function upload()
 
-     {
 
-         // 必须登录
 
-         if (! session('pboot_uid')) {
 
-             json(0, '请先登录!');
 
-         }
 
-         
 
-         $ext = $this->config('home_upload_ext') ?: "jpg,jpeg,png,gif,xls,xlsx,doc,docx,ppt,pptx,rar,zip,pdf,txt";
 
-         $upload = upload('upload', $ext);
 
-         if (is_array($upload)) {
 
-             json(1, $upload);
 
-         } else {
 
-             json(0, $upload);
 
-         }
 
-     }
 
-     // 发送邮件
 
-     public function sendEmail()
 
-     {
 
-         $retrieve = post('retrieve');
 
-         //$retrieve存在时为找回密码邮箱验证,不进行验证码模式判断
 
-         if(!$retrieve){
 
-             if ($this->config('register_check_code') != 2) {
 
-                 json(0, '发送失败,后台配置非邮箱验证码模式!');
 
-             }
 
-         }
 
-         if (time() - session('lastsend') < 10) {
 
-             json(0, '您提交太频繁了,请稍后再试!');
 
-         }
 
-         
 
-         if (! session('sendemail')) {
 
-             json(0, '非法提交发送邮件!');
 
-         }
 
-         
 
-         // 发送邮箱参数
 
-         if (! ! $to = post('to')) {
 
-             if (! preg_match('/^[\w]+@[\w]+\.[a-zA-Z]+$/', $to)) {
 
-                 json(0, '邮箱格式不正确,请输入正确的邮箱账号!');
 
-             }
 
-         } else {
 
-             json(0, '发送失败,缺少发送对象参数to!');
 
-         }
 
-         
 
-         // 检查邮箱注册
 
-         if(!$retrieve) {
 
-             if ($this->model->checkUsername("useremail='$to' OR username='$to'")) {
 
-                 alert_back('您输入的邮箱已被注册!');
 
-             }
 
-         }
 
-         
 
-         $rs = false;
 
-         if ($to) {
 
-             session('lastsend', time()); // 记录最后提交时间
 
-             $mail_subject = "【" . CMSNAME . "】您有新的验证码信息,请注意查收!";
 
-             $code = create_code(4);
 
-             session('checkcode', strtolower($code));
 
-             $mail_body = "您的验证码为:" . $code;
 
-             $mail_body .= '<br>来自网站 ' . get_http_url() . ' (' . date('Y-m-d H:i:s') . ')';
 
-             $rs = sendmail($this->config(), $to, $mail_subject, $mail_body);
 
-         }
 
-         if ($rs === true) {
 
-             json(1, '发送成功!');
 
-         } else {
 
-             json(0, '发送失败,' . $rs);
 
-         }
 
-     }
 
-     // 检查用户是否注册
 
-     public function isRegister()
 
-     {
 
-         // 接受用户名、邮箱、手机三种方式
 
-         $info = '';
 
-         if (! $username = post('username')) {
 
-             $err = '账号不能为空!';
 
-         }
 
-         
 
-         // 注册类型判断
 
-         if ($this->config('register_type') == 2) { // 邮箱注册
 
-             if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $username)) {
 
-                 $err = '账号格式不正确,请输入正确的邮箱账号!';
 
-             }
 
-             if ($this->model->checkUsername("useremail='$username' OR username='$username'")) {
 
-                 $err = '您输入的邮箱已被注册!';
 
-             } else {
 
-                 $suc = '您输入的邮箱可以使用!';
 
-             }
 
-         } elseif ($this->config('register_type') == 3) { // 手机注册
 
-             if (! preg_match('/^1[0-9]{10}$/', $username)) {
 
-                 $err = '账号格式不正确,请输入正确的手机号码!';
 
-             }
 
-             if ($this->model->checkUsername("usermobile='$username' OR username='$username'")) {
 
-                 $err = '您输入的手机号码已被注册!';
 
-             } else {
 
-                 $suc = '您输入的手机号码可以使用!';
 
-             }
 
-         } else { // 账号注册
 
-             if (! preg_match('/^[\w\@\.]+$/', $username)) {
 
-                 $err = '用户账号含有不允许的特殊字符!';
 
-             }
 
-             // 检查用户名
 
-             if ($this->model->checkUsername("username='$username' OR useremail='$username' OR usermobile='$username'")) {
 
-                 $err = '您输入的账号已被注册!';
 
-             } else {
 
-                 $suc = '您输入的账号可以使用!';
 
-             }
 
-         }
 
-         
 
-         if ($err) {
 
-             json(1, $err);
 
-         } else {
 
-             json(0, $suc);
 
-         }
 
-     }
 
-     public function _empty()
 
-     {
 
-         _404('您访问的地址不存在,请核对再试!');
 
-     }
 
- }
 
 
  |