123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Membersecurity extends BaseMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberpoints.lang.php');
- }
- public function index()
- {
- $member_info = $this->member_info;
- $member_info['security_level'] = model('member')->getMemberSecurityLevel($member_info);
- View::assign('member_info', $member_info);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_security');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem('index');
- return View::fetch($this->template_dir . 'index');
- }
- /**
- * 绑定邮箱 - 发送邮件
- */
- public function send_bind_email()
- {
- $email = input('param.email');
- $membersecurity_validate = ds_validate('membersecurity');
- if (!$membersecurity_validate->scene('send_bind_email')->check(array('email' => $email))) {
- ds_json_encode(10001, $membersecurity_validate->getError());
- }
- $member_model = model('member');
- $condition = array();
- $condition[] = array('member_email', '=', $email);
- $condition[] = array('member_id', '<>', session('member_id'));
- $member_info = $member_model->getMemberInfo($condition, 'member_id');
- if ($member_info) {
- ds_json_encode(10001, lang('mailbox_has_been_used'));
- }
- //验证发送频率
- $verify_code_model = model('verify_code');
- $result = $verify_code_model->isVerifyCodeFrequant(5, 1);
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- }
- $verify_code = $verify_code_model->genVerifyCode(5, 1);
- if (!$verify_code) {
- ds_json_encode(10001, lang('system_error'));
- }
- $uid = base64_encode(ds_encrypt(session('member_id') . ' ' . $email));
- $verify_url = HOME_SITE_URL . '/Login/bind_email.html?uid=' . $uid . '&hash=' . md5($verify_code);
- $mailtemplates_model = model('mailtemplates');
- $tpl_info = $mailtemplates_model->getTplInfo(array('mailmt_code' => 'bind_email'));
- $param = array();
- $param['site_name'] = config('ds_config.site_name');
- $param['user_name'] = session('member_name');
- $param['verify_url'] = $verify_url;
- $subject = ds_replace_text($tpl_info['mailmt_title'], $param);
- $message = ds_replace_text($tpl_info['mailmt_content'], $param);
- $message = htmlspecialchars_decode($message);
- $ob_email = new \sendmsg\Email();
- $result = $ob_email->send_sys_email($email, $subject, $message);
- if ($result) {
- $ip = request()->ip();
- $flag = $verify_code_model->addVerifyCode(array(
- 'verify_code_type' => 5,
- 'verify_code' => $verify_code,
- 'verify_code_user_type' => 1,
- 'verify_code_user_id' => session('member_id'),
- 'verify_code_user_name' => session('member_name'),
- 'verify_code_add_time' => TIMESTAMP,
- 'verify_code_ip' => $ip,
- ));
- if (!$flag) {
- ds_json_encode(10001, lang('system_error'));
- }
- $data = array();
- $data['member_email'] = $email;
- $data['member_emailbind'] = 0;
- $member_model->editMember(array('member_id' => session('member_id')), $data, session('member_id'));
- ds_json_encode(10000, lang('verify_mail_been_sent_mailbox'));
- } else {
- ds_json_encode(10001, lang('system_error'));
- }
- }
- public function auth()
- {
- $member_model = model('member');
- $type = input('param.type');
- if (!request()->isPost()) {
- if (!in_array($type, array('modify_pwd', 'modify_mobile', 'modify_email', 'modify_paypwd', 'pd_cash'))) {
- $this->redirect('Membersecurity/index');
- }
- //继承父类的member_info
- $member_info = $this->member_info;
- if (!$member_info) {
- $member_info = $member_model->getMemberInfo(array('member_id' => session('member_id')), 'member_email,member_emailbind,member_mobile,member_mobilebind');
- }
- //第一次绑定邮箱,不用发验证码,直接进下一步
- //第一次绑定手机,不用发验证码,直接进下一步
- if (($type == 'modify_email' && $member_info['member_emailbind'] == '0') || ($type == 'modify_mobile' && $member_info['member_mobilebind'] == '0')) {
- session('auth_' . $type, TIMESTAMP);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_security');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem($type);
- echo View::fetch($this->template_dir . $type);
- exit;
- }
- //修改密码、设置支付密码时,必须绑定邮箱或手机
- if (in_array($type, array('modify_pwd', 'modify_paypwd')) && $member_info['member_emailbind'] == '0' && $member_info['member_mobilebind'] == '0') {
- $this->error(lang('please_bind_email_phone_first'), 'membersecurity/index');
- }
- View::assign('member_info', $member_info);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_security');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem($type);
- return View::fetch($this->template_dir . 'auth');
- } else {
- if (!in_array($type, array('modify_pwd', 'modify_mobile', 'modify_email', 'modify_paypwd', 'pd_cash'))) {
- $this->redirect((string)url('Membersecurity/index'));
- }
- $verify_code = input('post.auth_code');
- $validate_data = array(
- 'verify_code' => $verify_code,
- );
- $verify_code_validate = ds_validate('verify_code');
- if (!$verify_code_validate->scene('verify_code_search')->check($validate_data)) {
- $this->error($verify_code_validate->getError());
- }
- $verify_code_model = model('verify_code');
- if (!$verify_code_model->getVerifyCodeInfo(array(array('verify_code_type', '=', 6), array('verify_code_user_type', '=', 1), array('verify_code_user_id', '=', session('member_id')), array('verify_code', '=', $verify_code), array('verify_code_add_time', '>', TIMESTAMP - VERIFY_CODE_INVALIDE_MINUTE * 60)))) {
- $this->error(lang('validation_fails'));
- }
- //当类型为提现 获取用户绑定的银行卡账户列表
- if ($type == 'pd_cash') {
- $memberbank_list = model('memberbank')->getMemberbankList(array('member_id' => session('member_id')));
- $member_wxinfo = unserialize($this->member_info['member_wxinfo']);
- if (!empty($member_wxinfo) && is_array($member_wxinfo) && isset($member_wxinfo['member_wxopenid']) && $member_wxinfo['member_wxopenid']) {
- if (empty($memberbank_list)) {
- $memberbank_list = array();
- }
- $memberbank_list[] = array('memberbank_id' => -1, 'memberbank_type' => 'weixin', 'memberbank_no' => $member_wxinfo['nickname'], 'member_wxinfo' => $member_wxinfo);
- }
- View::assign('memberbank_list', $memberbank_list);
- }
- session('auth_' . $type, TIMESTAMP);
- /* 设置买家当前菜单 */
- $this->setMemberCurMenu('member_security');
- /* 设置买家当前栏目 */
- $this->setMemberCurItem($type);
- return View::fetch($this->template_dir . $type);
- }
- }
- /**
- * 统一发送身份验证码
- */
- public function send_auth_code()
- {
- $type = input('param.type');
- if (!in_array($type, array('email', 'mobile')))
- exit();
- $member_model = model('member');
- $member_info = $member_model->getMemberInfoByID(session('member_id'));
- //验证发送频率
- $verify_code_model = model('verify_code');
- $result = $verify_code_model->isVerifyCodeFrequant(6, 1);
- if (!$result['code']) {
- exit(json_encode(array('state' => 'false', 'msg' => $result['msg'])));
- }
- $verify_code = $verify_code_model->genVerifyCode(6, 1);
- if (!$verify_code) {
- exit(json_encode(array('state' => 'false', 'msg' => lang('system_error'))));
- }
- $mailtemplates_model = model('mailtemplates');
- $tpl_info = $mailtemplates_model->getTplInfo(array('mailmt_code' => 'authenticate'));
- $param = array();
- $param['code'] = $verify_code;
- $ten_param = array($verify_code);
- $subject = ds_replace_text($tpl_info['mailmt_title'], $param);
- $message = ds_replace_text($tpl_info['mailmt_content'], $param);
- if ($type == 'email') {
- $email = new \sendmsg\Email();
- $result['state'] = $email->send_sys_email($member_info["member_email"], $subject, $message);
- } elseif ($type == 'mobile') {
- $smslog_param = array(
- 'ali_template_code' => $tpl_info['ali_template_code'],
- 'ali_template_param' => $param,
- 'ten_template_code' => $tpl_info['ten_template_code'],
- 'ten_template_param' => $ten_param,
- 'message' => $message,
- );
- $result = model('smslog')->sendSms($member_info["member_mobile"], $smslog_param, 5, $verify_code);
- }
- if ($result['state']) {
- $ip = request()->ip();
- $flag = $verify_code_model->addVerifyCode(array(
- 'verify_code_type' => 6,
- 'verify_code' => $verify_code,
- 'verify_code_user_type' => 1,
- 'verify_code_user_id' => session('member_id'),
- 'verify_code_user_name' => session('member_name'),
- 'verify_code_add_time' => TIMESTAMP,
- 'verify_code_ip' => $ip,
- ));
- if (!$flag) {
- exit(json_encode(array('state' => 'false', 'msg' => lang('system_error'))));
- }
- exit(json_encode(array('state' => 'true', 'msg' => lang('verification_code_has_been_sent'))));
- } else {
- exit(json_encode(array('state' => 'false', 'msg' => isset($result['message']) ? $result['message'] : lang('verification_code_sending_failed'))));
- }
- }
- /**
- * 修改密码
- */
- public function modify_pwd()
- {
- $member_model = model('member');
- //身份验证后,需要在30分钟内完成修改密码操作
- if (TIMESTAMP - session('auth_modify_pwd') > 1800) {
- ds_json_encode(10001, lang('operation_timed_out'));
- }
- if (!request()->isPost()) {
- exit();
- }
- $data = array(
- 'password' => input('post.password'),
- 'confirm_password' => input('post.confirm_password'),
- );
- $membersecurity_validate = ds_validate('membersecurity');
- if (!$membersecurity_validate->scene('modify_pwd')->check($data)) {
- ds_json_encode(10001, $membersecurity_validate->getError());
- }
- if ($data['password'] != $data['confirm_password']) {
- ds_json_encode(10001, lang('two_password_inconsistencies'));
- }
- //判断当前的密码是否和原密码相同
- $member_info = $member_model->getMemberInfo(array('member_id' => session('member_id')));
- if ($member_info['member_password'] == md5($data['password'])) {
- ds_json_encode(10001, lang('new_password_same'));
- }
- $update = $member_model->editMember(array('member_id' => session('member_id')), array('member_password' => md5($data['password'])), session('member_id'));
- $message = $update ? lang('password_modify_successfully') : 'operation_timed_out';
- session('auth_modify_pwd', NULL);
- if ($update) {
- ds_json_encode(10000, $message);
- } else {
- ds_json_encode(10001, $message);
- }
- }
- /**
- * 设置支付密码
- */
- public function modify_paypwd()
- {
- $member_model = model('member');
- //身份验证后,需要在30分钟内完成修改密码操作
- if (TIMESTAMP - session('auth_modify_paypwd') > 1800) {
- $this->error(lang('operation_timed_out'), (string)url('Membersecurity/auth', ['type' => 'modify_paypwd']));
- }
- if (!request()->isPost())
- exit();
- $data = array(
- 'password' => input('post.password'),
- 'confirm_password' => input('post.confirm_password'),
- );
- $membersecurity_validate = ds_validate('membersecurity');
- if (!$membersecurity_validate->scene('modify_paypwd')->check($data)) {
- ds_json_encode(10001, $membersecurity_validate->getError());
- }
- if ($data['password'] != $data['confirm_password']) {
- ds_json_encode(10001, lang('two_password_inconsistencies'));
- }
- $update = $member_model->editMember(array('member_id' => session('member_id')), array('member_paypwd' => md5($data['password'])), session('member_id'));
- $message = $update ? lang('password_set_successfully') : lang('password_setting_failed');
- session('auth_modify_paypwd', NULL);
- if ($update) {
- ds_json_encode(10000, $message);
- } else {
- ds_json_encode(10001, $message);
- }
- }
- /**
- * 绑定手机
- */
- public function modify_mobile()
- {
- $member_model = model('member');
- $member_model->getMemberInfoByID(session('member_id'));
- if (request()->isPost()) {
- $data = array(
- 'mobile' => input('post.mobile'),
- 'vcode' => input('post.vcode'),
- );
- $membersecurity_validate = ds_validate('membersecurity');
- if (!$membersecurity_validate->scene('modify_mobile')->check($data)) {
- ds_json_encode(10001, $membersecurity_validate->getError());
- }
- $verify_code = input('post.vcode');
- $validate_data = array(
- 'verify_code' => $verify_code,
- );
- $verify_code_validate = ds_validate('verify_code');
- if (!$verify_code_validate->scene('verify_code_search')->check($validate_data)) {
- ds_json_encode(10001, $verify_code_validate->getError());
- }
- $verify_code_model = model('verify_code');
- if (!$verify_code_model->getVerifyCodeInfo(array(array('verify_code_type', '=', 4), array('verify_code_user_type', '=', 1), array('verify_code_user_id', '=', session('member_id')), array('verify_code', '=', $verify_code), array('verify_code_add_time', '>', TIMESTAMP - VERIFY_CODE_INVALIDE_MINUTE * 60)))) {
- ds_json_encode(10001, lang('mobile_verification_code_error'));
- }
- $member_model->editMember(array('member_id' => session('member_id')), array('member_mobilebind' => 1), session('member_id'));
- ds_json_encode(10000, lang('phone_number_bound_successfully'));
- }
- }
- /**
- * 修改手机号 - 发送验证码
- */
- public function send_modify_mobile()
- {
- $mobile = input('param.mobile');
- $membersecurity_validate = ds_validate('membersecurity');
- if (!$membersecurity_validate->scene('send_modify_mobile')->check(array('mobile' => $mobile))) {
- exit(json_encode(array('state' => 'false', 'msg' => $membersecurity_validate->getError())));
- }
- $member_model = model('member');
- $condition = array();
- $condition[] = array('member_mobile', '=', $mobile);
- $condition[] = array('member_id', '<>', session('member_id'));
- $member_info = $member_model->getMemberInfo($condition, 'member_id');
- if ($member_info) {
- exit(json_encode(array('state' => 'false', 'msg' => lang('please_change_another_phone_number'))));
- }
- //验证发送频率
- $verify_code_model = model('verify_code');
- $result = $verify_code_model->isVerifyCodeFrequant(4, 1);
- if (!$result['code']) {
- exit(json_encode(array('state' => 'false', 'msg' => $result['msg'])));
- }
- $verify_code = $verify_code_model->genVerifyCode(4, 1);
- if (!$verify_code) {
- exit(json_encode(array('state' => 'false', 'msg' => lang('system_error'))));
- }
- $mailtemplates_model = model('mailtemplates');
- $tpl_info = $mailtemplates_model->getTplInfo(array('mailmt_code' => 'modify_mobile'));
- $param = array();
- $param['code'] = $verify_code;
- $ten_param = array($verify_code);
- $message = ds_replace_text($tpl_info['mailmt_content'], $param);
- $smslog_param = array(
- 'ali_template_code' => $tpl_info['ali_template_code'],
- 'ali_template_param' => $param,
- 'ten_template_code' => $tpl_info['ten_template_code'],
- 'ten_template_param' => $ten_param,
- 'message' => $message,
- );
- $result = model('smslog')->sendSms($mobile, $smslog_param, 4, $verify_code);
- if (!$result['state']) {
- exit(json_encode(array('state' => 'false', 'msg' => $result['message'])));
- }
- $ip = request()->ip();
- $flag = $verify_code_model->addVerifyCode(array(
- 'verify_code_type' => 4,
- 'verify_code' => $verify_code,
- 'verify_code_user_type' => 1,
- 'verify_code_user_id' => session('member_id'),
- 'verify_code_user_name' => session('member_name'),
- 'verify_code_add_time' => TIMESTAMP,
- 'verify_code_ip' => $ip,
- ));
- if (!$flag) {
- exit(json_encode(array('state' => 'false', 'msg' => lang('system_error'))));
- }
- $update = $member_model->editMember(array('member_id' => session('member_id')), array('member_mobile' => $mobile), session('member_id'));
- if (!$update) {
- exit(json_encode(array('state' => 'false', 'msg' => lang('modified_phone_same_original_one'))));
- } else {
- exit(json_encode(array('state' => 'true', 'msg' => lang('send_success'))));
- }
- }
- /**
- * 用户中心右边,小导航
- *
- * @param string $menu_type 导航类型
- * @param string $menu_key 当前导航的menu_key
- * @return
- */
- protected function getMemberItemList()
- {
- $menu_name = request()->action();
- switch ($menu_name) {
- case 'index':
- $menu_array = array(
- array(
- 'name' => 'index', 'text' => lang('account_security'),
- 'url' => (string)url('Membersecurity/index')
- )
- );
- return $menu_array;
- break;
- case 'modify_pwd':
- $menu_array = array(
- array(
- 'name' => 'index', 'text' => lang('account_security'),
- 'url' => (string)url('Membersecurity/index')
- ), array(
- 'name' => 'modify_pwd', 'text' => lang('change_login_password'),
- 'url' => (string)url('Membersecurity/auth', ['type' => 'modify_pwd'])
- ),
- );
- return $menu_array;
- break;
- case 'modify_email':
- $menu_array = array(
- array(
- 'name' => 'index', 'text' => lang('account_security'),
- 'url' => (string)url('Membersecurity/index')
- ), array(
- 'name' => 'modify_email', 'text' => lang('email_address_verification'),
- 'url' => (string)url('Membersecurity/auth', ['type' => 'modify_email'])
- ),
- );
- return $menu_array;
- break;
- case 'modify_mobile':
- $menu_array = array(
- array(
- 'name' => 'index', 'text' => lang('account_security'),
- 'url' => (string)url('Membersecurity/index')
- ), array(
- 'name' => 'modify_mobile', 'text' => lang('phone_verification'),
- 'url' => (string)url('Membersecurity/auth', ['type' => 'modify_mobile'])
- ),
- );
- return $menu_array;
- break;
- case 'modify_paypwd':
- $menu_array = array(
- array(
- 'name' => 'index', 'text' => lang('account_security'),
- 'url' => (string)url('Membersecurity/index')
- ), array(
- 'name' => 'modify_paypwd', 'text' => lang('set_payment_password'),
- 'url' => (string)url('Membersecurity/auth', ['type' => 'modify_paypwd'])
- ),
- );
- return $menu_array;
- break;
- case 'auth':
- $menu_array = array(
- array(
- 'name' => 'loglist', 'text' => lang('account_balance'),
- 'url' => (string)url('Predeposit/pd_log_list')
- ), array(
- 'name' => 'recharge_list', 'text' => lang('top_up_detail'),
- 'url' => (string)url('Predeposit/index')
- ), array(
- 'name' => 'cashlist', 'text' => lang('balance_withdrawal'),
- 'url' => (string)url('Predeposit/pd_cash_list')
- ), array(
- 'name' => 'pd_cash', 'text' => lang('withdrawal_application'),
- 'url' => (string)url('Membersecurity/auth', ['type' => 'pd_cash'])
- ),
- );
- return $menu_array;
- break;
- }
- }
- }
|