Initial project files: BESCMS full source
This commit is contained in:
@@ -0,0 +1,496 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
// 账号信息
|
||||
class Account extends \Phpcmf\Common {
|
||||
|
||||
/**
|
||||
* 修改资料
|
||||
*/
|
||||
public function index() {
|
||||
|
||||
// 初始化自定义字段类
|
||||
\Phpcmf\Service::L('field')->app(APP_DIR);
|
||||
|
||||
// 获取该组可用字段
|
||||
$field = [];
|
||||
if ($this->member_cache['field'] && $this->member['groupid']) {
|
||||
$fieldid = [];
|
||||
foreach ($this->member['groupid'] as $gid) {
|
||||
$this->member_cache['group'][$gid]['field']
|
||||
&& $fieldid = dr_array2array($fieldid, $this->member_cache['group'][$gid]['field']);
|
||||
}
|
||||
if ($fieldid) {
|
||||
foreach ($this->member_cache['field'] as $fname => $t) {
|
||||
in_array($fname, $fieldid) && $field[$fname] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 是否允许更新姓名
|
||||
$is_update_name = $this->member_cache['config']['edit_name'] || !$this->member['name'];
|
||||
|
||||
if (IS_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
\Phpcmf\Hooks::trigger('member_edit_before', $post);
|
||||
list($data, $return, $attach) = \Phpcmf\Service::L('form')->id($this->uid)->validation($post, null, $field, $this->member);
|
||||
// 输出错误
|
||||
if ($return) {
|
||||
$this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
}
|
||||
if ($is_update_name) {
|
||||
if (!$post['name']) {
|
||||
$this->_json(0, dr_lang('%s没有填写', MEMBER_CNAME), ['field' => 'name']);
|
||||
}
|
||||
$post['name'] = dr_strcut($post['name'], intval($this->member_cache['register']['cutname']), '');
|
||||
if ($this->member_cache['config']['unique_name']
|
||||
&& \Phpcmf\Service::M()->db->table('member')->where('id<>'. $this->uid)->where('name', $post['name'])->countAllResults()) {
|
||||
$this->_json(0, dr_lang('%s已经存在', MEMBER_CNAME), ['field' => 'name']);
|
||||
}
|
||||
if ($this->member_cache['config']['edit_verify']) {
|
||||
// 审核
|
||||
} else {
|
||||
\Phpcmf\Service::M()->table('member')->update($this->uid, [
|
||||
'name' => dr_strcut(dr_safe_replace($post['name']), 20, ''),
|
||||
]);
|
||||
}
|
||||
}
|
||||
$data[1]['is_complete'] = 1;
|
||||
if ($this->member_cache['config']['edit_verify']) {
|
||||
// 审核
|
||||
} else {
|
||||
\Phpcmf\Service::M()->table('member_data')->update($this->uid, $data[1]);
|
||||
}
|
||||
// 附件归档
|
||||
SYS_ATTACHMENT_DB && $attach && \Phpcmf\Service::M('Attachment')->handle(
|
||||
$this->member['id'],
|
||||
\Phpcmf\Service::M()->dbprefix('member').'-'.$this->uid,
|
||||
$attach
|
||||
);
|
||||
if ($this->member_cache['config']['edit_verify']) {
|
||||
// 审核
|
||||
$id = \Phpcmf\Service::M('verify', 'member')->save_info($this->uid, $is_update_name ? $post['name'] : '', $data[1]);
|
||||
// 提醒
|
||||
\Phpcmf\Service::M('member')->admin_notice(0, 'member', $this->member, dr_lang('用户[%s]资料审核', $this->member['username']), 'member/edit_verify/edit:id/'.$id);
|
||||
$this->_json(1, dr_lang('提交成功,等待管理员审核'), IS_API_HTTP ? \Phpcmf\Service::M('member')->get_member($this->uid) : []);
|
||||
} else {
|
||||
\Phpcmf\Hooks::trigger('member_edit_after', $data[1]);
|
||||
\Phpcmf\Service::M('member')->clear_cache($this->uid);
|
||||
$this->_json(1, dr_lang('保存成功'), IS_API_HTTP ? \Phpcmf\Service::M('member')->get_member($this->uid) : []);
|
||||
}
|
||||
}
|
||||
|
||||
$verify = [];
|
||||
if ($this->member_cache['config']['edit_verify']) {
|
||||
// 审核
|
||||
$verify = \Phpcmf\Service::M('verify', 'member')->info($this->uid);
|
||||
if ($verify) {
|
||||
$this->member = dr_array22array($this->member, $verify['info']);
|
||||
if ($verify['name'] && $is_update_name) {
|
||||
$this->member['name'] = $verify['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'field' => $field,
|
||||
'member' => $this->member,
|
||||
'myfield' => \Phpcmf\Service::L('field')->toform($this->uid, $field, $this->member),
|
||||
'edit_verify' => $verify,
|
||||
'is_update_name' => $is_update_name,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('account_index.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像上传
|
||||
*/
|
||||
public function avatar() {
|
||||
|
||||
if (IS_POST) {
|
||||
$content = isset($_POST['file']) && $_POST['file'] ? trim($_POST['file']) : '';
|
||||
// 普通文件上传
|
||||
if (isset($_FILES['file'])) {
|
||||
if (isset($_FILES["file"]["tmp_name"]) && $_FILES["file"]["tmp_name"]) {
|
||||
$content = \Phpcmf\Service::L('file')->base64_image($_FILES["file"]["tmp_name"]);
|
||||
}
|
||||
}
|
||||
if (!$content) {
|
||||
$this->_json(0, dr_lang('上传文件失败'));
|
||||
}
|
||||
list($cache_path) = dr_avatar_path();
|
||||
if (preg_match('/^(data:\s*image\/(\w+);base64,)/i', $content, $result)) {
|
||||
$content = base64_decode(str_replace($result[1], '', $content));
|
||||
if (strlen($content) > 30000000) {
|
||||
$this->_json(0, dr_lang('图片太大了'));
|
||||
}
|
||||
// 头像上传成功之前
|
||||
\Phpcmf\Hooks::trigger('upload_avatar_before', [
|
||||
'member' => $this->member,
|
||||
'base64_image' => $content,
|
||||
]);
|
||||
$name = $this->uid;
|
||||
$dir = dr_avatar_dir($this->uid);
|
||||
if ($this->member_cache['config']['avatar_verify']) {
|
||||
// 审核
|
||||
$name.= '_verify';
|
||||
}
|
||||
$rt = \Phpcmf\Service::L('upload')->base64_image([
|
||||
'content' => $content,
|
||||
'ext' => 'jpg',
|
||||
'save_name' => $name,
|
||||
'save_file' => $cache_path.$dir.$name.'.jpg',
|
||||
]);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
if (is_file($cache_path.$this->uid.'.jpg')) {
|
||||
// 移动老版本目录
|
||||
if (copy($cache_path.$this->uid.'.jpg', $cache_path.$dir.$this->uid.'.jpg')) {
|
||||
unlink($cache_path.$this->uid.'.jpg');
|
||||
}
|
||||
}
|
||||
if ($this->member_cache['config']['avatar_verify']) {
|
||||
// 审核
|
||||
$id = \Phpcmf\Service::M('verify', 'member')->save_avatar($this->uid);
|
||||
// 提醒
|
||||
\Phpcmf\Service::M('member')->admin_notice(0, 'member', $this->member, dr_lang('用户[%s]头像审核', $this->member['username']), 'member/avatar_verify/edit:id/'.$id);
|
||||
$this->_json(1, dr_lang('上传成功,等待管理员审核'), []);
|
||||
} else {
|
||||
// 头像上传成功之后
|
||||
\Phpcmf\Hooks::trigger('upload_avatar_after', [
|
||||
'member' => $this->member,
|
||||
'base64_image' => $content,
|
||||
]);
|
||||
// 头像认证成功
|
||||
if (!$this->member['is_avatar']) {
|
||||
\Phpcmf\Service::M('member')->do_avatar($this->member);
|
||||
}
|
||||
\Phpcmf\Service::M('member')->clear_cache($this->uid);
|
||||
$this->_json(1, dr_lang('上传成功'), IS_API_HTTP ? \Phpcmf\Service::M('member')->get_member($this->uid) : []);
|
||||
}
|
||||
} else {
|
||||
$this->_json(0, dr_lang('头像内容不规范'));
|
||||
}
|
||||
}
|
||||
|
||||
$verify = [];
|
||||
$avatar_url = '';
|
||||
if ($this->member_cache['config']['avatar_verify']) {
|
||||
// 审核
|
||||
$verify = \Phpcmf\Service::M('verify', 'member')->avatar($this->uid);
|
||||
if ($verify) {
|
||||
$avatar_url = dr_member_verify_avatar_url($this->uid);
|
||||
}
|
||||
}
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(['file' => '']),
|
||||
'avatar_url' => $avatar_url ? $avatar_url : dr_avatar($this->uid),
|
||||
'edit_verify' => $verify,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('account_avatar.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public function password() {
|
||||
|
||||
if ($this->member['salt'] == 'login_sms') {
|
||||
$this->member['password'] = '';
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$password = dr_safe_password($post['password']);
|
||||
if ((empty($post['password2']) || empty($post['password3']))) {
|
||||
$this->_json(0, dr_lang('密码不能为空'), ['field' => 'password2']);
|
||||
} elseif ($post['password3'] != $post['password2']) {
|
||||
$this->_json(0, dr_lang('两次密码不一致'), ['field' => 'password3']);
|
||||
} elseif ($this->member['password'] && md5(md5($password).$this->member['salt'].md5($password)) != $this->member['password']) {
|
||||
$this->_json(0, dr_lang('原密码不正确'), ['field' => 'password']);
|
||||
} elseif ($this->member['password'] && md5(md5($post['password2']).$this->member['salt'].md5($post['password2'])) == $this->member['password']) {
|
||||
$this->_json(0, dr_lang('原密码不能与新密码相同'), ['field' => 'password2']);
|
||||
}
|
||||
$rt = \Phpcmf\Service::L('Form')->check_password($post['password2'], $this->member['username']);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg'], ['field' => 'password2']);
|
||||
}
|
||||
// 修改密码
|
||||
\Phpcmf\Service::M('member')->edit_password($this->member, $post['password2']);
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'member' => $this->member,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('account_password.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机修改
|
||||
*/
|
||||
public function mobile() {
|
||||
|
||||
// 是否允许更新手机号码
|
||||
$is_update = $this->member_cache['config']['edit_mobile'] || !$this->member['phone'];
|
||||
|
||||
// 是否需要认证手机号码 // $this->member_cache['config']['mobile'] &&
|
||||
$is_mobile = !$this->member['is_mobile'] ;
|
||||
|
||||
// 账号已经录入了手机,且没有进行手机认证时,强制不更新,先认证
|
||||
//$is_mobile && $this->member['phone'] && $is_update = 0;
|
||||
|
||||
if (IS_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$cache = \Phpcmf\Service::L('cache')->check_auth_data('member-mobile-code-'.$this->uid, 300);
|
||||
if (!$this->member['randcode']) {
|
||||
$this->_json(0, dr_lang('手机验证码已过期'));
|
||||
} elseif ($post['code'] != $this->member['randcode']) {
|
||||
$this->_json(0, dr_lang('手机验证码不正确') . (IS_DEV ? '(你输入是:'.$post['code'].',正确是:'.$this->member['randcode'].')' : ''));
|
||||
} elseif (!$cache) {
|
||||
$this->_json(0, dr_lang('手机验证码储存过期'));
|
||||
}
|
||||
|
||||
$value = dr_safe_replace($post['phone']);
|
||||
if ($is_update && $value) {
|
||||
// 更新手机号
|
||||
if (!\Phpcmf\Service::L('Form')->check_phone($value)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'));
|
||||
} elseif (\Phpcmf\Service::M()->db->table('member')->where('id<>'.$this->member['id'])->where('phone', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('手机号码已经注册'));
|
||||
} elseif ($cache != $value) {
|
||||
// caceh存储的是手机号码,验证手机号码是否匹配
|
||||
$this->_json(0, dr_lang('手机号码不匹配(%s)', substr($cache, 0, 3).'****'.substr($cache, -4)) . (IS_DEV ? '(你输入是:'.$value.',正确是:'.$cache.')' : ''));
|
||||
}
|
||||
$this->member['phone_old'] = $this->member['phone'];
|
||||
$this->member['phone'] = $value;
|
||||
\Phpcmf\Hooks::trigger('member_edit_phone_after', $this->member);
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['phone' => $value]);
|
||||
} else {
|
||||
// 不变更手机时
|
||||
if ($cache != $this->member['phone']) {
|
||||
// caceh存储的是手机号码,验证手机号码是否匹配
|
||||
$this->_json(0, dr_lang('手机号码不匹配(%s)', substr($this->member['phone'], 0, 3).'****'.substr($this->member['phone'], -4)) . (IS_DEV ? '(正确是:'.$this->member['phone'].')' : ''));
|
||||
}
|
||||
}
|
||||
|
||||
// 认证号码
|
||||
!$this->member['is_mobile'] && \Phpcmf\Service::M()->db->table('member_data')->where('id', $this->member['id'])->update(['is_mobile' => 1]);
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['randcode' => 0]);
|
||||
|
||||
\Phpcmf\Service::M('member')->clear_cache($this->uid);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'api_url' => \Phpcmf\Service::L('Router')->member_url('account/mobile_code'),
|
||||
'is_update' => $is_update,
|
||||
'is_mobile' => $is_mobile,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('account_mobile.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱修改
|
||||
*/
|
||||
public function email() {
|
||||
|
||||
// 是否允许更新
|
||||
$is_update = $this->member_cache['config']['edit_email'] || !$this->member['email'];
|
||||
|
||||
// 是否需要认证 $this->member_cache['config']['email'] &&
|
||||
$is_email = !$this->member['is_email'] ;
|
||||
|
||||
// 账号已经录入了手机,且没有进行手机认证时,强制不更新,先认证
|
||||
//$is_email && $this->member['phone'] && $is_update = 0;
|
||||
|
||||
if (IS_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$cache = \Phpcmf\Service::L('cache')->check_auth_data('member-email-code-'.$this->uid, 300);
|
||||
if (!$this->member['randcode']) {
|
||||
$this->_json(0, dr_lang('邮箱验证码已过期'));
|
||||
} elseif ($post['code'] != $this->member['randcode']) {
|
||||
$this->_json(0, dr_lang('邮箱验证码不正确') . (IS_DEV ? '(你输入是:'.$post['code'].',正确是:'.$this->member['randcode'].')' : ''));
|
||||
} elseif (!$cache) {
|
||||
$this->_json(0, dr_lang('邮箱验证码储存过期'));
|
||||
}
|
||||
|
||||
$value = dr_safe_replace($post['email']);
|
||||
if ($is_update && $value) {
|
||||
// 更新
|
||||
if (!\Phpcmf\Service::L('Form')->check_email($value)) {
|
||||
$this->_json(0, dr_lang('邮箱格式不正确'));
|
||||
} elseif (\Phpcmf\Service::M()->db->table('member')->where('id<>'.$this->member['id'])->where('email', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('邮箱地址已经注册'));
|
||||
} elseif ($cache != $value) {
|
||||
// caceh存储的是,验证号码是否匹配
|
||||
$this->_json(0, dr_lang('邮件地址不匹配(%s)', substr($cache, 0, 3).'****'.substr($cache, -4)) . (IS_DEV ? '(你输入是:'.$value.',正确是:'.$cache.')' : ''));
|
||||
}
|
||||
$this->member['email_old'] = $this->member['email'];
|
||||
$this->member['email'] = $value;
|
||||
\Phpcmf\Hooks::trigger('member_edit_email_after', $this->member);
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['email' => $value]);
|
||||
} else {
|
||||
// 不变更时
|
||||
if ($cache != $this->member['email']) {
|
||||
// caceh存储的是手机号码,验证手机号码是否匹配
|
||||
$this->_json(0, dr_lang('邮箱地址不匹配(%s)', substr($this->member['email'], 0, 3).'****'.substr($this->member['email'], -4)) . (IS_DEV ? '(正确是:'.$this->member['phone'].')' : ''));
|
||||
}
|
||||
}
|
||||
|
||||
// 认证
|
||||
!$this->member['is_email'] && \Phpcmf\Service::M()->db->table('member_data')->where('id', $this->member['id'])->update(['is_email' => 1]);
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['randcode' => 0]);
|
||||
|
||||
\Phpcmf\Service::M('member')->clear_cache($this->uid);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'api_url' => \Phpcmf\Service::L('Router')->member_url('account/email_code'),
|
||||
'is_update' => $is_update,
|
||||
'is_email' => $is_email,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('account_email.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
*/
|
||||
public function mobile_code() {
|
||||
|
||||
$value = '';
|
||||
// 是否允许更新手机号码
|
||||
if ($this->member_cache['config']['edit_mobile'] || !$this->member['phone'] || !$this->member['is_mobile']) {
|
||||
$value = dr_safe_replace(\Phpcmf\Service::L('input')->get('value'));
|
||||
}
|
||||
|
||||
// 是否需要认证手机号码 && $this->member_cache['config']['mobile']
|
||||
if (!$value && $this->member['phone'] && !$this->member['is_mobile']) {
|
||||
$value = $this->member['phone'];
|
||||
}
|
||||
|
||||
// 已经认证通过的
|
||||
if (!$value && $this->member['is_mobile']) {
|
||||
$this->_json(0, dr_lang('您已经通过认证了'));
|
||||
}
|
||||
|
||||
// 验证操作间隔
|
||||
$name = 'member-mobile-code-'.$this->uid;
|
||||
if (\Phpcmf\Service::L('cache')->check_auth_data($name, defined('SYS_CACHE_SMS') && SYS_CACHE_SMS ? SYS_CACHE_SMS : 60)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试'));
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_phone($value)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'));
|
||||
}
|
||||
|
||||
$this->member['randcode'] = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['uid'])->update(['randcode' => $this->member['randcode']]);
|
||||
|
||||
$rt = \Phpcmf\Service::M('member')->sendsms_code($value, $this->member['randcode']);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_auth_data($name, $value);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件验证码
|
||||
*/
|
||||
public function email_code() {
|
||||
|
||||
$value = '';
|
||||
// 是否允许更新手机号码
|
||||
if ($this->member_cache['config']['edit_email'] || !$this->member['email'] || !$this->member['is_email']) {
|
||||
$value = dr_safe_replace(\Phpcmf\Service::L('input')->get('value'));
|
||||
}
|
||||
|
||||
// 是否需要认证手机号码$this->member_cache['config']['email'] &&
|
||||
if (!$value && $this->member['email'] && !$this->member['is_email']) {
|
||||
$value = $this->member['email'];
|
||||
}
|
||||
|
||||
// 已经认证通过的
|
||||
if (!$value && $this->member['is_email']) {
|
||||
$this->_json(0, dr_lang('您已经通过认证了'));
|
||||
}
|
||||
|
||||
// 验证操作间隔
|
||||
$name = 'member-email-code-'.$this->uid;
|
||||
if (\Phpcmf\Service::L('cache')->check_auth_data($name, 300)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试'));
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_email($value)) {
|
||||
$this->_json(0, dr_lang('邮箱地址格式不正确'));
|
||||
}
|
||||
|
||||
$this->member['randcode'] = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['uid'])->update(['randcode' => $this->member['randcode']]);
|
||||
|
||||
$rt = \Phpcmf\Service::M('member')->sendmail($value, dr_lang('邮件验证'), 'member_email_code.html', $this->member);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_auth_data($name, $value);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录记录
|
||||
*/
|
||||
public function login() {
|
||||
\Phpcmf\Service::V()->display('account_login.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 解除绑定
|
||||
*/
|
||||
public function oauth_delete() {
|
||||
|
||||
$name = dr_safe_replace(\Phpcmf\Service::L('input')->get('name'));
|
||||
\Phpcmf\Service::M()->db->table('member_oauth')->where('uid', $this->uid)->where('oauth', $name)->delete();
|
||||
if (dr_is_app('weixin')) {
|
||||
\Phpcmf\Service::M()->db->table('weixin_user')->where('uid', $this->uid)->delete();
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->clear_cache($this->uid);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'), ['url' => \Phpcmf\Service::L('Router')->member_url('account/oauth')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快捷登录
|
||||
*/
|
||||
public function oauth() {
|
||||
|
||||
$name = [];
|
||||
$oauth = dr_oauth_list();
|
||||
if (dr_is_app('weixin')) {
|
||||
$oauth['wechat'] = [];
|
||||
}
|
||||
foreach ($oauth as $value => $t) {
|
||||
if (!isset($this->member_cache['oauth'][$value]['id'])
|
||||
|| !$this->member_cache['oauth'][$value]['id']) {
|
||||
continue;
|
||||
}
|
||||
$name[] = $value;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'list' => \Phpcmf\Service::M('member')->oauth($this->uid),
|
||||
'oauth' => $name,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('account_oauth.html');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Api extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
|
||||
// 查看流程
|
||||
public function verify() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
if (!$id) {
|
||||
$this->_json(0, dr_lang('审核流程id不存在'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('admin_verify')->where('id', $id)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'role' => \Phpcmf\Service::M('Auth')->get_role_all(),
|
||||
'value' => dr_string2array($data['verify']),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('verify_show.html');exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
// 用户组申请
|
||||
class Apply extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
// 模板前缀(避免混淆)
|
||||
$this->my_field = array(
|
||||
'username' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('账户'),
|
||||
'fieldname' => 'username',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
)
|
||||
),
|
||||
'uid' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('uid'),
|
||||
'fieldname' => 'uid',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户组审核');
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'member_group_verify',
|
||||
'field' => $this->my_field,
|
||||
'sys_field' => [],
|
||||
'order_by' => 'inputtime desc',
|
||||
'date_field' => 'inputtime',
|
||||
'list_field' => [],
|
||||
]);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户组审核' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-users'],
|
||||
'详情' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
]
|
||||
),
|
||||
'field' => $this->my_field,
|
||||
]);
|
||||
}
|
||||
|
||||
// index
|
||||
public function index() {
|
||||
$this->_List();
|
||||
\Phpcmf\Service::V()->display('member_apply_list.html');
|
||||
}
|
||||
|
||||
// edit
|
||||
public function edit() {
|
||||
|
||||
list($tpl, $data) = $this->_Post((int)\Phpcmf\Service::L('input')->get('id'), [], 1);
|
||||
if (!$data) {
|
||||
$this->_admin_msg(0, dr_lang('申请记录不存在'));
|
||||
}
|
||||
|
||||
$my = dr_string2array($data['content']);
|
||||
$user = dr_member_info($data['uid']);
|
||||
$my = dr_array22array($user, $my);
|
||||
|
||||
// 获取该组可用字段
|
||||
$field = [
|
||||
'note' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('审核备注'),
|
||||
'fieldname' => 'note',
|
||||
'fieldtype' => 'Textarea',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => '80%',
|
||||
),
|
||||
)
|
||||
),
|
||||
];
|
||||
if ($this->member_cache['field'] && $this->member_cache['group'][$data['gid']]['field']) {
|
||||
foreach ($this->member_cache['field'] as $fname => $t) {
|
||||
dr_in_array($fname, $this->member_cache['group'][$data['gid']]['field']) && $field[$fname] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
$verify_msg = [];
|
||||
if ($this->member_cache['config']['verify_msg']) {
|
||||
$msg = @explode(PHP_EOL, $this->member_cache['config']['verify_msg']);
|
||||
$msg && $verify_msg = $msg;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'myfield' => \Phpcmf\Service::L('field')->toform($this->uid, $field, $my),
|
||||
'verify_msg' => $verify_msg,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_apply_post.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存内容
|
||||
* $id 内容id,新增为0
|
||||
* $data 提交内容数组,留空为自动获取
|
||||
* $func 格式化提交的数据
|
||||
* */
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
|
||||
\Phpcmf\Service::M('member')->todo_admin_notice('member/apply/edit:id/'.$id);
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$member = \Phpcmf\Service::M('member')->member_info($old['uid']);
|
||||
$member['verify'] = dr_array22array($old, $post);
|
||||
$member['verify_group'] = $this->member_cache['group'][$old['gid']]['name'];
|
||||
$member['verify_status'] = $post['status'] ? dr_lang('成功') : dr_lang('被拒绝');
|
||||
$member['verify_content'] = $post['note'];
|
||||
|
||||
if ($post['status']) {
|
||||
unset($post['status']);
|
||||
// 获取该组可用字段
|
||||
$field = [];
|
||||
if ($this->member_cache['field'] && $this->member_cache['group'][$old['gid']]['field']) {
|
||||
foreach ($this->member_cache['field'] as $fname => $t) {
|
||||
dr_in_array($fname, $this->member_cache['group'][$old['gid']]['field']) && $field[$fname] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
// 表单操作类
|
||||
\Phpcmf\Service::L('form')->id($id); // 初始化id
|
||||
list($post, $return, $attach) = \Phpcmf\Service::L('form')->validation($post, [], $field, []);
|
||||
if ($return) {
|
||||
$this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
}
|
||||
unset($post[1]['uid']);
|
||||
unset($post[1]['username']);
|
||||
|
||||
$post[1] && \Phpcmf\Service::M()->table('member_data')->update($old['uid'], $post[1]);
|
||||
SYS_ATTACHMENT_DB && $attach && \Phpcmf\Service::M('Attachment')->handle($old['uid'], \Phpcmf\Service::M()->dbprefix('member').'-'.$id, $attach);
|
||||
|
||||
\Phpcmf\Service::M()->table('member_group_verify')->delete($id);
|
||||
$post[1] && \Phpcmf\Service::M()->table('member_data')->update($old['uid'], $post[1]);
|
||||
\Phpcmf\Service::M('member')->insert_group($old['uid'], $old['gid']);
|
||||
$old['lid'] && \Phpcmf\Service::M('member')->update_level($old['uid'], $old['gid'], $old['lid']);
|
||||
} else {
|
||||
// 审核拒绝
|
||||
unset($post['status']);
|
||||
\Phpcmf\Service::M()->table('member_group_verify')->update($id, [
|
||||
'content' => dr_array2string($post),
|
||||
'status' => 1, // 拒绝
|
||||
]);
|
||||
// 不退回金额
|
||||
}
|
||||
|
||||
// 通知 钩子
|
||||
\Phpcmf\Service::L('Notice')->send_notice('member_verify_group', $member);
|
||||
\Phpcmf\Hooks::trigger('member_verify_group_after', $member);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function del() {
|
||||
$this->_Del(\Phpcmf\Service::L('input')->get_post_ids(), null, function($rows) {
|
||||
foreach ($rows as $t) {
|
||||
// 删除审核提醒
|
||||
\Phpcmf\Service::M('member')->delete_admin_notice('member/apply/edit:id/'.$t['id']);
|
||||
// 退回金额
|
||||
$this->_call_score($t);
|
||||
}
|
||||
return dr_return_data(1, 'ok');
|
||||
});
|
||||
}
|
||||
|
||||
// 退回金额
|
||||
private function _call_score($t) {
|
||||
|
||||
if ($t['price'] > 0) {
|
||||
$group = $this->member_cache['group'][$t['gid']];
|
||||
$notice = $t['lid'] ? dr_lang('[退回]申请用户组(%s): %s', $group['name'], $group['level'][$t['lid']]['name']) : dr_lang('[退回]申请用户组(%s)', $group['name']);
|
||||
if ($this->member_cache['group'][$t['gid']]['unit']) {
|
||||
// 金币
|
||||
// 扣分
|
||||
$rt = \Phpcmf\Service::M('member')->add_score($t['uid'], (int)$t['price'], $notice, '', '');
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
// 提醒通知
|
||||
\Phpcmf\Service::M('member')->notice($t['uid'], 2, $notice);
|
||||
} else {
|
||||
// rmb
|
||||
if (!dr_is_app('pay')) {
|
||||
$this->_msg(0, '没有安装「支付系统」插件');exit;
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('Pay','pay')->add_money($t['uid'], $t['price']);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
// 增加到交易流水
|
||||
$rt = \Phpcmf\Service::M('Pay','pay')->add_paylog([
|
||||
'uid' => $t['uid'],
|
||||
'touid' => 0,
|
||||
'mid' => 'system',
|
||||
'title' => $notice,
|
||||
'value' => $t['price'],
|
||||
'type' => 'finecms',
|
||||
'status' => 1,
|
||||
'result' => '',
|
||||
'paytime' => SYS_TIME,
|
||||
'inputtime' => SYS_TIME,
|
||||
]);
|
||||
// 提醒通知
|
||||
\Phpcmf\Service::M('member')->notice(
|
||||
$t['uid'],
|
||||
2,
|
||||
$notice,
|
||||
\Phpcmf\Service::L('Router')->member_url('pay/paylog/show', ['id'=>$rt['code']])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,634 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Auth extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
// 用户权限开关项
|
||||
protected $member_check_fields = [
|
||||
'avatar' => '强制上传头像',
|
||||
'complete' => '强制完善资料',
|
||||
'mobile' => '强制手机认证',
|
||||
'email' => '强制邮箱认证',
|
||||
'downfile' => '附件下载权限',
|
||||
'uploadfile' => '附件上传权限',
|
||||
];
|
||||
|
||||
// 用户权限数值项
|
||||
protected $member_number_fields = [
|
||||
'login' => [
|
||||
'name' => '每日登录奖励',
|
||||
'items' => [
|
||||
'login_score' => ['app' => 'scorelog', 'unit' => 'score'],
|
||||
'login_exp' => ['app' => 'explog', 'unit' => 'exp'],
|
||||
],
|
||||
],
|
||||
'avatar_award' => [
|
||||
'name' => '头像认证奖励',
|
||||
'items' => [
|
||||
'avatar_score' => ['app' => 'scorelog', 'unit' => 'score'],
|
||||
'avatar_exp' => ['app' => 'explog', 'unit' => 'exp'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public function index() {
|
||||
|
||||
// 用户组列
|
||||
$group = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
'use' => 1,
|
||||
]
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
$group[$t['id']] = [
|
||||
'id' => $t['id'],
|
||||
'name' => dr_lang($t['name']),
|
||||
'use' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
// 用户组等级列
|
||||
$level = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
'group_name' => '',
|
||||
'level_name' => dr_lang('游客'),
|
||||
'use' => 1,
|
||||
]
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
$gname = dr_lang($t['name']);
|
||||
$level[$t['id']] = [
|
||||
'id' => $t['id'],
|
||||
'name' => $gname,
|
||||
'group_name' => '',
|
||||
'level_name' => $gname,
|
||||
'use' => 1,
|
||||
];
|
||||
if ($t['level']) {
|
||||
foreach ($t['level'] as $lv) {
|
||||
$lname = dr_lang($lv['name']);
|
||||
$level[$t['id'].'-'.$lv['id']] = [
|
||||
'id' => $t['id'].'-'.$lv['id'],
|
||||
'name' => $gname.' / '.$lname,
|
||||
'group_name' => $gname,
|
||||
'level_name' => $lname,
|
||||
'use' => 1,
|
||||
];
|
||||
$level[$t['id']]['use'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth_type')->get()->getRowArray();
|
||||
$auth_type = intval($v['value']);
|
||||
|
||||
// 当前模式对应的列
|
||||
if ($auth_type == 1) {
|
||||
$columns = $group;
|
||||
} elseif ($auth_type == 2) {
|
||||
$columns = [];
|
||||
foreach ($level as $i => $t) {
|
||||
if ($t['use']) {
|
||||
$columns[$i] = $t;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$columns = [
|
||||
'public' => [
|
||||
'id' => 'public',
|
||||
'name' => dr_lang('全局'),
|
||||
'use' => 1,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// 读取权限
|
||||
$row = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$value = $row ? dr_string2array($row['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$auth_data = isset($value[SITE_ID]) && is_array($value[SITE_ID]) ? $value[SITE_ID] : [];
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!is_array($post)) {
|
||||
$post = [];
|
||||
}
|
||||
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$old = [];
|
||||
if (isset($auth_data[$aid]) && is_array($auth_data[$aid])) {
|
||||
$old = $auth_data[$aid];
|
||||
} elseif (isset($auth_data[$key]) && is_array($auth_data[$key])) {
|
||||
$old = $auth_data[$key];
|
||||
}
|
||||
|
||||
// 仅读取当前列提交值,且只白名单写入,避免 POST 注入多余字段
|
||||
$post_member = [];
|
||||
if (isset($post[$aid]['member']) && is_array($post[$aid]['member'])) {
|
||||
$post_member = $post[$aid]['member'];
|
||||
} elseif (isset($post[$key]['member']) && is_array($post[$key]['member'])) {
|
||||
$post_member = $post[$key]['member'];
|
||||
}
|
||||
|
||||
$member = [];
|
||||
foreach ($this->member_check_fields as $field => $name) {
|
||||
$member[$field] = empty($post_member[$field]) ? 0 : 1;
|
||||
}
|
||||
foreach ($this->member_number_fields as $group_item) {
|
||||
foreach ($group_item['items'] as $field => $cfg) {
|
||||
$member[$field] = isset($post_member[$field]) ? intval($post_member[$field]) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
$old['member'] = $member;
|
||||
// 应用插件 / 内容权限仍保留,此处不覆盖
|
||||
$auth_data[$aid] = $old;
|
||||
}
|
||||
|
||||
$value[SITE_ID] = $auth_data;
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$diy = $this->_get_diy();
|
||||
$col_count = dr_count($columns);
|
||||
$is_single = $col_count <= 1;
|
||||
|
||||
// 取某列已存 member 配置
|
||||
$get_member = function ($aid) use ($auth_data) {
|
||||
$key = (string)$aid;
|
||||
if (isset($auth_data[$aid]['member']) && is_array($auth_data[$aid]['member'])) {
|
||||
return $auth_data[$aid]['member'];
|
||||
}
|
||||
if (isset($auth_data[$key]['member']) && is_array($auth_data[$key]['member'])) {
|
||||
return $auth_data[$key]['member'];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
$form_html = '';
|
||||
$thead_html = '';
|
||||
$tbody_html = '';
|
||||
|
||||
if ($is_single) {
|
||||
// 全局模式:标准表单排版
|
||||
$aid = 'public';
|
||||
foreach ($columns as $k => $col) {
|
||||
$aid = (string)$k;
|
||||
break;
|
||||
}
|
||||
$member = $get_member($aid);
|
||||
$aid_attr = htmlspecialchars($aid);
|
||||
|
||||
foreach ($this->member_check_fields as $field => $name) {
|
||||
$checked = !empty($member[$field]) ? ' checked' : '';
|
||||
$form_html .= '<div class="form-group">'
|
||||
.'<label class="col-md-2 control-label">'.dr_lang($name).'</label>'
|
||||
.'<div class="col-md-9">'
|
||||
.'<input type="checkbox" name="data['.$aid_attr.'][member]['.$field.']" value="1"'.$checked
|
||||
.' data-on-text="'.dr_lang('是').'" data-off-text="'.dr_lang('否').'"'
|
||||
.' data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">'
|
||||
.'</div></div>';
|
||||
}
|
||||
|
||||
foreach ($this->member_number_fields as $item) {
|
||||
$form_html .= '<div class="form-group">'
|
||||
.'<label class="col-md-2 control-label">'.dr_lang($item['name']).'</label>'
|
||||
.'<div class="col-md-9">';
|
||||
foreach ($item['items'] as $field => $cfg) {
|
||||
$val = intval(isset($member[$field]) ? $member[$field] : 0);
|
||||
$readonly = (($cfg['app'] == 'scorelog' && !dr_is_app('scorelog'))
|
||||
|| ($cfg['app'] == 'explog' && !dr_is_app('explog'))) ? ' readonly' : '';
|
||||
$unit = $cfg['unit'] == 'score' ? SITE_SCORE : SITE_EXPERIENCE;
|
||||
$form_html .= '<label style="margin-right:10px;">'
|
||||
.'<div class="input-group" style="width:200px;">'
|
||||
.'<input type="text" class="form-control" name="data['.$aid_attr.'][member]['.$field.']" value="'.$val.'"'.$readonly.'>'
|
||||
.'<span class="input-group-btn"><button class="btn default" type="button">+'.htmlspecialchars((string)$unit).'</button></span>'
|
||||
.'</div></label>';
|
||||
}
|
||||
$form_html .= '</div></div>';
|
||||
}
|
||||
|
||||
if (!empty($diy['app'])) {
|
||||
$url = dr_url('member/auth/add', ['aid' => $aid, 'page' => 'app']);
|
||||
$form_html .= '<div class="form-group">'
|
||||
.'<label class="col-md-2 control-label">'.dr_lang('应用插件权限').'</label>'
|
||||
.'<div class="col-md-9">'
|
||||
.'<a href="'.$url.'" class="btn blue btn-sm"><i class="fa fa-puzzle-piece"></i> '.dr_lang('设置').'</a>'
|
||||
.'</div></div>';
|
||||
}
|
||||
} else {
|
||||
// 多列矩阵
|
||||
$thead_html = '<th class="fc-auth-name">'.dr_lang('权限项').'</th>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
if ($key === '0') {
|
||||
$title = '<span class="font-red">'.htmlspecialchars((string)$col['name']).'</span>';
|
||||
} elseif (!empty($col['group_name'])) {
|
||||
$title = '<span class="fc-auth-gname">'.htmlspecialchars((string)$col['group_name']).'</span>'
|
||||
.'<span class="fc-auth-lname">'.htmlspecialchars((string)$col['level_name']).'</span>';
|
||||
} else {
|
||||
$title = htmlspecialchars((string)$col['name']);
|
||||
}
|
||||
$thead_html .= '<th class="fc-auth-col">'.$title.'</th>';
|
||||
}
|
||||
|
||||
foreach ($this->member_check_fields as $field => $name) {
|
||||
$tbody_html .= '<tr><td class="fc-auth-name">'.dr_lang($name).'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$member = $get_member($aid);
|
||||
$checked = !empty($member[$field]) ? ' checked' : '';
|
||||
$tbody_html .= '<td class="fc-auth-col">'
|
||||
.'<input type="checkbox" class="fc-auth-check" name="data['.htmlspecialchars($key).'][member]['.$field.']" value="1"'.$checked.' />'
|
||||
.'</td>';
|
||||
}
|
||||
$tbody_html .= '</tr>';
|
||||
}
|
||||
|
||||
foreach ($this->member_number_fields as $item) {
|
||||
$tbody_html .= '<tr><td class="fc-auth-name">'.dr_lang($item['name']).'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$member = $get_member($aid);
|
||||
$tbody_html .= '<td class="fc-auth-col fc-auth-num-cell">';
|
||||
foreach ($item['items'] as $field => $cfg) {
|
||||
$val = intval(isset($member[$field]) ? $member[$field] : 0);
|
||||
$readonly = (($cfg['app'] == 'scorelog' && !dr_is_app('scorelog'))
|
||||
|| ($cfg['app'] == 'explog' && !dr_is_app('explog'))) ? ' readonly' : '';
|
||||
$unit = $cfg['unit'] == 'score' ? SITE_SCORE : SITE_EXPERIENCE;
|
||||
$tbody_html .= '<div class="input-group input-group-sm fc-auth-num">'
|
||||
.'<input type="text" class="form-control" name="data['
|
||||
.htmlspecialchars($key).'][member]['.$field.']" value="'.$val.'"'.$readonly.' />'
|
||||
.'<span class="input-group-addon">+'.htmlspecialchars((string)$unit).'</span>'
|
||||
.'</div>';
|
||||
}
|
||||
$tbody_html .= '</td>';
|
||||
}
|
||||
$tbody_html .= '</tr>';
|
||||
}
|
||||
|
||||
if (!empty($diy['app'])) {
|
||||
$tbody_html .= '<tr><td class="fc-auth-name">'.dr_lang('应用插件权限').'</td>';
|
||||
foreach ($columns as $aid => $col) {
|
||||
$key = (string)$aid;
|
||||
$url = dr_url('member/auth/add', ['aid' => $key, 'page' => 'app']);
|
||||
$tbody_html .= '<td class="fc-auth-col">'
|
||||
.'<a href="'.$url.'" class="btn blue btn-xs"><i class="fa fa-puzzle-piece"></i> '.dr_lang('设置').'</a>'
|
||||
.'</td>';
|
||||
}
|
||||
$tbody_html .= '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户权限' => ['member/auth/index', 'fa fa-cog'],
|
||||
'help' => [801],
|
||||
]
|
||||
),
|
||||
'auth_type' => $auth_type,
|
||||
'is_single' => $is_single,
|
||||
'is_cms' => (defined('IS_USE_CMS') && IS_USE_CMS) ? 1 : 0,
|
||||
'cms_auth_url' => (defined('IS_USE_CMS') && IS_USE_CMS) ? dr_url('cms/auth/index') : '',
|
||||
'form_html' => $form_html,
|
||||
'thead_html' => $thead_html,
|
||||
'tbody_html' => $tbody_html,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_auth.html');
|
||||
}
|
||||
|
||||
// 存储模式值
|
||||
public function save_edit() {
|
||||
|
||||
$value = intval(\Phpcmf\Service::L('input')->get('value'));
|
||||
if (!$value) {
|
||||
$msg = dr_lang('已切换至按全局配置模式');
|
||||
} elseif ($value == 1) {
|
||||
$msg = dr_lang('已切换至按用户组配置模式');
|
||||
} elseif ($value == 2) {
|
||||
$msg = dr_lang('已切换至按用户组等级配置模式');
|
||||
} else {
|
||||
$this->_json(0, dr_lang('未知模式'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth_type',
|
||||
'value' => $value
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
|
||||
$this->_json(1, $msg);
|
||||
}
|
||||
|
||||
// 初始化组权限(仅清空用户相关配置,保留内容权限)
|
||||
public function init_edit() {
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$aid = \Phpcmf\Service::L('input')->get('aid');
|
||||
if ($aid === null || $aid === false || $aid === '') {
|
||||
$this->_json(0, dr_lang('参数错误'));
|
||||
}
|
||||
// 允许 public / 数字组ID / 组-等级
|
||||
if ($aid !== 'public' && $aid !== '0' && $aid !== 0
|
||||
&& !preg_match('/^\d+(-\d+)?$/', (string)$aid)) {
|
||||
$this->_json(0, dr_lang('参数错误'));
|
||||
}
|
||||
$value = $v ? dr_string2array($v['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$old = isset($value[SITE_ID][$aid]) && is_array($value[SITE_ID][$aid]) ? $value[SITE_ID][$aid] : [];
|
||||
// 兼容整型键
|
||||
if (!$old && is_numeric($aid) && isset($value[SITE_ID][intval($aid)]) && is_array($value[SITE_ID][intval($aid)])) {
|
||||
$old = $value[SITE_ID][intval($aid)];
|
||||
unset($value[SITE_ID][intval($aid)]);
|
||||
}
|
||||
unset($old['member'], $old['app']);
|
||||
$value[SITE_ID][$aid] = $old;
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
|
||||
$this->_json(1, dr_lang('本组权限初始化完成'));
|
||||
}
|
||||
|
||||
// 兼容:单组详细设置(应用插件扩展权限)
|
||||
public function add() {
|
||||
|
||||
$aid = \Phpcmf\Service::L('input')->get('aid');
|
||||
if ($aid == 'public') {
|
||||
$name = dr_lang('全局');
|
||||
} elseif (!$aid) {
|
||||
$aid = 0;
|
||||
$name = dr_lang('游客');
|
||||
} elseif (strpos($aid, '-') !== false) {
|
||||
list($gid, $lid) = explode('-', $aid);
|
||||
if (!$this->member_cache['group'][$gid]) {
|
||||
$this->_admin_msg(0, dr_lang('此用户组不存在'));
|
||||
} elseif (!$this->member_cache['group'][$gid]['level'][$lid]) {
|
||||
$this->_admin_msg(0, dr_lang('此用户组等级不存在'));
|
||||
}
|
||||
$name = $this->member_cache['group'][$gid]['name'].'-'.$this->member_cache['group'][$gid]['level'][$lid]['name'];
|
||||
} else {
|
||||
if (!$this->member_cache['group'][$aid]) {
|
||||
$this->_admin_msg(0, dr_lang('此用户组不存在'));
|
||||
}
|
||||
$name = $this->member_cache['group'][$aid]['name'];
|
||||
}
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$value = $v ? dr_string2array($v['value']) : [];
|
||||
if (!is_array($value)) {
|
||||
$value = [];
|
||||
}
|
||||
$data = isset($value[SITE_ID][$aid]) && is_array($value[SITE_ID][$aid]) ? $value[SITE_ID][$aid] : [];
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!is_array($post)) {
|
||||
$post = [];
|
||||
}
|
||||
$save = $data;
|
||||
// 本页仅维护应用插件权限,禁止通过 POST 覆盖用户权限 member
|
||||
if (isset($post['app']) && is_array($post['app'])) {
|
||||
$save['app'] = $post['app'];
|
||||
}
|
||||
$value[SITE_ID][$aid] = $save;
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
$page = trim(\Phpcmf\Service::L('input')->get('page'));
|
||||
if (!$page) {
|
||||
$page = 'app';
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'aid' => $aid,
|
||||
'diy' => $this->_get_diy(),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'返回' => ['member/auth/index', 'fa fa-cog'],
|
||||
dr_lang('%s:应用权限', $name) => ['member/auth/add{aid='.$aid.'}', 'fa fa-puzzle-piece'],
|
||||
'help' => [801],
|
||||
]
|
||||
),
|
||||
'page' => $page,
|
||||
'data' => $data,
|
||||
'is_ajax_edit' => 0,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_auth_setting.html');
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->_json(0, dr_lang('内容权限请到【内容系统 → 权限设置 → 内容权限】中配置'));
|
||||
}
|
||||
|
||||
public function copy_edit() {
|
||||
|
||||
$at = dr_safe_filename(\Phpcmf\Service::L('input')->get('at'));
|
||||
if (!$at) {
|
||||
$this->_json(0, dr_lang('at参数错误'));
|
||||
}
|
||||
|
||||
$v = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'auth2')->get()->getRowArray();
|
||||
$aid = dr_safe_filename(\Phpcmf\Service::L('input')->get('aid'));
|
||||
!$aid && $aid = 0;
|
||||
$value = dr_string2array($v['value']);
|
||||
|
||||
switch ($at) {
|
||||
|
||||
case 'level':
|
||||
$group = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
],
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
$group[$t['id']] = [
|
||||
'id' => $t['id'],
|
||||
'name' => dr_lang($t['name']),
|
||||
];
|
||||
if ($t['level']) {
|
||||
foreach ($t['level'] as $lv) {
|
||||
$group[$t['id'].'-'.$lv['id']] = [
|
||||
'id' => $t['id'].'-'.$lv['id'],
|
||||
'name' => ' └ '.dr_lang($lv['name']),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$auth = $value[SITE_ID][$aid];
|
||||
if (!$auth) {
|
||||
$this->_json(0, dr_lang('当前用户组没有配置权限规则'));
|
||||
}
|
||||
|
||||
$catids = \Phpcmf\Service::L('input')->post('catid');
|
||||
if (!$catids) {
|
||||
$this->_json(0, dr_lang('你还没有选择用户组呢'));
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
if (isset($catids[0]) && $catids[0] == 0) {
|
||||
foreach ($group as $id => $t) {
|
||||
$c ++;
|
||||
$value[SITE_ID][$id] = $auth;
|
||||
}
|
||||
} else {
|
||||
foreach ($catids as $id) {
|
||||
$c ++;
|
||||
$value[SITE_ID][$id] = $auth;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('共复制%s个用户组', $c));
|
||||
exit;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'select' => \Phpcmf\Service::L('tree')->select_category(
|
||||
$group,
|
||||
0,
|
||||
'id=\'dr_catid\' name=\'catid[]\' multiple="multiple" style="height:200px"',
|
||||
'',
|
||||
0,
|
||||
0
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_auth_copy_group.html');exit;
|
||||
|
||||
case 'group':
|
||||
$group = [
|
||||
0 => [
|
||||
'id' => 0,
|
||||
'name' => dr_lang('游客'),
|
||||
],
|
||||
];
|
||||
foreach ($this->member_cache['group'] as $t) {
|
||||
$group[$t['id']] = $t;
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$auth = $value[SITE_ID][$aid];
|
||||
if (!$auth) {
|
||||
$this->_json(0, dr_lang('当前用户组没有配置权限规则'));
|
||||
}
|
||||
|
||||
$catids = \Phpcmf\Service::L('input')->post('catid');
|
||||
if (!$catids) {
|
||||
$this->_json(0, dr_lang('你还没有选择用户组呢'));
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
if (isset($catids[0]) && $catids[0] == 0) {
|
||||
foreach ($group as $id => $t) {
|
||||
$c ++;
|
||||
$value[SITE_ID][$id] = $auth;
|
||||
}
|
||||
} else {
|
||||
foreach ($catids as $id) {
|
||||
$c ++;
|
||||
$value[SITE_ID][$id] = $auth;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'auth2',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member');
|
||||
$this->_json(1, dr_lang('共复制%s个用户组', $c));
|
||||
exit;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'select' => \Phpcmf\Service::L('tree')->select_category(
|
||||
$group,
|
||||
0,
|
||||
'id=\'dr_catid\' name=\'catid[]\' multiple="multiple" style="height:200px"',
|
||||
'',
|
||||
0,
|
||||
0
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_auth_copy_group.html');exit;
|
||||
|
||||
case 'share_category':
|
||||
case 'category':
|
||||
$this->_json(0, dr_lang('内容权限请到【内容系统 → 权限设置 → 内容权限】中配置'));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$this->_json(0, dr_lang('未知类型'));
|
||||
}
|
||||
|
||||
private function _get_diy() {
|
||||
|
||||
$diy = [
|
||||
'member' => [],
|
||||
'app' => [],
|
||||
];
|
||||
|
||||
$local = \Phpcmf\Service::Apps(1);
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file($path.'Config/Auth.php')) {
|
||||
$_data = require $path.'Config/Auth.php';
|
||||
if ($_data) {
|
||||
foreach ($_data as $key => $val) {
|
||||
if ($val && isset($diy[$key])) {
|
||||
foreach ($val as $file) {
|
||||
if (is_file($path.'Views/auth/'.$file)) {
|
||||
$diy[$key][] = [
|
||||
'app' => $dir,
|
||||
'file' => $path.'Views/auth/'.$file,
|
||||
];
|
||||
} else {
|
||||
log_message('error', '应用插件['.$dir.']权限模板文件不存在:'.$path.'Views/auth/'.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $diy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
// 审核管理
|
||||
class Avatar_verify extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->my_field = array(
|
||||
'uid' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('账号'),
|
||||
'fieldname' => 'uid',
|
||||
'fieldtype' => 'Uid',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户头像审核');
|
||||
// 初始化数据表
|
||||
$list_field = [
|
||||
'avatar' => array(
|
||||
'use' => '1',
|
||||
'name' => '头像',
|
||||
'width' => '90',
|
||||
'func' => 'dr_member_verify_avatar',
|
||||
'center' => '1',
|
||||
),
|
||||
'username' => array(
|
||||
'use' => '1',
|
||||
'name' => '账号',
|
||||
'width' => '120',
|
||||
'func' => 'author',
|
||||
'center' => '0',
|
||||
),
|
||||
'avatar2' => array(
|
||||
'use' => '1',
|
||||
'name' => '新头像',
|
||||
'width' => '90',
|
||||
'func' => 'dr_member_verify_avatar2',
|
||||
'center' => '1',
|
||||
),
|
||||
'status' => array(
|
||||
'use' => '1',
|
||||
'name' => '状态',
|
||||
'width' => '90',
|
||||
'func' => 'dr_member_verify_status',
|
||||
'center' => '1',
|
||||
),
|
||||
'inputtime' => array(
|
||||
'use' => '1',
|
||||
'name' => '修改时间',
|
||||
'width' => '170',
|
||||
'func' => 'datetime',
|
||||
'center' => '0',
|
||||
),
|
||||
];
|
||||
$this->_init([
|
||||
'table' => 'member_verify',
|
||||
'stable' => 'member',
|
||||
'field' => [ 'avatar' => array (
|
||||
'name' => '新头像',
|
||||
'fieldname' => 'avatar',
|
||||
'ismain' => '1',
|
||||
'fieldtype' => 'Diy',
|
||||
'setting' =>
|
||||
array (
|
||||
'option' =>
|
||||
array (
|
||||
'file' => 'avatar.php',
|
||||
),
|
||||
),
|
||||
)],
|
||||
'join_list' => ['member', 'member.id=member_verify.uid', 'left'],
|
||||
'order_by' => 'member_verify.id desc',
|
||||
'list_field' => $list_field,
|
||||
'where_list' => 'tid=2',
|
||||
'select_list' => \Phpcmf\Service::M()->dbprefix('member_verify').'.*,'.\Phpcmf\Service::M()->dbprefix('member').'.username',
|
||||
]);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户资料审核' => ['member/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-edit'],
|
||||
]
|
||||
),
|
||||
'field' => $this->my_field,
|
||||
]);
|
||||
}
|
||||
|
||||
// 用户管理
|
||||
public function index() {
|
||||
|
||||
$this->_List();
|
||||
$this->mytable = [
|
||||
'foot_tpl' => '',
|
||||
'link_tpl' => '',
|
||||
'link_var' => 'html = html.replace(/\{id\}/g, row.id);
|
||||
html = html.replace(/\{uid\}/g, row.id);',
|
||||
];
|
||||
$uriprefix = APP_DIR.'/'.\Phpcmf\Service::L('Router')->class;
|
||||
if ($this->_is_admin_auth('del') || $this->_is_admin_auth('edit')) {
|
||||
$this->mytable['foot_tpl'].= '<label class="table_select_all"><input onclick="dr_table_select_all(this)" type="checkbox"><span></span></label>';
|
||||
}
|
||||
if ($this->_is_admin_auth('del')) {
|
||||
$this->mytable['foot_tpl'].= '<label><button type="button" onclick="dr_table_option(\''.(IS_ADMIN ? dr_url($uriprefix.'/del') : dr_member_url($uriprefix.'/del')).'\', \''.dr_lang('你确定要删除它们吗?').'\')" class="btn red btn-sm"> <i class="fa fa-trash"></i> '.dr_lang('删除').'</button></label>';
|
||||
}
|
||||
|
||||
if ($this->_is_admin_auth('edit')) {
|
||||
$this->mytable['link_tpl'].= '<label><a href="'.dr_url($uriprefix.'/edit').'&id={id}" class="btn btn-xs green"> <i class="fa fa-edit"></i> '.dr_lang('审核').'</a></label>';
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mytable' => $this->mytable,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('edit_verify_list.html');
|
||||
}
|
||||
|
||||
// 修改内容
|
||||
public function edit() {
|
||||
list($tpl) = $this->_Post(intval(\Phpcmf\Service::L('input')->get('id')));
|
||||
$verify_msg = [];
|
||||
if ($this->member_cache['config']['verify_msg']) {
|
||||
$msg = @explode(PHP_EOL, $this->member_cache['config']['verify_msg']);
|
||||
$msg && $verify_msg = $msg;
|
||||
}
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'verify_msg' => $verify_msg,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('edit_verify_post.html');
|
||||
}
|
||||
|
||||
// 删除内容
|
||||
public function del() {
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('Input')->get_post_ids(),
|
||||
function($rows) {
|
||||
// 删除前的验证
|
||||
return dr_return_data(1, 'ok', $rows);
|
||||
},
|
||||
function($rows) {
|
||||
// 删除后的处理
|
||||
return dr_return_data(1, 'ok');
|
||||
},
|
||||
\Phpcmf\Service::M()->dbprefix($this->init['table'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
$row = parent::_Data($id);
|
||||
// 这里可以对内容进行格式化显示操处理
|
||||
$data = \Phpcmf\Service::M()->table('member')->get($row['uid']);
|
||||
$row['username'] = $data['username'];
|
||||
$row['avatar'] = $row['uid'];
|
||||
return $row;
|
||||
}
|
||||
|
||||
// 格式化保存数据
|
||||
protected function _Format_Data($id, $data, $old) {
|
||||
|
||||
if ($old['status'] == 2) {
|
||||
$this->_json(0, '已通过无法编辑');
|
||||
}
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$save = [
|
||||
'status' => $post['status'] ? 2 : 0,
|
||||
'updatetime' => SYS_TIME,
|
||||
'result' => $post['result'],
|
||||
];
|
||||
|
||||
// 后台提醒
|
||||
\Phpcmf\Service::M('member')->todo_admin_notice('member/avatar_verify/edit:id/'.$id, 0);
|
||||
|
||||
// 通知
|
||||
$call = $save;
|
||||
$call['uid'] = $old['uid'];
|
||||
$call['inputtime'] = $old['inputtime'];
|
||||
if ($post['status']) {
|
||||
list($cache_path, $cache_url) = dr_avatar_path();
|
||||
$dir = dr_avatar_dir($old['uid']);
|
||||
if (is_file($cache_path.$dir.$old['uid'].'_verify.jpg')) {
|
||||
copy($cache_path.$dir.$old['uid'].'_verify.jpg', $cache_path.$dir.$old['uid'].'.jpg');
|
||||
@unlink($cache_path.$dir.$old['uid'].'_verify.jpg');
|
||||
}
|
||||
$call['avatar'] = $cache_url.$dir.$old['uid'].'.jpg';
|
||||
\Phpcmf\Service::L('Notice')->send_notice('member_avatar_verify_1', $call);
|
||||
// 头像上传成功之后
|
||||
$member = \Phpcmf\Service::M('member')->get_member($call['uid']);
|
||||
// 头像认证成功
|
||||
if (!$member['is_avatar']) {
|
||||
\Phpcmf\Service::M('member')->do_avatar($member);
|
||||
}
|
||||
\Phpcmf\Service::M('member')->clear_cache($member['id']);
|
||||
} else {
|
||||
\Phpcmf\Service::M()->db->table('member_data')->where('id', $call['uid'])->update(['is_avatar' => 0]);
|
||||
$call['avatar'] = dr_member_verify_avatar_url($call['uid']);
|
||||
\Phpcmf\Service::L('Notice')->send_notice('member_avatar_verify_0', $call);
|
||||
}
|
||||
|
||||
return $save;
|
||||
}
|
||||
|
||||
|
||||
// 保存内容
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
return parent::_Save($id, $data, $old, function($id, $data, $old){
|
||||
// 验证数据
|
||||
/*
|
||||
if (!$data[1]['title']) {
|
||||
return dr_return_data(0, '标题不能为空!', ['field' => 'title']);
|
||||
}*/
|
||||
// 保存之前执行的函数,并返回新的数据
|
||||
if (!$id) {
|
||||
// 当提交新数据时,把当前时间插入进去
|
||||
//$data[1]['inputtime'] = SYS_TIME;
|
||||
}
|
||||
|
||||
return dr_return_data(1, null, $data);
|
||||
}, function ($id, $data, $old) {
|
||||
// 保存之后执行的动作
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if ($post['status']) {
|
||||
\Phpcmf\Service::M()->table('member_verify')->delete($id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
// 审核管理
|
||||
class Edit_verify extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->my_field = array(
|
||||
'uid' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('账号'),
|
||||
'fieldname' => 'uid',
|
||||
'fieldtype' => 'Uid',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
'content' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('全局'),
|
||||
'fieldname' => 'content',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户资料审核');
|
||||
// 初始化数据表
|
||||
$list_field = [
|
||||
'avatar' => array(
|
||||
'use' => '1',
|
||||
'name' => '头像',
|
||||
'width' => '70',
|
||||
'func' => 'dr_member_verify_avatar',
|
||||
'center' => '1',
|
||||
),
|
||||
'username' => array(
|
||||
'use' => '1',
|
||||
'name' => '账号',
|
||||
'width' => '120',
|
||||
'func' => 'author',
|
||||
'center' => '0',
|
||||
),
|
||||
'status' => array(
|
||||
'use' => '1',
|
||||
'name' => '状态',
|
||||
'width' => '120',
|
||||
'func' => 'dr_member_verify_status',
|
||||
'center' => '0',
|
||||
),
|
||||
'inputtime' => array(
|
||||
'use' => '1',
|
||||
'name' => '修改时间',
|
||||
'width' => '170',
|
||||
'func' => 'datetime',
|
||||
'center' => '0',
|
||||
),
|
||||
];
|
||||
$this->_init([
|
||||
'table' => 'member_verify',
|
||||
'stable' => 'member',
|
||||
'field' => $this->member_cache['field'],
|
||||
'join_list' => ['member', 'member.id=member_verify.uid', 'left'],
|
||||
'order_by' => 'member_verify.id desc',
|
||||
'list_field' => $list_field,
|
||||
'where_list' => 'tid=1',
|
||||
'select_list' => \Phpcmf\Service::M()->dbprefix('member_verify').'.*,'.\Phpcmf\Service::M()->dbprefix('member').'.username',
|
||||
]);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户资料审核' => ['member/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-edit'],
|
||||
]
|
||||
),
|
||||
'field' => $this->my_field,
|
||||
]);
|
||||
}
|
||||
|
||||
// 用户管理
|
||||
public function index() {
|
||||
|
||||
$this->_List();
|
||||
$this->mytable = [
|
||||
'foot_tpl' => '',
|
||||
'link_tpl' => '',
|
||||
'link_var' => 'html = html.replace(/\{id\}/g, row.id);
|
||||
html = html.replace(/\{uid\}/g, row.id);',
|
||||
];
|
||||
$uriprefix = APP_DIR.'/'.\Phpcmf\Service::L('Router')->class;
|
||||
if ($this->_is_admin_auth('del') || $this->_is_admin_auth('edit')) {
|
||||
$this->mytable['foot_tpl'].= '<label class="table_select_all"><input onclick="dr_table_select_all(this)" type="checkbox"><span></span></label>';
|
||||
}
|
||||
if ($this->_is_admin_auth('del')) {
|
||||
$this->mytable['foot_tpl'].= '<label><button type="button" onclick="dr_table_option(\''.(IS_ADMIN ? dr_url($uriprefix.'/del') : dr_member_url($uriprefix.'/del')).'\', \''.dr_lang('你确定要删除它们吗?').'\')" class="btn red btn-sm"> <i class="fa fa-trash"></i> '.dr_lang('删除').'</button></label>';
|
||||
}
|
||||
|
||||
if ($this->_is_admin_auth('edit')) {
|
||||
$this->mytable['link_tpl'].= '<label><a href="'.dr_url($uriprefix.'/edit').'&id={id}" class="btn btn-xs green"> <i class="fa fa-edit"></i> '.dr_lang('审核').'</a></label>';
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mytable' => $this->mytable,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('edit_verify_list.html');
|
||||
}
|
||||
|
||||
// 修改内容
|
||||
public function edit() {
|
||||
list($tpl) = $this->_Post(intval(\Phpcmf\Service::L('input')->get('id')));
|
||||
$verify_msg = [];
|
||||
if ($this->member_cache['config']['verify_msg']) {
|
||||
$msg = @explode(PHP_EOL, $this->member_cache['config']['verify_msg']);
|
||||
$msg && $verify_msg = $msg;
|
||||
}
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'verify_msg' => $verify_msg,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 删除内容
|
||||
public function del() {
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('Input')->get_post_ids(),
|
||||
function($rows) {
|
||||
// 删除前的验证
|
||||
return dr_return_data(1, 'ok', $rows);
|
||||
},
|
||||
function($rows) {
|
||||
// 删除后的处理
|
||||
return dr_return_data(1, 'ok');
|
||||
},
|
||||
\Phpcmf\Service::M()->dbprefix($this->init['table'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
$row = parent::_Data($id);
|
||||
// 这里可以对内容进行格式化显示操处理
|
||||
$data = \Phpcmf\Service::M()->table('member')->get($row['uid']);
|
||||
$row['username'] = $data['username'];
|
||||
$data = dr_string2array($row['content']);
|
||||
$row['name'] = $data['name'];
|
||||
if ($data['info']) {
|
||||
foreach ($data['info'] as $i => $t) {
|
||||
$row[$i] = $t;
|
||||
}
|
||||
}
|
||||
$data = \Phpcmf\Service::M()->table('member_data')->get($row['uid']);
|
||||
if ($data) {
|
||||
foreach ($data as $i => $t) {
|
||||
if (!isset($row[$i])) {
|
||||
$row[$i] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
// 格式化保存数据
|
||||
protected function _Format_Data($id, $data, $old) {
|
||||
|
||||
if ($old['status'] == 2) {
|
||||
$this->_json(0, '已通过内容无法编辑');
|
||||
}
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$save = [
|
||||
'status' => $post['status'] ? 2 : 0,
|
||||
'updatetime' => SYS_TIME,
|
||||
'result' => $post['result'],
|
||||
'content' => dr_array2string([
|
||||
'name' => $post['name'] ? $post['name'] : '',
|
||||
'info' => $data[1],
|
||||
]),
|
||||
];
|
||||
|
||||
|
||||
// 后台提醒
|
||||
\Phpcmf\Service::M('member')->todo_admin_notice('member/edit_verify/edit:id/'.$id, 0);
|
||||
|
||||
// 通知
|
||||
$call = $save;
|
||||
$call['uid'] = $old['uid'];
|
||||
$call['content'] = dr_string2array($call['content']);
|
||||
$call['inputtime'] = $old['inputtime'];
|
||||
if ($post['status']) {
|
||||
if ($post['name']) {
|
||||
if ($this->member_cache['config']['unique_name']
|
||||
&& \Phpcmf\Service::M()->db->table('member')->where('id<>'. $old['uid'])->where('name', $post['name'])->countAllResults()) {
|
||||
$this->_json(0, dr_lang('%s已经存在', MEMBER_CNAME), ['field' => 'name']);
|
||||
}
|
||||
\Phpcmf\Service::M()->table('member')->update($old['uid'], [
|
||||
'name' => dr_strcut(dr_safe_replace($post['name']), 20, ''),
|
||||
]);
|
||||
}
|
||||
$data[1]['is_complete'] = 1;
|
||||
\Phpcmf\Service::M()->table('member_data')->update($old['uid'], $data[1]);
|
||||
\Phpcmf\Service::L('Notice')->send_notice('member_edit_verify_1', $call);
|
||||
} else {
|
||||
\Phpcmf\Service::M()->db->table('member_data')->where('id', $call['uid'])->update(['is_complete' => 0]);
|
||||
\Phpcmf\Service::L('Notice')->send_notice('member_edit_verify_0', $call);
|
||||
}
|
||||
|
||||
return $save;
|
||||
}
|
||||
|
||||
|
||||
// 保存内容
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
return parent::_Save($id, $data, $old, function($id, $data, $old){
|
||||
// 验证数据
|
||||
/*
|
||||
if (!$data[1]['title']) {
|
||||
return dr_return_data(0, '标题不能为空!', ['field' => 'title']);
|
||||
}*/
|
||||
// 保存之前执行的函数,并返回新的数据
|
||||
if (!$id) {
|
||||
// 当提交新数据时,把当前时间插入进去
|
||||
//$data[1]['inputtime'] = SYS_TIME;
|
||||
}
|
||||
|
||||
return dr_return_data(1, null, $data);
|
||||
}, function ($id, $data, $old) {
|
||||
// 保存之后执行的动作
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if ($post['status']) {
|
||||
\Phpcmf\Service::M()->table('member_verify')->delete($id);
|
||||
}
|
||||
|
||||
\Phpcmf\Hooks::trigger('member_verify_after', $data, $old);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Field extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'字段划分' => ['member/field/index', 'fa fa-cog'],
|
||||
'自定义字段' => ['url:'.\Phpcmf\Service::L('Router')->url('field/index', ['rname' => 'member']), 'fa fa-code'],
|
||||
'help' => [531],
|
||||
]
|
||||
),
|
||||
'uriprefix' => 'member/field'
|
||||
]);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$color = $list = $group = [];
|
||||
|
||||
// 字段配置
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'field')->get()->getRowArray();
|
||||
$value = $data ? dr_string2array($data['value']) : [];
|
||||
|
||||
// 注册配置
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'register_field')->get()->getRowArray();
|
||||
$register = $data ? dr_string2array($data['value']) : [];
|
||||
|
||||
// 字段查询
|
||||
$field = \Phpcmf\Service::M()->db->table('field')->where('disabled', 0)->where('relatedname', 'member')->orderBy('displayorder ASC,id ASC')->get()->getResultArray();
|
||||
if ($field) {
|
||||
foreach ($field as $f) {
|
||||
$f['register'] = dr_in_array($f['id'], $register);
|
||||
$f['group'] = $value[$f['id']];
|
||||
$list[$f['fieldname']] = $f;
|
||||
}
|
||||
}
|
||||
|
||||
// 用户组
|
||||
$data = \Phpcmf\Service::M()->db->table('member_group')->orderBy('displayorder ASC,id ASC')->get()->getResultArray();
|
||||
if ($data) {
|
||||
$_color = ['blue', 'red', 'green', 'dark', 'yellow'];
|
||||
foreach ($data as $i => $t) {
|
||||
$group[$t['id']] = $t;
|
||||
$color[$t['id']] = $_color[$i];
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'list' => $list,
|
||||
'group' => $group,
|
||||
'color' => $color,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_field.html');
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('你还没有选择呢'));
|
||||
}
|
||||
|
||||
$gids = \Phpcmf\Service::L('input')->post('groupid');
|
||||
if (!$gids) {
|
||||
$this->_json(0, dr_lang('你还没有选择用户组'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'field')->get()->getRowArray();
|
||||
$value = $data ? dr_string2array($data['value']) : [];
|
||||
|
||||
foreach ($ids as $id) {
|
||||
foreach ($gids as $gid) {
|
||||
$value[$id][$gid] = $gid;
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'field',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('划分成功'));
|
||||
}
|
||||
|
||||
// 注册权限
|
||||
public function reg_edit() {
|
||||
|
||||
$fid = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!$fid) {
|
||||
$this->_json(0, dr_lang('字段id不存在'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'register_field')->get()->getRowArray();
|
||||
$register = $data ? dr_string2array($data['value']) : [];
|
||||
|
||||
if ($register[$fid]) {
|
||||
unset($register[$fid]);
|
||||
$rt = 1;
|
||||
} else {
|
||||
$register[$fid] = $fid;
|
||||
$rt = 0;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'register_field',
|
||||
'value' => dr_array2string($register)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'), ['value' => $rt]);
|
||||
}
|
||||
|
||||
// 用户组划分删除全部
|
||||
public function all_del() {
|
||||
|
||||
$fid = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!$fid) {
|
||||
$this->_json(0, dr_lang('字段id不存在'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'field')->get()->getRowArray();
|
||||
$value = $data ? dr_string2array($data['value']) : [];
|
||||
|
||||
if (isset($value[$fid])) {
|
||||
unset($value[$fid]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'field',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
public function del() {
|
||||
|
||||
$fid = (int)\Phpcmf\Service::L('input')->get('fid');
|
||||
if (!$fid) {
|
||||
$this->_json(0, dr_lang('字段id不存在'));
|
||||
}
|
||||
|
||||
$gid = (int)\Phpcmf\Service::L('input')->get('gid');
|
||||
if (!$gid) {
|
||||
$this->_json(0, dr_lang('用户组id不存在'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'field')->get()->getRowArray();
|
||||
$value = $data ? dr_string2array($data['value']) : [];
|
||||
if (!$value[$fid][$gid]) {
|
||||
$this->_json(0, dr_lang('配置不存在'));
|
||||
}
|
||||
|
||||
unset($value[$fid][$gid]);
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'field',
|
||||
'value' => dr_array2string($value)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('删除成功'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
// 用户组
|
||||
class Group extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
private $type;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
// 表单验证配置
|
||||
$this->form_rule = [
|
||||
'name' => [
|
||||
'name' => '名称',
|
||||
'rule' => [
|
||||
'empty' => dr_lang('名称不能为空')
|
||||
],
|
||||
'filter' => [],
|
||||
'length' => '200'
|
||||
],
|
||||
];
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户组管理' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-users'],
|
||||
'添加组' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
|
||||
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
'等级制度' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/level_index', 'fa fa-list-ol'],
|
||||
'添加等级' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/level_add', 'fa fa-plus'],
|
||||
'修改等级' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/level_edit', 'fa fa-edit'],
|
||||
'help' => [515]
|
||||
]
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
private function _init_group() {
|
||||
$this->type = 1;
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户组');
|
||||
$this->tpl_prefix = 'member_group_';
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'member_group',
|
||||
'sys_field' => [],
|
||||
'order_by' => 'displayorder asc,id asc',
|
||||
'list_field' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
private function _init_level($gid) {
|
||||
|
||||
if (!$gid) {
|
||||
$this->_admin_msg(0, dr_lang('用户组id参数不能为空'));
|
||||
}
|
||||
|
||||
$this->type = 0;
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户组等级');
|
||||
$this->tpl_prefix = 'member_level_';
|
||||
|
||||
$this->my_field = [
|
||||
'stars' => [
|
||||
'ismain' => 1,
|
||||
'name' => '图标',
|
||||
'fieldtype' => 'File',
|
||||
'fieldname' => 'stars',
|
||||
'setting' => ['option' => ['ext' => 'jpg,gif,png,jpeg', 'size' => 10, 'input' => 1]]
|
||||
]
|
||||
];
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'member_level',
|
||||
'field' => $this->my_field,
|
||||
'sys_field' => [],
|
||||
'order_by' => 'displayorder asc,id asc',
|
||||
'list_field' => [],
|
||||
'where_list' => 'gid='.$gid,
|
||||
]);
|
||||
$group = \Phpcmf\Service::M()->table('member_group')->get($gid);
|
||||
$group['setting'] = dr_string2array($group['setting']);
|
||||
|
||||
if ($group['setting']['level']['auto']) {
|
||||
// 自动模式,只有消费额和经验值
|
||||
if ($group['setting']['level']['unit']) {
|
||||
$dwz = dr_lang('消费额');
|
||||
} else {
|
||||
$dwz = SITE_EXPERIENCE;
|
||||
}
|
||||
} else {
|
||||
// 手动模式,只有人民币和积分
|
||||
if ($group['unit']) {
|
||||
$dwz = SITE_SCORE;
|
||||
} else {
|
||||
$dwz = dr_lang('元');
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'dwz' => $dwz,
|
||||
'group' => $group
|
||||
]);
|
||||
}
|
||||
|
||||
// 管理
|
||||
public function index() {
|
||||
$this->_init_group();
|
||||
list($tpl, $data) = $this->_List(null, -1);
|
||||
if ($data['list']) {
|
||||
foreach ($data['list'] as $i => $t) {
|
||||
$data['list'][$i]['level'] = \Phpcmf\Service::M()->table('member_level')->where('gid', $t['id'])->order_by('value asc')->getAll();
|
||||
}
|
||||
\Phpcmf\Service::V()->assign('list', $data['list']);
|
||||
}
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 添加
|
||||
public function add() {
|
||||
$this->_init_group();
|
||||
list($tpl) = $this->_Post(0);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 修改
|
||||
public function edit() {
|
||||
$this->_init_group();
|
||||
$gid = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
list($tpl) = $this->_Post($gid);
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
$is_level = \Phpcmf\Service::M()->table('member_level')->where('gid', $gid)->getRow();
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'is_level' => $is_level,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 排序
|
||||
public function order_edit() {
|
||||
$this->_init_group();
|
||||
$this->_Display_Order(
|
||||
intval(\Phpcmf\Service::L('input')->get('id')),
|
||||
intval(\Phpcmf\Service::L('input')->get('value')),
|
||||
function ($r) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 允许注册
|
||||
public function register_edit() {
|
||||
$this->_init_group();
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = $this->_Data($id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
if (!$data['register']) {
|
||||
$level = \Phpcmf\Service::M()->table('member_level')->where('gid', $id)->order_by('displayorder ASC,id ASC')->getRow();
|
||||
if ($level && !$data['setting']['level']['auto'] && $level['value'] > 0) {
|
||||
$this->_json(0, dr_lang('收费的用户组,不能开启允许注册开关'), $data);
|
||||
} elseif ($data['price'] > 0) {
|
||||
$this->_json(0, dr_lang('收费的用户组,不能开启允许注册开关'), $data);
|
||||
}
|
||||
}
|
||||
|
||||
$value = $data['register'] ? 0 : 1;
|
||||
\Phpcmf\Service::M()->table('member_group')->save($id, 'register', $value);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'), ['value' => $value]);
|
||||
}
|
||||
|
||||
// 允许申请
|
||||
public function apply_edit() {
|
||||
$this->_init_group();
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = $this->_Data($id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
$value = $data['apply'] ? 0 : 1;
|
||||
\Phpcmf\Service::M()->table('member_group')->save($id, 'apply', $value);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
exit($this->_json(1, dr_lang('操作成功'), ['value' => $value]));
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function del() {
|
||||
$this->_init_group();
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
$this->_Del(
|
||||
$ids,
|
||||
null,
|
||||
function ($rows) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
},
|
||||
\Phpcmf\Service::M()->dbprefix($this->init['table'])
|
||||
);
|
||||
}
|
||||
|
||||
// 等级管理
|
||||
public function level_index() {
|
||||
$gid = intval($_GET['gid']);
|
||||
$this->_init_level($gid);;
|
||||
list($tpl) = $this->_List([], -1);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'gid' => $gid,
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户组管理' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-users'],
|
||||
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
'等级制度' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/level_index', 'fa fa-list-ol'],
|
||||
'添加等级' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/level_add{gid='.intval($_GET['gid']).'}', 'fa fa-plus'],
|
||||
]
|
||||
),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 添加等级
|
||||
public function level_add() {
|
||||
$gid = intval($_GET['gid']);
|
||||
$this->_init_level($gid);
|
||||
list($tpl) = $this->_Post(0);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'gid' => $gid,
|
||||
'form' => dr_form_hidden(['gid' => $gid]),
|
||||
'apply' => 1,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 修改等级
|
||||
public function level_edit() {
|
||||
$gid = intval($_GET['gid']);
|
||||
$this->_init_level($gid);
|
||||
list($tpl, $data) = $this->_Post(intval(\Phpcmf\Service::L('input')->get('id')));
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(['gid' => intval($data['gid'])]),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 等级排序
|
||||
public function level_order_edit() {
|
||||
$this->_init_level(intval($_GET['gid']));
|
||||
$this->_Display_Order(
|
||||
intval(\Phpcmf\Service::L('input')->get('id')),
|
||||
intval(\Phpcmf\Service::L('input')->get('value')),
|
||||
function ($r) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 允许申请等级
|
||||
public function apply_level_edit() {
|
||||
$gid = intval($_GET['gid']);
|
||||
$this->_init_level($gid);
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = $this->_Data($id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
$value = $data['apply'] ? 0 : 1;
|
||||
\Phpcmf\Service::M()->table('member_level')->save($id, 'apply', $value);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
exit($this->_json(1, dr_lang('操作成功'), ['value' => $value]));
|
||||
}
|
||||
|
||||
// 删除等级
|
||||
public function level_del() {
|
||||
$gid = intval($_GET['gid']);
|
||||
$this->_init_level($gid);
|
||||
$this->_Del(
|
||||
\Phpcmf\Service::L('input')->get_post_ids(),
|
||||
null,
|
||||
function ($r) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
},
|
||||
\Phpcmf\Service::M()->dbprefix($this->init['table'])
|
||||
);
|
||||
}
|
||||
|
||||
// 保存
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $after = null) {
|
||||
return parent::_Save($id, $data, $old, function($id, $post, $old){
|
||||
$data = \Phpcmf\Service::L('input')->post('data');
|
||||
$setting = \Phpcmf\Service::L('input')->post('setting');
|
||||
$data['setting'] = dr_array2string($setting);
|
||||
if ($this->type) {
|
||||
// 用户组
|
||||
$level = $id ? \Phpcmf\Service::M()->table('member_level')->where('gid', $id)->order_by('displayorder ASC,id ASC')->getRow() : [];
|
||||
if ($level && !$setting['level']['auto'] && $level['value'] > 0 && $data['register']) {
|
||||
return dr_return_data(0, dr_lang('收费的用户组,不能开启允许注册开关'), $data);
|
||||
} elseif ($data['price'] > 0 && $data['register']) {
|
||||
return dr_return_data(0, dr_lang('收费的用户组,不能开启允许注册开关'), $data);
|
||||
}
|
||||
$data['price'] = floatval($data['price']);
|
||||
$data['days'] = intval($data['days']);
|
||||
} else {
|
||||
// 等级
|
||||
$data['gid'] = (int)\Phpcmf\Service::L('input')->post('gid');
|
||||
if (!$data['gid']) {
|
||||
return dr_return_data(0, dr_lang('所属用户组id不存在'), $data);
|
||||
}
|
||||
$data['stars'] = $post[1]['stars'];
|
||||
$data['value'] = intval($data['value']);
|
||||
}
|
||||
!$id && $data['displayorder'] = 0;
|
||||
return dr_return_data(1, null, $data);
|
||||
}, function ($id, $data, $old) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
$data = parent::_Data($id);
|
||||
$data['setting'] = dr_string2array($data['setting']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,790 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
// 会员管理
|
||||
class Home extends \Phpcmf\Table
|
||||
{
|
||||
public $group;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// 不是超级管理员排除角色账号
|
||||
if (!dr_in_array(1, $this->admin['roleid']) && \Phpcmf\Service::M('auth')->is_post_user()) {
|
||||
$this->_admin_msg(0, dr_lang('投稿者无权限操作'));
|
||||
}
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
// 模板前缀(避免混淆)
|
||||
$this->tpl_prefix = 'member_';
|
||||
$this->my_field = array(
|
||||
'username' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('账号'),
|
||||
'fieldname' => 'username',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
)
|
||||
)
|
||||
),
|
||||
'email' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('邮箱'),
|
||||
'fieldname' => 'email',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
)
|
||||
)
|
||||
),
|
||||
'phone' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('手机'),
|
||||
'fieldname' => 'phone',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
)
|
||||
)
|
||||
),
|
||||
'name' => array(
|
||||
'ismain' => 1,
|
||||
'name' => MEMBER_CNAME,
|
||||
'fieldname' => 'name',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户');
|
||||
// 初始化数据表
|
||||
if ($this->member_cache['field']) {
|
||||
foreach ($this->member_cache['field'] as $i => $t) {
|
||||
$this->member_cache['field'][$i]['setting']['validate']['required'] = 0;
|
||||
$this->my_field[$t['fieldname']] = $t;
|
||||
}
|
||||
}
|
||||
if (!isset($this->member_cache['list_field']) || !$this->member_cache['list_field']) {
|
||||
$this->member_cache = \Phpcmf\Service::M('member', 'member')->cache();
|
||||
}
|
||||
$list_field = [
|
||||
'avatar' => array(
|
||||
'use' => '1',
|
||||
'name' => '头像',
|
||||
'width' => '70',
|
||||
'func' => 'dr_member_list_avatar',
|
||||
'center' => '1',
|
||||
),
|
||||
];
|
||||
$this->_init([
|
||||
'table' => 'member',
|
||||
'stable' => 'member_data',
|
||||
'field' => $this->member_cache['field'],
|
||||
'join_list' => ['member_data', 'member.id=member_data.id', 'left'],
|
||||
'order_by' => 'member.id desc',
|
||||
'list_field' => dr_array22array($list_field, $this->member_cache['list_field']),
|
||||
]);
|
||||
$this->group = $this->member_cache['group'];
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户管理' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-user'],
|
||||
'添加用户' => ['add:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/add', 'fa fa-plus'],
|
||||
'批量添加' => ['add:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/all_add', 'fa fa-plus-square', '70%'],
|
||||
'修改' => ['hide:'.APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
]
|
||||
),
|
||||
'group' => $this->group,
|
||||
'field' => $this->my_field,
|
||||
'member_list_field' => dr_array22array(\Phpcmf\Service::L('Field')->member_list_field(), $this->member_cache['field']),
|
||||
'is_show_search_bar' => $this->member_cache['config']['is_show_search_bar'],
|
||||
]);
|
||||
}
|
||||
|
||||
// 用户管理
|
||||
public function index() {
|
||||
|
||||
$p = $where = [];
|
||||
$name = dr_safe_replace(\Phpcmf\Service::L('input')->request('field'));
|
||||
$value = dr_safe_replace(\Phpcmf\Service::L('input')->request('keyword'));
|
||||
|
||||
if ($name && $value && isset($this->my_field[$name])) {
|
||||
if (isset($this->member_cache['field'][$name])) {
|
||||
$where[] = str_replace('`'.\Phpcmf\Service::M()->dbprefix('member_data').'`', 'member_data', \Phpcmf\Service::M()->_where(
|
||||
\Phpcmf\Service::M()->dbprefix('member_data'),
|
||||
$name,
|
||||
$value,
|
||||
$this->member_cache['field'][$name],
|
||||
1
|
||||
));
|
||||
unset($this->init['field'][$name]);
|
||||
} else {
|
||||
$where[] = '`'.$name.'` LIKE "%'.$value.'%"';
|
||||
}
|
||||
$p[$name] = $value;
|
||||
}
|
||||
|
||||
$groupid = \Phpcmf\Service::L('input')->request('groupid');
|
||||
if ($groupid && is_array($groupid)) {
|
||||
$in = [];
|
||||
foreach ($groupid as $gid) {
|
||||
$gid = intval($gid);
|
||||
if ($gid) {
|
||||
$in[] = $gid;
|
||||
}
|
||||
}
|
||||
if ($in) {
|
||||
$where[] = \Phpcmf\Service::M()->dbprefix('member').'.id IN (select uid from `'.\Phpcmf\Service::M()->dbprefix('member_group_index').'` where gid in ('.implode(',', $in).'))';
|
||||
$p['groupid'] = $in;
|
||||
}
|
||||
}
|
||||
|
||||
$sname = [
|
||||
'is_lock' => '账号锁定',
|
||||
'is_mobile' => '手机认证',
|
||||
'is_email' => '邮箱认证',
|
||||
'is_complete' => '完善资料',
|
||||
];
|
||||
$status = \Phpcmf\Service::L('input')->request('status');
|
||||
if ($status) {
|
||||
foreach ($status as $v) {
|
||||
if (isset($sname[$v])) {
|
||||
$where[] = 'member_data.'.$v.' = 1';
|
||||
}
|
||||
}
|
||||
$p['status'] = $status;
|
||||
}
|
||||
|
||||
// 不是超级管理员排除角色账号
|
||||
if (!dr_in_array(1, $this->admin['roleid'])) {
|
||||
$where[] = 'member.id NOT IN (select uid from `'.\Phpcmf\Service::M()->dbprefix('admin_role_index').'` where uid<> '.$this->uid.')';
|
||||
}
|
||||
|
||||
$rs = \Phpcmf\Hooks::trigger_callback('admin_member_list_where');
|
||||
if ($rs && isset($rs['code']) && $rs['code']) {
|
||||
$where[] = $rs['data']['where'];
|
||||
}
|
||||
|
||||
$where && \Phpcmf\Service::M()->set_where_list(implode(' AND ', $where));
|
||||
|
||||
$this->field = dr_array22array(\Phpcmf\Service::L('Field')->member_list_field(), $this->my_field);
|
||||
$this->is_ajax_list = true;
|
||||
list($tpl, $data) = $this->_List($p);
|
||||
|
||||
$this->mytable = [
|
||||
'foot_tpl' => '',
|
||||
'link_tpl' => '',
|
||||
'link_var' => 'html = html.replace(/\{id\}/g, row.id);
|
||||
html = html.replace(/\{uid\}/g, row.id);',
|
||||
];
|
||||
$uriprefix = APP_DIR.'/'.\Phpcmf\Service::L('Router')->class;
|
||||
if ($this->_is_admin_auth('del') || $this->_is_admin_auth('edit')) {
|
||||
$this->mytable['foot_tpl'].= '<label class="table_select_all"><input onclick="dr_table_select_all(this)" type="checkbox"><span></span></label>';
|
||||
}
|
||||
if ($this->_is_admin_auth('del')) {
|
||||
$this->mytable['foot_tpl'].= '<label><button type="button" onclick="dr_ajax_option_user(\''.dr_url('member/home/del').'\', 1)" class="btn red btn-sm"> <i class="fa fa-trash"></i> '.dr_lang('删除').'</button></label>';
|
||||
}
|
||||
|
||||
if ($this->_is_admin_auth('edit')) {
|
||||
$this->mytable['link_tpl'].= '<label><a href="javascript:dr_iframe_show(\''.dr_lang('登录记录').'\', \''.dr_url($uriprefix.'/login_index').'&id={id}\', \'80%\')" class="btn btn-xs blue"> <i class="fa fa-calendar"></i> '.dr_lang('记录').'</a></label>';
|
||||
$this->mytable['link_tpl'].= '<label><a href="'.dr_url($uriprefix.'/edit').'&id={id}" class="btn btn-xs red"> <i class="fa fa-edit"></i> '.dr_lang('修改').'</a></label>';
|
||||
$this->mytable['link_tpl'].= '<label><a href="javascript:dr_iframe(\''.dr_lang('设置用户组').'\', \''.dr_url($uriprefix.'/group_edit').'&id={id}\', \'60%\')" class="btn btn-xs dark"> <i class="fa fa-users"></i> '.dr_lang('权限').'</a></label>';
|
||||
$this->mytable['link_tpl'].= '<label><a href="'.dr_url('api/alogin').'&id={id}" class="btn btn-xs red" target="_blank"> <i class="fa fa-user"></i> '.dr_lang('登录').'</a></label>';
|
||||
|
||||
$this->mytable['foot_tpl'].= '
|
||||
<label>
|
||||
<select name="groupid" class="form-control">
|
||||
<option value=""> -- </option>';
|
||||
foreach ($this->group as $t) {
|
||||
$this->mytable['foot_tpl'].= '<option value="'.$t['id'].'" '.($data['param']['groupid'] == $t['id'] ? ' selected' : '').'>'.dr_lang($t['name']).'</option> ';
|
||||
}
|
||||
$this->mytable['foot_tpl'].= '
|
||||
</select>
|
||||
</label>
|
||||
<label><button type="button" onclick="dr_ajax_option(\''.dr_url('member/home/group_all_edit').'\', \''.dr_lang('你确定要这样操作吗?').'\', 1)" class="btn green btn-sm"> <i class="fa fa-edit"></i> '.dr_lang('更改').'</button></label>
|
||||
';
|
||||
|
||||
$clink = $this->_app_clink('member');
|
||||
if ($clink) {
|
||||
foreach ($clink as $a) {
|
||||
if ($a['model'] && $a['check']
|
||||
&& method_exists($a['model'], $a['check']) && call_user_func(array($a['model'], $a['check']), APP_DIR, []) == 0) {
|
||||
continue;
|
||||
}
|
||||
$this->mytable['link_tpl'].= '<label><a class="btn '.$a['color'].' btn-xs" href="'.$a['url'].'"><i class="'.$a['icon'].'"></i> '.dr_lang($a['name']);
|
||||
if ($a['field'] && \Phpcmf\Service::M()->is_field_exists($this->init['table'], $a['field'])) {
|
||||
$this->mytable['link_tpl'].= '({'.$a['field'].'})';
|
||||
$this->mytable['link_var'].= 'html = html.replace(/\{'.$a['field'].'\}/g, row.'.$a['field'].');';
|
||||
}
|
||||
$this->mytable['link_tpl'].= '</a></label>';
|
||||
}
|
||||
}
|
||||
|
||||
$cbottom = $this->_app_cbottom('member');
|
||||
if ($cbottom) {
|
||||
$this->mytable['foot_tpl'].= '<label>
|
||||
<div class="btn-group dropup">
|
||||
<a class="btn blue btn-sm dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true" aria-expanded="false" href="javascript:;"> '.dr_lang('批量').'
|
||||
<i class="fa fa-angle-up"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu">';
|
||||
foreach ($cbottom as $a) {
|
||||
$this->mytable['foot_tpl'].= '<li>
|
||||
<a href="'.urldecode($a['url']).'"> <i class="'.$a['icon'].'"></i> '.dr_lang($a['name']).' </a>
|
||||
</li>';
|
||||
}
|
||||
$this->mytable['foot_tpl'].= '
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
</label>';
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mytable' => $this->mytable,
|
||||
'status' => $sname,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display($tpl);
|
||||
}
|
||||
|
||||
// 修改账号
|
||||
public function username_edit() {
|
||||
|
||||
$uid = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$member = dr_member_info($uid);
|
||||
if (!$member) {
|
||||
$this->_json(0, dr_lang('该用户不存在'));
|
||||
}
|
||||
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_admin_msg(0, dr_lang('无权限操作其他管理员账号'));
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$name = trim(dr_safe_filename(\Phpcmf\Service::L('input')->post('name')));
|
||||
if (!$name) {
|
||||
$this->_json(0, dr_lang('新账号不能为空'));
|
||||
} elseif ($member['username'] == $name) {
|
||||
$this->_json(0, dr_lang('新账号不能和原始账号相同'));
|
||||
} elseif (\Phpcmf\Service::M()->table('member')->where('username', $name)->counts()) {
|
||||
$this->_json(0, dr_lang('新账号%s已经注册', $name), ['field' => 'name']);
|
||||
}
|
||||
$rt = \Phpcmf\Service::L('form')->check_username($name);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg'], ['field' => 'name']);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->edit_username($uid, $name);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'member' => $member,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_edit_username.html');exit;
|
||||
}
|
||||
|
||||
// 后台添加
|
||||
public function add() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (empty($post['password'])) {
|
||||
$this->_json(0, dr_lang('密码必须填写'), ['field' => 'password']);
|
||||
} else {
|
||||
$rt = \Phpcmf\Service::L('Form')->check_password((string)$post['password'], (string)$post['username']);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg'], ['field' => 'password']);
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('member')->register((int)$post['groupid'], [
|
||||
'username' => (string)$post['username'],
|
||||
'phone' => (string)$post['phone'],
|
||||
'email' => (string)$post['email'],
|
||||
'name' => (string)$post['name'],
|
||||
'password' => dr_safe_password($post['password']),
|
||||
]);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg'], ['field' => $rt['data']['field']]);
|
||||
}
|
||||
}
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_add.html');exit;
|
||||
}
|
||||
|
||||
// 后台添加
|
||||
public function all_add() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!$post['all']) {
|
||||
$this->_json(0, dr_lang('用户集未填写'), ['field' => 'all']);
|
||||
}
|
||||
|
||||
$all = explode(PHP_EOL, $post['all']);
|
||||
$error = $ok = 0;
|
||||
foreach ($all as $t) {
|
||||
list($username, $password, $email, $phone, $name) = explode('|', $t);
|
||||
$name = trim($name == 'null' ? '' : (string)$name);
|
||||
$phone = trim($phone == 'null' ? '' : (string)$phone);
|
||||
$email = trim($email == 'null' ? '' : (string)$email);
|
||||
$username = trim($username == 'null' ? '' : (string)$username);
|
||||
$password = trim($password == 'null' ? '' : (string)$password);
|
||||
$rt = \Phpcmf\Service::L('Form')->check_password($password, $username);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg'], ['field' => 'password']);
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('member')->register((int)$post['groupid'], [
|
||||
'username' => (string)$username,
|
||||
'phone' => (string)$phone,
|
||||
'email' => (string)$email,
|
||||
'name' => (string)$name,
|
||||
'password' => dr_safe_password($password),
|
||||
]);
|
||||
if ($rt['code']) {
|
||||
$ok ++;
|
||||
} else {
|
||||
$error ++;
|
||||
log_message('error', dr_lang('后台批量注册会员失败(%s):%s', trim($t), $rt['msg']));
|
||||
}
|
||||
}
|
||||
$this->_json(1, dr_lang('批量注册%s个用户,失败%s个(查看系统错误日志)', $ok, $error));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_add_all.html');exit;
|
||||
}
|
||||
|
||||
// 后台修改
|
||||
public function edit() {
|
||||
|
||||
$uid = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
if (!$uid) {
|
||||
$this->_admin_msg(0, dr_lang('用户uid不存在'));
|
||||
}
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_admin_msg(0, dr_lang('无权限操作其他管理员账号'));
|
||||
}
|
||||
|
||||
$field = [];
|
||||
if (dr_in_array(1, $this->admin['roleid'])) {
|
||||
// 超级管理员,显示全部字段并提示
|
||||
if ($this->member_cache['field']) {
|
||||
$member = \Phpcmf\Service::M('member')->get_member($uid);
|
||||
$fieldid = [];
|
||||
if ($member['groupid']) {
|
||||
foreach ($member['groupid'] as $gid) {
|
||||
if ($this->member_cache['group'][$gid]['field']) {
|
||||
$fieldid = dr_array2array($fieldid, $this->member_cache['group'][$gid]['field']);
|
||||
}
|
||||
}
|
||||
if ($fieldid) {
|
||||
foreach ($this->member_cache['field'] as $fname => $t) {
|
||||
if (!in_array($fname, $fieldid)) {
|
||||
$field[$fname] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 子管理员排查不可用的字段
|
||||
$myfield = [];
|
||||
$groupid = \Phpcmf\Service::M()->table('member_group_index')->where('uid', $uid)->getAll();
|
||||
if ($groupid && $this->member_cache['field']) {
|
||||
$fieldid = [];
|
||||
foreach ($groupid as $t) {
|
||||
if ($this->member_cache['group'][$t['gid']]['field']) {
|
||||
$fieldid = dr_array2array($fieldid, $this->member_cache['group'][$t['gid']]['field']);
|
||||
}
|
||||
}
|
||||
if ($fieldid) {
|
||||
foreach ($this->member_cache['field'] as $fname => $t) {
|
||||
if (in_array($fname, $fieldid)) {
|
||||
$myfield[$fname] = $t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_init([
|
||||
'table' => 'member',
|
||||
'field' => $field,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->_Post($uid);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'uid' => $uid,
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'field' => $field,
|
||||
'oauth' => \Phpcmf\Service::M()->table('member_oauth')->where('uid', $uid)->getAll(),
|
||||
'mygroup' => \Phpcmf\Service::M()->table('member_group_index')->where('uid', $uid)->getAll(),
|
||||
'regfield' => [
|
||||
'regip' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('注册地区'),
|
||||
'fieldtype' => 'Textbtn',
|
||||
'fieldname' => 'regip',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 320,
|
||||
'name' => '查看',
|
||||
'icon' => 'fa fa-arrow-right',
|
||||
'func' => 'dr_show_ip',
|
||||
'value' => \Phpcmf\Service::L('input')->ip_info()
|
||||
)
|
||||
)
|
||||
),
|
||||
'regtime' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('注册时间'),
|
||||
'fieldtype' => 'Date',
|
||||
'fieldname' => 'regtime',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 280,
|
||||
'value' => 'SYS_TIME',
|
||||
'is_left' => 0,
|
||||
)
|
||||
)
|
||||
),
|
||||
],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_edit.html');
|
||||
}
|
||||
|
||||
// 后台删除
|
||||
public function del() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (dr_in_array(1, $ids)) {
|
||||
$this->_json(0, dr_lang('创始人账号不能删除'));
|
||||
} elseif (dr_in_array($this->uid, $ids)) {
|
||||
$this->_json(0, dr_lang('不能删除自己'));
|
||||
}
|
||||
|
||||
// 删除时同步删除很多内容
|
||||
$this->_Del(
|
||||
$ids,
|
||||
function ($rows) {
|
||||
foreach ($rows as $t) {
|
||||
if (!isset($this->admin['role'][1])
|
||||
&& \Phpcmf\Service::M()->table('admin_role_index')->where('uid', intval($t['id']))->where('roleid', 1)->counts()) {
|
||||
return dr_return_data(0, dr_lang('账号[%s]不能删除', $t['username']));
|
||||
}
|
||||
}
|
||||
return dr_return_data(1, 'ok');
|
||||
},
|
||||
function ($rows) {
|
||||
$ids = [];
|
||||
foreach ($rows as $t) {
|
||||
$id = intval($t['id']);
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($id)) {
|
||||
continue;
|
||||
}
|
||||
$ids[] = $id;
|
||||
\Phpcmf\Service::M('member')->member_delete($id, (int)\Phpcmf\Service::L('input')->get('sync'));
|
||||
|
||||
}
|
||||
return dr_return_data(1, 'ok');
|
||||
},
|
||||
(int)\Phpcmf\Service::L('input')->get('sync') ? \Phpcmf\Service::M()->dbprefix('member') : 0
|
||||
);
|
||||
}
|
||||
|
||||
// 解绑
|
||||
public function jb_del() {
|
||||
|
||||
$uid = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_json(0, dr_lang('无权限操作其他管理员账号'));
|
||||
}
|
||||
|
||||
$tid = dr_safe_filename(\Phpcmf\Service::L('input')->get('tid'));
|
||||
|
||||
\Phpcmf\Service::M()->table('member_oauth')->where('uid', $uid)->where('oauth', $tid)->delete();
|
||||
|
||||
if ($tid == 'wechat' && dr_is_app('weixin')) {
|
||||
// 判断微信
|
||||
\Phpcmf\Service::C()->init_file('weixin');
|
||||
\Phpcmf\Service::M()->table(weixin_wxtable('user'))->where('uid', $uid)->delete();
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->clear_cache($uid);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'), [
|
||||
'url' => dr_url(APP_DIR.'/home/edit', ['id'=> $uid, 'page'=>4])
|
||||
]);
|
||||
}
|
||||
|
||||
// 登录记录
|
||||
public function login_index() {
|
||||
|
||||
$uid = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_admin_msg(0, dr_lang('无权限操作其他管理员账号'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'list' => \Phpcmf\Service::M()->table('member_login')->where('uid', $uid)->order_by('logintime desc')->getAll(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_login.html');exit;
|
||||
}
|
||||
|
||||
// 删除用户组
|
||||
public function group_del() {
|
||||
|
||||
$gid = (int)\Phpcmf\Service::L('input')->get('gid');
|
||||
$uid = (int)\Phpcmf\Service::L('input')->get('uid');
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_json(0, dr_lang('无权限操作其他管理员账号'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->delete_group($uid, $gid, 1);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
// 设置用户组
|
||||
public function group_edit() {
|
||||
|
||||
$uid = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_admin_msg(0, dr_lang('无权限操作其他管理员账号'));
|
||||
}
|
||||
|
||||
$groups = \Phpcmf\Service::M('member')->update_group(
|
||||
\Phpcmf\Service::M()->table('member')->get($uid),
|
||||
\Phpcmf\Service::M()->table('member_group_index')->where('uid', $uid)->getAll()
|
||||
);
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!$post) {
|
||||
$this->_json(0, dr_lang('用户组不存在'));
|
||||
} elseif (!$this->member_cache['config']['groups'] && dr_count($groups) > 1) {
|
||||
$this->_json(0, dr_lang('不能同时拥有多个用户组'));
|
||||
}
|
||||
foreach ($post as $gid => $t) {
|
||||
// 手动更新等级
|
||||
if ($t['lid'] && $t['lid'] != $groups[$gid]['lid']) {
|
||||
\Phpcmf\Service::M('member')->update_level($uid, $gid, $t['lid']);
|
||||
}
|
||||
$stime = (int)strtotime($t['stime']);
|
||||
$etime = (int)strtotime($t['etime']);
|
||||
// 设置时间
|
||||
\Phpcmf\Service::M()->db->table('member_group_index')->where('uid', $uid)->where('gid', $gid)->update([
|
||||
'stime' => $t['stime'] ? $stime : SYS_TIME,
|
||||
'etime' => $t['etime'] ? ($stime > $etime ? 0 : $etime) : 0,
|
||||
]);
|
||||
}
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'id' => $uid,
|
||||
'form' => dr_form_hidden(),
|
||||
'mygroup' => $groups,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_group.html');exit;
|
||||
}
|
||||
|
||||
// 批量设置用户组
|
||||
public function group_all_edit() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('所选用户不存在'));
|
||||
}
|
||||
|
||||
$gid = \Phpcmf\Service::L('input')->post('groupid');
|
||||
if (!$gid) {
|
||||
$this->_json(0, dr_lang('所选用户组不存在'));
|
||||
}
|
||||
|
||||
// 验证用户
|
||||
foreach ($ids as $i) {
|
||||
$uid = intval($i);
|
||||
if (!$uid) {
|
||||
$this->_json(0, dr_lang('所选用户不存在'));
|
||||
} elseif (!\Phpcmf\Service::M('auth')->cleck_edit_member($uid)) {
|
||||
$this->_json(0, dr_lang('无权限操作用户#%s', $uid));
|
||||
} elseif (!$this->member_cache['config']['groups']
|
||||
&& dr_count(\Phpcmf\Service::M()->table('member_group_index')->where('uid', $uid)->getAll()) > 1) {
|
||||
$this->_json(0, dr_lang('用户#%s不能同时拥有多个用户组', $uid));
|
||||
} elseif (\Phpcmf\Service::M()->counts('member_group_index', 'uid='.$uid.' and gid='.$gid)) {
|
||||
$this->_json(0, dr_lang('用户#%s已经拥有了此用户组', $uid));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($ids as $i) {
|
||||
\Phpcmf\Service::M('member')->insert_group(intval($i), $gid);
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('共执行%s个用户', dr_count($ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台授权登录
|
||||
*/
|
||||
public function alogin_index() {
|
||||
$this->_msg(1, dr_lang('正在授权登录此用户...'), dr_url('api/alogin', ['id' => intval(\Phpcmf\Service::L('input')->get('id'))]), 0);
|
||||
}
|
||||
|
||||
// 重写存储值
|
||||
protected function _Save_Value($id, $name, $value, $after = null, $before = null) {
|
||||
|
||||
\Phpcmf\Service::M('member')->clear_cache($id);
|
||||
|
||||
if ($name == 'username') {
|
||||
if (!$value) {
|
||||
$this->_json(0, dr_lang('新账号不能为空'));
|
||||
} elseif ($this->member['username'] == $value) {
|
||||
$this->_json(0, dr_lang('新账号不能和原始账号相同'));
|
||||
} elseif (\Phpcmf\Service::M()->db->table('member')->where('username', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('新账号%s已经注册', $value), ['field' => 'name']);
|
||||
}
|
||||
$rt = \Phpcmf\Service::L('form')->check_username($value);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['code'], ['field' => 'name']);
|
||||
}
|
||||
\Phpcmf\Service::M('member')->edit_username($id, $value);
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
} elseif ($name == 'email' ) {
|
||||
if (!\Phpcmf\Service::L('Form')->check_email($value)) {
|
||||
$this->_json(0, dr_lang('邮箱格式不正确'), ['field' => 'email']);
|
||||
} elseif (\Phpcmf\Service::M()->db->table('member')->where('id<>'. $id)->where('email', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('邮箱%s已经注册', $value), ['field' => 'email']);
|
||||
}
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $id)->update(['email' => $value]);
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
} elseif ($name == 'phone' ) {
|
||||
if (!\Phpcmf\Service::L('Form')->check_phone($value)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
|
||||
} elseif (\Phpcmf\Service::M()->db->table('member')->where('id<>'. $id)->where('phone', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('手机号码%s已经注册', $value), ['field' => 'phone']);
|
||||
}
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $id)->update(['phone' => $value]);
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
} elseif ($name == 'money') {
|
||||
$this->_json(0, dr_lang('金额不能变更'));
|
||||
} elseif ($name == 'score') {
|
||||
$this->_json(0, dr_lang('积分不能变更'));
|
||||
}
|
||||
|
||||
|
||||
parent::_Save_Value($id, $name, $value, $after, $before);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
* $id 内容id,新增为0
|
||||
* */
|
||||
protected function _Data($id = 0) {
|
||||
$data = parent::_Data($id);
|
||||
$data2 = \Phpcmf\Service::M()->db->table('member_data')->where('id', $id)->get()->getRowArray();
|
||||
if ($data2) {
|
||||
$data = $data + $data2;
|
||||
$data['is_mobile2'] = $data['is_mobile'];
|
||||
unset($data['is_mobile']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存内容
|
||||
* $id 内容id,新增为0
|
||||
* $data 提交内容数组,留空为自动获取
|
||||
* $func 格式化提交的数据
|
||||
* */
|
||||
protected function _Save($id = 0, $data = [], $old = [], $func = null, $func2 = null) {
|
||||
|
||||
return parent::_Save($id, $data, $old,
|
||||
function ($id, $data, $old){
|
||||
// 保存之前的判断
|
||||
$member = \Phpcmf\Service::L('input')->post('member');
|
||||
if ($member['email'] && !\Phpcmf\Service::L('Form')->check_email($member['email'])) {
|
||||
$this->_json(0, dr_lang('邮箱格式不正确'), ['field' => 'email']);
|
||||
} elseif ($member['phone'] && !\Phpcmf\Service::L('Form')->check_phone($member['phone'])) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
|
||||
} elseif ($member['email'] && \Phpcmf\Service::M()->db->table('member')->where('id<>'. $id)->where('email', $member['email'])->countAllResults()) {
|
||||
return dr_return_data(0, dr_lang('邮箱%s已经注册', $member['email']), ['field' => 'email']);
|
||||
} elseif ($member['phone'] && \Phpcmf\Service::M()->db->table('member')->where('id<>'. $id)->where('phone', $member['phone'])->countAllResults()) {
|
||||
return dr_return_data(0, dr_lang('手机号码%s已经注册', $member['phone']), ['field' => 'phone']);
|
||||
} elseif ($this->member_cache['config']['unique_name']
|
||||
&& $member['name'] && \Phpcmf\Service::M()->db->table('member')->where('id<>'. $id)->where('name', $member['name'])->countAllResults()) {
|
||||
return dr_return_data(0, dr_lang('姓名%s已经注册', $member['name']), ['field' => 'name']);
|
||||
}
|
||||
$password = \Phpcmf\Service::L('input')->post('password');
|
||||
if ($password) {
|
||||
$rt = \Phpcmf\Service::L('Form')->check_password($password, $old['username']);
|
||||
if (!$rt['code']) {
|
||||
return dr_return_data(0, $rt['msg'], ['field' => 'password']);
|
||||
}
|
||||
}
|
||||
|
||||
// 保存附表内容
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$status = \Phpcmf\Service::L('input')->post('status');
|
||||
|
||||
$member['regip'] = $post['regip'];
|
||||
$member['regtime'] = strtotime($post['regtime']);
|
||||
|
||||
$member_data = $data[1] ? $data[1] : [];
|
||||
$member_data['is_lock'] = isset($status['is_lock']) ? (int)$status['is_lock'] : 0;
|
||||
$member_data['is_mobile'] = isset($status['is_mobile']) ? (int)$status['is_mobile'] : 0;
|
||||
$member_data['is_email'] = isset($status['is_email']) ? (int)$status['is_email'] : 0;
|
||||
$member_data['is_verify'] = isset($status['is_verify']) ? (int)$status['is_verify'] : 0;
|
||||
$member_data['is_complete'] = isset($status['is_complete']) ? (int)$status['is_complete'] : 0;
|
||||
$member_data['is_avatar'] = isset($status['is_avatar']) ? (int)$status['is_avatar'] : 0;
|
||||
\Phpcmf\Service::M()->table('member_data')->update($id, $member_data);
|
||||
return dr_return_data(1, '', [1 => $member]);
|
||||
},
|
||||
function ($id, $data, $old) {
|
||||
// 保存之后
|
||||
// 修改密码
|
||||
$password = \Phpcmf\Service::L('input')->post('password');
|
||||
if ($password) {
|
||||
$member = \Phpcmf\Service::M()->table('member')->get($id);
|
||||
\Phpcmf\Service::M('member')->edit_password($member, $password);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->clear_cache($id, $old ? $old['username'] : '');
|
||||
|
||||
// 审核状态
|
||||
$status = \Phpcmf\Service::L('input')->post('status');
|
||||
if ($status && $old && isset($old['is_verify']) && $old['is_verify'] == 0 && $status['is_verify'] == 1) {
|
||||
\Phpcmf\Service::M('member')->verify_member($id);
|
||||
}
|
||||
|
||||
\Phpcmf\Hooks::trigger('member_edit_after', $data, $old);
|
||||
|
||||
return $data;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Menu extends \Phpcmf\Common
|
||||
{
|
||||
private $form; // 表单验证配置
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
\Phpcmf\Service::V()->assign('menu', \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户中心菜单' => ['member/menu/index', 'fa fa-list-alt'],
|
||||
'初始化菜单' => ['ajax:member/menu/init', 'fa fa-refresh'],
|
||||
'help' => [381],
|
||||
]
|
||||
));
|
||||
// 表单验证配置
|
||||
$this->form = [
|
||||
'name' => [
|
||||
'name' => '菜单名称',
|
||||
'rule' => [
|
||||
'empty' => dr_lang('菜单名称不能为空')
|
||||
],
|
||||
'filter' => [],
|
||||
'length' => '200'
|
||||
],
|
||||
'icon' => [
|
||||
'name' => '菜单图标',
|
||||
'rule' => [
|
||||
'empty' => dr_lang('菜单图标不能为空')
|
||||
],
|
||||
'filter' => [],
|
||||
'length' => '100'
|
||||
],
|
||||
'uri' => [
|
||||
'name' => '系统路径',
|
||||
'rule' => [
|
||||
'empty' => dr_lang('系统路径不能为空')
|
||||
],
|
||||
'filter' => [],
|
||||
'length' => '200'
|
||||
],
|
||||
'url' => [
|
||||
'name' => '实际地址',
|
||||
'rule' => [
|
||||
'empty' => dr_lang('实际地址不能为空')
|
||||
],
|
||||
'filter' => [
|
||||
'url'
|
||||
],
|
||||
'length' => '200'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
if (!function_exists('dr_client_data')) {
|
||||
$this->_admin_msg(0, 'CMS主程序版本过低,需要升级到最新版');
|
||||
}
|
||||
|
||||
$table = \Phpcmf\Service::M()->dbprefix('member_menu');
|
||||
if (\Phpcmf\Service::M()->is_table_exists($table) && !\Phpcmf\Service::M()->is_field_exists($table, 'client')) {
|
||||
\Phpcmf\Service::M('table')->add_field($table, 'client', 'TEXT', 'NOT NULL', '');
|
||||
}
|
||||
|
||||
// 用户组
|
||||
$group = $color = [];
|
||||
$data = \Phpcmf\Service::M()->db->table('member_group')->orderBy('displayorder ASC,id ASC')->get()->getResultArray();
|
||||
if ($data) {
|
||||
foreach ($data as $i => $t) {
|
||||
$group[$t['id']] = $t;
|
||||
}
|
||||
}
|
||||
|
||||
// 终端
|
||||
$client = dr_client_data();
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'data' => \Phpcmf\Service::M('Menu')->gets('member'),
|
||||
'group' => $group,
|
||||
'color' => ['blue', 'red', 'green', 'dark', 'yellow'],
|
||||
'client' => $client,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_menu_list.html');
|
||||
}
|
||||
|
||||
public function group_add() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('你还没有选择呢'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_menu')->whereIN('id', $ids)->get()->getResultArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('无可用菜单'));
|
||||
}
|
||||
|
||||
$gids = \Phpcmf\Service::L('input')->post('groupid');
|
||||
if (!$gids) {
|
||||
foreach ($data as $t) {
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $t['id'])->update([
|
||||
'group' => ''
|
||||
]);
|
||||
}
|
||||
$this->_json(1, dr_lang('取消成功'));
|
||||
}
|
||||
|
||||
foreach ($data as $t) {
|
||||
$value = dr_string2array($t['group']);
|
||||
foreach ($gids as $gid) {
|
||||
$value[$gid] = $gid;
|
||||
}
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $t['id'])->update([
|
||||
'group' => dr_array2string($value)
|
||||
]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('划分成功'));
|
||||
}
|
||||
|
||||
public function group_del() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = \Phpcmf\Service::M('Menu')->getRowData('member', $id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('菜单不存在'));
|
||||
}
|
||||
|
||||
$gid = (int)\Phpcmf\Service::L('input')->get('gid');
|
||||
if (!$gid) {
|
||||
$this->_json(0, dr_lang('用户组id不存在'));
|
||||
}
|
||||
|
||||
$value = dr_string2array($data['group']);
|
||||
unset($value[$gid]);
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $id)->update([
|
||||
'group' => dr_array2string($value)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('删除成功'));
|
||||
}
|
||||
|
||||
public function site_add() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('你还没有选择呢'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_menu')->whereIN('id', $ids)->get()->getResultArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('无可用菜单'));
|
||||
}
|
||||
|
||||
$sids = \Phpcmf\Service::L('input')->post('siteid');
|
||||
if (!$sids) {
|
||||
foreach ($data as $t) {
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $t['id'])->update([
|
||||
'site' => ''
|
||||
]);
|
||||
}
|
||||
$this->_json(1, dr_lang('取消成功'));
|
||||
}
|
||||
|
||||
foreach ($data as $t) {
|
||||
$value = dr_string2array($t['site']);
|
||||
foreach ($sids as $sid) {
|
||||
$value[$sid] = $sid;
|
||||
}
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $t['id'])->update([
|
||||
'site' => dr_array2string($value)
|
||||
]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('划分成功'));
|
||||
}
|
||||
|
||||
public function site_del() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = \Phpcmf\Service::M('Menu')->getRowData('member', $id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('菜单不存在'));
|
||||
}
|
||||
|
||||
$sid = (int)\Phpcmf\Service::L('input')->get('sid');
|
||||
if (!$sid) {
|
||||
$this->_json(0, dr_lang('站点id不存在'));
|
||||
}
|
||||
|
||||
$value = dr_string2array($data['site']);
|
||||
unset($value[$sid]);
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $id)->update([
|
||||
'site' => dr_array2string($value)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('删除成功'));
|
||||
}
|
||||
|
||||
public function client_add() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('你还没有选择呢'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_menu')->whereIN('id', $ids)->get()->getResultArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('无可用菜单'));
|
||||
}
|
||||
|
||||
$sids = \Phpcmf\Service::L('input')->post('clientid');
|
||||
if (!$sids) {
|
||||
foreach ($data as $t) {
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $t['id'])->update([
|
||||
'client' => ''
|
||||
]);
|
||||
}
|
||||
$this->_json(1, dr_lang('取消成功'));
|
||||
}
|
||||
|
||||
foreach ($data as $t) {
|
||||
$value = dr_string2array($t['client']);
|
||||
foreach ($sids as $sid) {
|
||||
$value[$sid] = $sid;
|
||||
}
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $t['id'])->update([
|
||||
'client' => dr_array2string($value)
|
||||
]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('划分成功'));
|
||||
}
|
||||
|
||||
public function client_del() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = \Phpcmf\Service::M('Menu')->getRowData('member', $id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('菜单不存在'));
|
||||
}
|
||||
|
||||
$sid = \Phpcmf\Service::L('input')->get('sid');
|
||||
if (!$sid) {
|
||||
$this->_json(0, dr_lang('终端id不存在'));
|
||||
}
|
||||
|
||||
$value = dr_string2array($data['client']);
|
||||
unset($value[$sid]);
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member_menu')->where('id', $id)->update([
|
||||
'client' => dr_array2string($value)
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('删除成功'));
|
||||
}
|
||||
|
||||
public function add() {
|
||||
|
||||
$pid = intval(\Phpcmf\Service::L('input')->get('pid'));
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$data = \Phpcmf\Service::L('input')->post('data');
|
||||
$data = $this->_validation($data);
|
||||
\Phpcmf\Service::L('input')->system_log('添加用户中心菜单: '.$data['name']);
|
||||
$rt = \Phpcmf\Service::M('Menu')->_add('member', $pid, $data);
|
||||
if ($rt['code']) {
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'top' => \Phpcmf\Service::M('Menu')->get_top('member'),
|
||||
'type' => $pid,
|
||||
'form' => dr_form_hidden()
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_menu_add.html');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$data = \Phpcmf\Service::M('Menu')->getRowData('member', $id);
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $id));
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$data = \Phpcmf\Service::L('input')->post('data');
|
||||
$data = $this->_validation($data);
|
||||
if ($data['uri']
|
||||
&& \Phpcmf\Service::M()->table('member_menu')->where('id<>'.$id)->where('uri', $data['uri'])->counts()) {
|
||||
// 链接菜单判断重复
|
||||
$this->_json(0, dr_lang('系统路径已经存在'), ['field' => 'uri']);
|
||||
}
|
||||
\Phpcmf\Service::M('Menu')->_update('member', $id, $data);
|
||||
\Phpcmf\Service::L('input')->system_log('修改用户中心菜单: '.$data['name']);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'top' => \Phpcmf\Service::M('Menu')->get_top('member'),
|
||||
'type' => $data['pid'],
|
||||
'data' => $data,
|
||||
'form' => dr_form_hidden(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_menu_add.html');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function del() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('你还没有选择呢'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('Menu')->_delete('member', $ids);
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
\Phpcmf\Service::L('input')->system_log('批量删除用户中心菜单: '. implode(',', $ids));
|
||||
$this->_json(1, dr_lang('操作成功'), ['ids' => $ids]);
|
||||
}
|
||||
|
||||
// 初始化
|
||||
public function init() {
|
||||
|
||||
\Phpcmf\Service::M('Menu')->init('member');
|
||||
\Phpcmf\Service::L('input')->system_log('初始化用户中心菜单');
|
||||
$this->_json(1, dr_lang('初始化菜单成功,请按F5刷新整个页面'));
|
||||
}
|
||||
|
||||
// 隐藏或者启用
|
||||
public function use_edit() {
|
||||
|
||||
$i = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$v = \Phpcmf\Service::M('Menu')->_uesd('member', $i);
|
||||
if ($v == -1) {
|
||||
$this->_json(0, dr_lang('数据#%s不存在', $i), ['value' => $v]);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('input')->system_log('修改用户中心菜单状态: '. $i);
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
$this->_json(1, dr_lang($v ? '此菜单已被隐藏' : '此菜单已被启用'), ['value' => $v]);
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
public function save_edit() {
|
||||
|
||||
$i = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
\Phpcmf\Service::M('Menu')->_save(
|
||||
'member',
|
||||
$i,
|
||||
dr_safe_replace(\Phpcmf\Service::L('input')->get('name')),
|
||||
dr_safe_replace(\Phpcmf\Service::L('input')->get('value'))
|
||||
);
|
||||
|
||||
\Phpcmf\Service::M('cache')->sync_cache(''); // 自动更新缓存
|
||||
\Phpcmf\Service::L('input')->system_log('修改用户中心菜单信息: '. $i);
|
||||
$this->_json(1, dr_lang('更改成功'));
|
||||
}
|
||||
|
||||
|
||||
// 验证数据
|
||||
private function _validation($data) {
|
||||
|
||||
if ($data['type'] != 3) {
|
||||
// 非链接菜单时不录入url和uri
|
||||
unset($this->form['url'], $this->form['uri']);
|
||||
} else {
|
||||
// url和uri 只验证一个
|
||||
if ($data['url']) {
|
||||
unset($this->form['uri']);
|
||||
}
|
||||
if ($data['uri']) {
|
||||
unset($this->form['url']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['mark']) {
|
||||
list($a, $b) = explode('-', $data['mark']);
|
||||
if ($a == 'module' && !is_dir(dr_get_app_dir($b))) {
|
||||
$this->_json(0, dr_lang('模块[%s]不存在', $b), ['field' => 'mark']);
|
||||
}
|
||||
}
|
||||
|
||||
list($data, $return) = \Phpcmf\Service::L('form')->validation($data, $this->form);
|
||||
if ($return) {
|
||||
$this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
}
|
||||
|
||||
$data['uri'] = strtolower((string)$data['uri']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
// 授权登录
|
||||
class Oauth extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
// 模板前缀(避免混淆)
|
||||
$this->my_field = array(
|
||||
'nickname' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('昵称'),
|
||||
'isemoji' => 1,
|
||||
'fieldname' => 'nickname',
|
||||
'fieldtype' => 'Text',
|
||||
),
|
||||
'uid' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('uid'),
|
||||
'fieldname' => 'uid',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户组审核');
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'member_oauth',
|
||||
'field' => $this->my_field,
|
||||
'sys_field' => [],
|
||||
'order_by' => 'id desc',
|
||||
'list_field' => [],
|
||||
]);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'授权账号' => ['member/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-qq'],
|
||||
'详情' => ['hide:member/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
|
||||
]
|
||||
),
|
||||
'field' => $this->my_field,
|
||||
]);
|
||||
}
|
||||
|
||||
// index
|
||||
public function index() {
|
||||
$this->_List();
|
||||
\Phpcmf\Service::V()->display('member_oauth.html');
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function del() {
|
||||
$this->_Del(\Phpcmf\Service::L('input')->get_post_ids());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Setting extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$page = intval(\Phpcmf\Service::L('input')->get('page'));
|
||||
|
||||
// 获取会员全部配置信息
|
||||
$data = [];
|
||||
$result = \Phpcmf\Service::M()->db->table('member_setting')->get()->getResultArray();
|
||||
if ($result) {
|
||||
foreach ($result as $t) {
|
||||
$data[$t['name']] = dr_string2array($t['value']);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$save = ['register', 'login', 'oauth', 'config', 'list_field'];
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if ($post['register']['sms']) {
|
||||
if (!dr_in_array('phone', $post['register']['field'])) {
|
||||
$this->_json(0, dr_lang('短信验证注册必须让手机号作为注册字段'));
|
||||
} elseif (!$post['register']['code'] && !SYS_SMS_IMG_CODE) {
|
||||
$this->_json(0, dr_lang('短信验证注册必须开启图片验证码'));
|
||||
}
|
||||
}
|
||||
if ($post['register']['email']) {
|
||||
if (!dr_in_array('email', $post['register']['field'])) {
|
||||
$this->_json(0, dr_lang('邮件验证注册必须让邮件作为注册字段'));
|
||||
} elseif (!$post['register']['code'] && !SYS_SMS_IMG_CODE) {
|
||||
$this->_json(0, dr_lang('邮件验证注册必须开启图片验证码'));
|
||||
}
|
||||
}
|
||||
if ($post['list_field']) {
|
||||
foreach ($post['list_field'] as $t) {
|
||||
if ($t['func']) {
|
||||
if (method_exists(\Phpcmf\Service::L('Function_list'), $t['func'])) {
|
||||
} elseif (!function_exists($t['func'])) {
|
||||
$this->_json(0, dr_lang('列表回调函数[%s]未定义', $t['func']));
|
||||
} elseif (strpos($t['func'], 'dr_') === false && strpos($t['func'], 'my_') === false) {
|
||||
$this->_json(0, '函数【'.$t['func'].'】必须以dr_或者my_开头');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($save as $name) {
|
||||
$row = \Phpcmf\Service::M()->table('member_setting')->where('name', $name)->getRow();
|
||||
if ($row) {
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->where('name', $name)->update([
|
||||
'name' => $name,
|
||||
'value' => dr_array2string($post[$name])
|
||||
]);
|
||||
} else {
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => $name,
|
||||
'value' => dr_array2string($post[$name])
|
||||
]);
|
||||
}
|
||||
}
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
if (!$data['list_field']) {
|
||||
$data['list_field'] = $this->member_cache['list_field'];
|
||||
}
|
||||
|
||||
// 主表字段
|
||||
$field = \Phpcmf\Service::M()->db->table('field')
|
||||
->where('disabled', 0)
|
||||
->where('ismain', 1)
|
||||
->where('relatedname', 'member')
|
||||
->orderBy('displayorder ASC,id ASC')
|
||||
->get()->getResultArray();
|
||||
$field = dr_list_field_value($data['list_field'], \Phpcmf\Service::L('Field')->member_list_field(), $field);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'data' => $data,
|
||||
'page' => $page,
|
||||
'form' => dr_form_hidden(['page' => $page]),
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'用户设置' => ['member/setting/index', 'fa fa-cog'],
|
||||
'help' => [1042],
|
||||
]
|
||||
),
|
||||
'field' => $field,
|
||||
'oauth' => dr_oauth_list(),
|
||||
'group' => \Phpcmf\Service::M()->table('member_group')->getAll(),
|
||||
'synurl' => \Phpcmf\Service::M('member')->get_sso_url(),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_setting.html');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
class Setting_notice extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
public function index() {
|
||||
|
||||
$notice = [];
|
||||
$notice['member'] = [
|
||||
'name' => dr_lang('系统'),
|
||||
'value' => require APPPATH.'Config/Notice.php',
|
||||
];
|
||||
|
||||
if (is_file(MYPATH.'Config/Notice.php')) {
|
||||
$notice['my'] = [
|
||||
'name' => dr_lang('自定义'),
|
||||
'value' => require MYPATH.'Config/Notice.php',
|
||||
];
|
||||
}
|
||||
|
||||
$local = \Phpcmf\Service::Apps(1);
|
||||
foreach ($local as $dir => $path) {
|
||||
if (is_file($path.'/Config/App.php') ) {
|
||||
$app = require $path.'/Config/App.php';
|
||||
if (is_file($path.'/Config/Notice.php')) {
|
||||
$cfg = require $path.'/Config/Notice.php';
|
||||
$cfg && $notice[strtolower($dir)] = [
|
||||
'name' => $app['name'],
|
||||
'value' => $cfg
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$path = \Phpcmf\Service::L('html')->get_webpath(SITE_ID, 'site', '');
|
||||
$notice_type = \Phpcmf\Service::L('notice')->get_type();
|
||||
foreach ($notice as $i => $t) {
|
||||
if ($t['value']) {
|
||||
foreach ($t['value'] as $ii => $v) {
|
||||
$notice[$i]['value'][$ii] = [
|
||||
'name' => $v,
|
||||
];
|
||||
$notice[$i]['value'][$ii]['file'] = [
|
||||
];
|
||||
foreach ($notice_type as $jj => $tt) {
|
||||
$notice[$i]['value'][$ii]['file'][$jj] = $this->_is_file($path, CONFIGPATH, $ii, $tt['file']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'notice')->get()->getRowArray();
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'通知设置' => ['member/setting_notice/index', 'fa fa-volume-up'],
|
||||
'help' => [194],
|
||||
]
|
||||
),
|
||||
'value' => dr_string2array($data['value']),
|
||||
'notice_type' => $notice_type,
|
||||
'notice_config' => $notice,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_setting_notice.html');
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
public function add() {
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
\Phpcmf\Service::M()->db->table('member_setting')->replace([
|
||||
'name' => 'notice',
|
||||
'value' => dr_array2string(\Phpcmf\Service::L('input')->post('data'))
|
||||
]);
|
||||
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
} else {
|
||||
$this->_json(0, dr_lang('异常请求'));
|
||||
}
|
||||
}
|
||||
|
||||
private function _get_file($path, $ppath, $file, $name) {
|
||||
|
||||
$file1 = $path.'config/notice/'.$name.'/'.$file.'.html';
|
||||
$file2 = $ppath.'notice/'.$name.'/'.$file.'.html';
|
||||
if (is_file($file1)) {
|
||||
return htmlentities(file_get_contents($file1),ENT_COMPAT,'UTF-8');
|
||||
} elseif (is_file($file2)) {
|
||||
return (IS_DEV ? dr_lang('############由于web目录下没有此文件,因此加载根目录下的文件:'.$file2.'#################').PHP_EOL : '')
|
||||
.htmlentities(file_get_contents($file2),ENT_COMPAT,'UTF-8');
|
||||
}
|
||||
|
||||
return (IS_DEV ? dr_lang('############'.$file1.'#################').PHP_EOL : '')
|
||||
.dr_lang('文件不存在,请手动创建此文件');
|
||||
}
|
||||
|
||||
private function _is_file($path, $ppath, $file, $name) {
|
||||
|
||||
$file1 = $path.'config/notice/'.$name.'/'.$file.'.html';
|
||||
$file2 = $ppath.'notice/'.$name.'/'.$file.'.html';
|
||||
if (is_file($file1)) {
|
||||
return true;
|
||||
} elseif (is_file($file2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 修改模板
|
||||
public function edit() {
|
||||
|
||||
$file = dr_safe_filename($_GET['file']);
|
||||
$list = [];
|
||||
$ppath = CONFIGPATH;
|
||||
!defined('IS_SITES') && define('IS_SITES', 0);
|
||||
|
||||
$notice_type = \Phpcmf\Service::L('notice')->get_type();
|
||||
|
||||
foreach ($this->site_info as $sid => $t) {
|
||||
if ($sid != SITE_ID) {
|
||||
continue;
|
||||
}
|
||||
$path = \Phpcmf\Service::L('html')->get_webpath($sid, 'site', '');
|
||||
$list[$sid] = [
|
||||
'name' => $t['SITE_NAME'],
|
||||
'data' => [
|
||||
|
||||
]
|
||||
];
|
||||
foreach ($notice_type as $nid => $tt) {
|
||||
$list[$sid]['data'][$nid] = [
|
||||
'name' => dr_lang($tt['name']),
|
||||
'code' => $this->_get_file($path, $ppath, $file, $tt['file']),
|
||||
'file' => (CI_DEBUG && IS_SITES ? $path : '') . 'config/notice/'.$tt['file'].'/'.$file.'.html',
|
||||
'help' => $tt['help'], //'http://help.phpcmf.net/479.html',
|
||||
'height' => $tt['height'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
if (!IS_DEV) {
|
||||
$this->_json(0, dr_lang('禁止修改'));
|
||||
}
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data', false);
|
||||
if (!$post) {
|
||||
$this->_json(0, dr_lang('内容没有填写完整'));
|
||||
}
|
||||
|
||||
$ok = 0;
|
||||
foreach ($post as $sid => $t) {
|
||||
foreach ($t as $name => $value) {
|
||||
if (isset($list[$sid]['data'][$name]) && $list[$sid]['data'][$name] && $value) {
|
||||
$rt = file_put_contents($list[$sid]['data'][$name]['file'], $value);
|
||||
if (!$rt) {
|
||||
$this->_json(0, dr_lang('文件%s写入失败', $list[$sid]['data'][$name]['file']));
|
||||
}
|
||||
$ok++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('共修改%s个文件', $ok));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'list' => $list,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_setting_notice_edit.html');exit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php namespace Phpcmf\Controllers\Admin;
|
||||
|
||||
|
||||
// 审核管理
|
||||
class Verify extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
private $group;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->my_field = array(
|
||||
'username' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('账号'),
|
||||
'fieldname' => 'username',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
'email' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('邮箱'),
|
||||
'fieldname' => 'email',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
'phone' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('手机'),
|
||||
'fieldname' => 'phone',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
'name' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('姓名'),
|
||||
'fieldname' => 'name',
|
||||
'fieldtype' => 'Text',
|
||||
'setting' => array(
|
||||
'option' => array(
|
||||
'width' => 200,
|
||||
),
|
||||
'validate' => array(
|
||||
'required' => 1,
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('用户');
|
||||
// 初始化数据表
|
||||
if ($this->member_cache['field']) {
|
||||
foreach ($this->member_cache['field'] as $i => $t) {
|
||||
$this->member_cache['field'][$i]['setting']['validate']['required'] = 0;
|
||||
$this->my_field[$t['fieldname']] = $t;
|
||||
}
|
||||
}
|
||||
if (!isset($this->member_cache['list_field']) || !$this->member_cache['list_field']) {
|
||||
$this->member_cache = \Phpcmf\Service::M('member', 'member')->cache();
|
||||
}
|
||||
// 初始化数据表
|
||||
$list_field = [
|
||||
'avatar' => array(
|
||||
'use' => '1',
|
||||
'name' => '头像',
|
||||
'width' => '70',
|
||||
'func' => 'dr_member_list_avatar',
|
||||
'center' => '1',
|
||||
),
|
||||
];
|
||||
$this->_init([
|
||||
'table' => 'member',
|
||||
'stable' => 'member_data',
|
||||
'field' => $this->member_cache['field'],
|
||||
'join_list' => ['member_data', 'member.id=member_data.id', 'left'],
|
||||
'order_by' => 'member.id desc',
|
||||
'list_field' => dr_array22array($list_field, $this->member_cache['list_field']),
|
||||
]);
|
||||
$this->group = $this->member_cache['group'];
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
|
||||
[
|
||||
'待审核用户' => ['member/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-user'],
|
||||
]
|
||||
),
|
||||
'field' => $this->my_field,
|
||||
'group' => $this->group,
|
||||
'member_list_field' => dr_array22array(\Phpcmf\Service::L('Field')->member_list_field(), $this->member_cache['field']),
|
||||
'is_show_search_bar' => $this->member_cache['config']['is_show_search_bar'],
|
||||
]);
|
||||
}
|
||||
|
||||
// 用户管理
|
||||
public function index() {
|
||||
|
||||
$p = [];
|
||||
$name = dr_safe_replace(\Phpcmf\Service::L('input')->request('field'));
|
||||
$value = dr_safe_replace(\Phpcmf\Service::L('input')->request('keyword'));
|
||||
|
||||
$where = [
|
||||
\Phpcmf\Service::M()->dbprefix('member').'.`id` IN (select id from `'.\Phpcmf\Service::M()->dbprefix('member_data').'` where `is_verify`=0)',
|
||||
];
|
||||
|
||||
if ($name && $value && isset($this->my_field[$name])) {
|
||||
$p[$name] = $value;
|
||||
$where[] = '`'.$name.'` LIKE "%'.$value.'%"';
|
||||
}
|
||||
|
||||
$groupid = \Phpcmf\Service::L('input')->request('groupid');
|
||||
if ($groupid && is_array($groupid)) {
|
||||
$in = [];
|
||||
foreach ($groupid as $gid) {
|
||||
$gid = intval($gid);
|
||||
if ($gid) {
|
||||
$in[] = $gid;
|
||||
}
|
||||
}
|
||||
if ($in) {
|
||||
$where[] = \Phpcmf\Service::M()->dbprefix('member').'.id IN (select uid from `'.\Phpcmf\Service::M()->dbprefix('member_group_index').'` where gid in ('.implode(',', $in).'))';
|
||||
$p['groupid'] = $in;
|
||||
}
|
||||
}
|
||||
|
||||
$rs = \Phpcmf\Hooks::trigger_callback('admin_member_list_where');
|
||||
if ($rs && isset($rs['code']) && $rs['code']) {
|
||||
$where[] = $rs['data']['where'];
|
||||
}
|
||||
|
||||
$where && \Phpcmf\Service::M()->set_where_list(implode(' AND ', $where));
|
||||
|
||||
$this->field = dr_array22array(\Phpcmf\Service::L('Field')->member_list_field(), $this->my_field);
|
||||
$this->is_ajax_list = true;
|
||||
$this->_List($p);
|
||||
$this->mytable = [
|
||||
'foot_tpl' => '',
|
||||
'link_tpl' => '',
|
||||
'link_var' => 'html = html.replace(/\{id\}/g, row.id);
|
||||
html = html.replace(/\{uid\}/g, row.id);',
|
||||
];
|
||||
$uriprefix = APP_DIR.'/'.\Phpcmf\Service::L('Router')->class;
|
||||
if ($this->_is_admin_auth('del') || $this->_is_admin_auth('edit')) {
|
||||
$this->mytable['foot_tpl'].= '<label class="table_select_all"><input onclick="dr_table_select_all(this)" type="checkbox"><span></span></label>';
|
||||
}
|
||||
if ($this->_is_admin_auth('del')) {
|
||||
$this->mytable['foot_tpl'].= '<label><button type="button" onclick="dr_ajax_option_user(\''.dr_url('member/home/del').'\', 1)" class="btn red btn-sm"> <i class="fa fa-trash"></i> '.dr_lang('删除').'</button></label>';
|
||||
}
|
||||
|
||||
if ($this->_is_admin_auth('edit')) {
|
||||
$this->mytable['link_tpl'] .= '<label><a href="javascript:dr_iframe_show(\'' . dr_lang('登录记录') . '\', \'' . dr_url('member/home/login_index') . '&id={id}\', \'80%\')" class="btn btn-xs blue"> <i class="fa fa-calendar"></i> ' . dr_lang('记录') . '</a></label>';
|
||||
$this->mytable['foot_tpl'] .= '
|
||||
<label><button type="button" onclick="dr_ajax_option(\''.dr_url('member/verify/edit').'\', \''.dr_lang('你确定要通过审核吗?').'\', 1)" class="btn blue btn-sm"> <i class="fa fa-check-square-o"></i> '.dr_lang('通过').'</button></label>
|
||||
';
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'mytable' => $this->mytable,
|
||||
'is_verify' => 1,
|
||||
'uriprefix' => 'member/home',
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('member_list.html');
|
||||
}
|
||||
|
||||
// 审核
|
||||
public function edit() {
|
||||
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('所选用户不存在'));
|
||||
}
|
||||
|
||||
foreach ($ids as $id) {
|
||||
\Phpcmf\Service::M('member')->verify_member($id);
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,663 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
// 用户api
|
||||
class Api extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
/**
|
||||
* 会员关联字段数据读取
|
||||
*/
|
||||
public function members() {
|
||||
|
||||
// 强制将模板设置为后台
|
||||
\Phpcmf\Service::V()->admin();
|
||||
|
||||
$field = array(
|
||||
'id' => array(
|
||||
'ismain' => 1,
|
||||
'name' => 'Uid',
|
||||
'fieldname' => 'id',
|
||||
'fieldtype' => 'Text',
|
||||
),
|
||||
'username' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('账号'),
|
||||
'fieldname' => 'username',
|
||||
'fieldtype' => 'Text',
|
||||
),
|
||||
'email' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('邮箱'),
|
||||
'fieldname' => 'email',
|
||||
'fieldtype' => 'Text',
|
||||
),
|
||||
'phone' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('手机'),
|
||||
'fieldname' => 'phone',
|
||||
'fieldtype' => 'Text',
|
||||
),
|
||||
'name' => array(
|
||||
'ismain' => 1,
|
||||
'name' => dr_lang('姓名'),
|
||||
'fieldname' => 'name',
|
||||
'fieldtype' => 'Text',
|
||||
),
|
||||
);
|
||||
|
||||
$param = $data = \Phpcmf\Service::L('input')->get('', true);
|
||||
|
||||
$diy = dr_safe_filename($data['diy']);
|
||||
|
||||
if (IS_POST) {
|
||||
$ids = \Phpcmf\Service::L('input')->get_post_ids();
|
||||
if (!$ids) {
|
||||
$this->_json(0, dr_lang('没有选择项'));
|
||||
}
|
||||
$id = [];
|
||||
foreach ($ids as $i) {
|
||||
$id[] = (int)$i;
|
||||
}
|
||||
$builder = \Phpcmf\Service::M()->db->table('member');
|
||||
$builder->whereIn('id', $id);
|
||||
$mylist = $builder->orderBy('id DESC')->get()->getResultArray();
|
||||
if (!$mylist) {
|
||||
$this->_json(0, dr_lang('没有相关数据'));
|
||||
}
|
||||
$name = dr_safe_filename(\Phpcmf\Service::L('input')->get('name'));
|
||||
if (!$name) {
|
||||
$this->_json(0, dr_lang('name参数不能为空'));
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ($mylist as $t) {
|
||||
$ids[] = $t['id'];
|
||||
}
|
||||
|
||||
$file = \Phpcmf\Service::V()->code2php(
|
||||
file_get_contents(is_file(MYPATH.'View/api_members_field_'.$diy.'.html') ? MYPATH.'View/api_members_field_'.$diy.'.html' : COREPATH.'View/api_members_field.html')
|
||||
);
|
||||
ob_start();
|
||||
require $file;
|
||||
$code = ob_get_clean();
|
||||
$html = explode('<!--list-->', $code);
|
||||
|
||||
$this->_json(1, dr_lang('操作成功'), ['ids' => $ids, 'html' => $html[1]]);
|
||||
}
|
||||
|
||||
$where = [];
|
||||
if ($data['group']) {
|
||||
// 指定用户组时
|
||||
$ids = explode(',', (string)$data['group']);
|
||||
if ($ids) {
|
||||
$arr = [];
|
||||
foreach ($ids as $gid) {
|
||||
$gid = intval($gid);
|
||||
if ($gid) {
|
||||
$arr[] = $gid;
|
||||
}
|
||||
}
|
||||
if ($arr) {
|
||||
$where[] = '`id` IN (select uid from `'.\Phpcmf\Service::M()->dbprefix('member_group_index').'` where gid in('.implode(',', $arr).'))';
|
||||
}
|
||||
}
|
||||
$group = [];
|
||||
} else {
|
||||
$group = $this->member_cache['group'];
|
||||
}
|
||||
|
||||
if ($data['search']) {
|
||||
$gid = (int)$data['groupid'];
|
||||
if ($gid) {
|
||||
$where[] = '`id` IN (select uid from `'.\Phpcmf\Service::M()->dbprefix('member_group_index').'` where gid='.$gid.')';
|
||||
}
|
||||
$data['keyword'] = dr_safe_replace(urldecode($data['keyword']));
|
||||
if (isset($data['keyword']) && $data['keyword'] && $data['field'] && isset($field[$data['field']])) {
|
||||
$data['keyword'] = dr_safe_replace(urldecode($data['keyword']));
|
||||
if ($data['field'] == 'id') {
|
||||
// id搜索
|
||||
$id = [];
|
||||
$ids = explode(',', $data['keyword']);
|
||||
foreach ($ids as $i) {
|
||||
$id[] = (int)$i;
|
||||
}
|
||||
$where[] = 'id in('.implode(',', $id).')';
|
||||
} else {
|
||||
// 其他模糊搜索
|
||||
$where[] = $data['field'].' LIKE "%'.$data['keyword'].'%"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rules = $data;
|
||||
$rules['page'] = '{page}';
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'diy' => $data['diy'],
|
||||
'where' => $where ? urlencode(implode(' AND ', $where)) : '',
|
||||
'param' => $data,
|
||||
'field' => $field,
|
||||
'group' => $group,
|
||||
'search' => dr_form_search_hidden(['search' => 1, 'is_iframe' => 1, 'diy' => $data['diy']]),
|
||||
'urlrule' => '/index.php?s=module&c=api&m=related&'.http_build_query($rules),
|
||||
]);
|
||||
if (is_file(MYPATH.'View/api_members_'.$diy.'.html')) {
|
||||
\Phpcmf\Service::V()->display('api_members_'.$diy.'.html');
|
||||
} else {
|
||||
\Phpcmf\Service::V()->display('api_members.html');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态调用模板
|
||||
*/
|
||||
public function template() {
|
||||
|
||||
$app = dr_safe_filename(\Phpcmf\Service::L('input')->get('app'));
|
||||
$file = dr_safe_filename(\Phpcmf\Service::L('input')->get('name'));
|
||||
$module = dr_safe_filename(\Phpcmf\Service::L('input')->get('module'));
|
||||
|
||||
$data = [
|
||||
'app' => $app,
|
||||
'file' => $file,
|
||||
'module' => $module,
|
||||
];
|
||||
|
||||
if (!$file) {
|
||||
$html = 'name不能为空';
|
||||
} else {
|
||||
if ($module) {
|
||||
$this->_module_init($module);
|
||||
\Phpcmf\Service::V()->module($module);
|
||||
} elseif ($app) {
|
||||
\Phpcmf\Service::V()->module($app);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign(\Phpcmf\Service::L('input')->get('', true));
|
||||
ob_start();
|
||||
\Phpcmf\Service::V()->display($file);
|
||||
$html = ob_get_contents();
|
||||
ob_clean();
|
||||
|
||||
$data['call_value'] = \Phpcmf\Service::V()->call_value;
|
||||
}
|
||||
|
||||
$this->_json(1, $html, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权登录用户中心跳转
|
||||
*/
|
||||
public function alogin() {
|
||||
|
||||
$code = \Phpcmf\Service::L('input')->get_cookie('admin_login_member');
|
||||
if (!$code) {
|
||||
if (isset($_COOKIE[SYS_KEY.'admin_login_member']) && $_COOKIE[SYS_KEY.'admin_login_member']) {
|
||||
$code = $_COOKIE[SYS_KEY.'admin_login_member'];
|
||||
} else {
|
||||
$this->_msg(0, dr_lang('没有获取到cookie'));
|
||||
}
|
||||
}
|
||||
|
||||
$session = $this->session()->get('admin_login_member_code');
|
||||
if (!$session) {
|
||||
$this->_msg(0, dr_lang('没有获取到会话信息'));
|
||||
}
|
||||
|
||||
list($uid, $adminid) = explode('-', $code);
|
||||
$uid = (int)$uid;
|
||||
if ($this->uid != $uid) {
|
||||
$admin = \Phpcmf\Service::M()->table('member')->get((int)$adminid);
|
||||
if ($session != md5($uid.$admin['id'].$admin['password'])) {
|
||||
$this->_msg(0, dr_lang('会话信息不匹配'));
|
||||
}
|
||||
}
|
||||
|
||||
$url = dr_safe_url(urldecode(\Phpcmf\Service::L('input')->get('url')));
|
||||
!$url && $url = MEMBER_URL;
|
||||
dr_redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 头像更新
|
||||
*/
|
||||
public function avatar() {
|
||||
\Phpcmf\Service::L('Thread')->cron(['action' => 'oauth_down_avatar', 'id' => intval(\Phpcmf\Service::L('input')->get('id')) ]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核
|
||||
*/
|
||||
public function verify() {
|
||||
|
||||
if (!$this->member) {
|
||||
$this->_msg(0, dr_lang('账号未登录'));
|
||||
}
|
||||
|
||||
// 获取返回页面
|
||||
$url = dr_safe_url($_SERVER['HTTP_REFERER']);
|
||||
(strpos($url, 'verify') !== false || !$url) && $url = MEMBER_URL;
|
||||
|
||||
if ($this->member['is_verify'] && !IS_XRDEV) {
|
||||
if (IS_API_HTTP) {
|
||||
$this->_json(0, dr_lang('此用户已经通过审核了'));
|
||||
}
|
||||
dr_redirect($url);
|
||||
exit;
|
||||
} elseif (!$this->member['is_verify'] && !$this->member_cache['register']['verify']) {
|
||||
// 如果系统已经关闭了审核机制就自动通过
|
||||
\Phpcmf\Service::M('member')->verify_member($this->member['uid']);
|
||||
if (IS_API_HTTP) {
|
||||
$this->_json(0, dr_lang('系统已经关闭了审核机制'));
|
||||
}
|
||||
dr_redirect($url);
|
||||
exit;
|
||||
} elseif ($this->member_cache['register']['verify'] == 'admin') {
|
||||
$this->_msg(0, dr_lang('请等待管理员的审核'));
|
||||
} elseif (!$this->member['email'] && !$this->member['phone']) {
|
||||
// 手机邮箱都为空,表示从第三方登录注册的
|
||||
$this->change();exit;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'post_url' => dr_member_url('api/verify_code', ['back' => urlencode($url)]),
|
||||
'meta_title' => dr_lang('账号审核'),
|
||||
'verify_url' => dr_member_url('api/'.$this->member_cache['register']['verify'].'_verify_code'),
|
||||
'verify_name' => $this->member[$this->member_cache['register']['verify']],
|
||||
'verify_type' => $this->member_cache['register']['verify'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('verify.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核时变更邮箱或者手机
|
||||
*/
|
||||
public function change() {
|
||||
|
||||
if (!$this->member) {
|
||||
$this->_msg(0, dr_lang('账号未登录'));
|
||||
} elseif ($this->member['is_verify'] && !IS_XRDEV) {
|
||||
if (IS_API_HTTP) {
|
||||
$this->_json(0, dr_lang('此用户已经通过审核了'));
|
||||
}
|
||||
dr_redirect(MEMBER_URL);
|
||||
exit;
|
||||
} elseif (!$this->member['is_verify'] && !$this->member_cache['register']['verify']) {
|
||||
// 如果系统已经关闭了审核机制就自动通过
|
||||
\Phpcmf\Service::M('member')->verify_member($this->member['uid']);
|
||||
if (IS_API_HTTP) {
|
||||
$this->_json(0, dr_lang('系统已经关闭了审核机制'));
|
||||
}
|
||||
dr_redirect(MEMBER_URL);
|
||||
exit;
|
||||
} elseif ($this->member_cache['register']['verify'] == 'admin') {
|
||||
$this->_msg(0, dr_lang('请等待管理员的审核'));
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
$value = dr_safe_replace(\Phpcmf\Service::L('input')->post('value'));
|
||||
if (!\Phpcmf\Service::L('Form')->check_captcha('code')) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
|
||||
} elseif (empty($value)) {
|
||||
$this->_json(0, dr_lang('新邮箱或者手机号码必须填写'));
|
||||
} elseif ($this->member_cache['register']['verify'] == 'email' && !\Phpcmf\Service::L('Form')->check_email($value)) {
|
||||
$this->_json(0, dr_lang('邮箱格式不正确'), ['field' => 'value']);
|
||||
} elseif ($this->member_cache['register']['verify'] == 'phone' && !\Phpcmf\Service::L('Form')->check_phone($value)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'value']);
|
||||
} elseif ($this->member_cache['register']['verify'] == 'email' && \Phpcmf\Service::M()->db->table('member')->where('email', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('邮箱%s已经注册',$value), ['field' => 'value']);
|
||||
} elseif ($this->member_cache['register']['verify'] == 'phone' && \Phpcmf\Service::M()->db->table('member')->where('phone', $value)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('手机号码%s已经注册', $value), ['field' => 'value']);
|
||||
}
|
||||
|
||||
$this->member['randcode'] = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->uid)->update([
|
||||
'randcode' => $this->member['randcode'],
|
||||
$this->member_cache['register']['verify'] => $value
|
||||
]);
|
||||
|
||||
switch ($this->member_cache['register']['verify']) {
|
||||
|
||||
case 'phone':
|
||||
// 挂钩点 短信验证之前
|
||||
\Phpcmf\Hooks::trigger('member_send_phone_before', $value);
|
||||
\Phpcmf\Service::M('member')->sendsms_code($value, $this->member['randcode']);
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
\Phpcmf\Service::M('member')->sendmail($value, dr_lang('注册邮件验证'), 'member_verify.html', $this->member);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('信息已经变更'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'post_url' => dr_member_url('api/verify_code'),
|
||||
'meta_title' => dr_lang('账号审核信息变更'),
|
||||
'verify_name' => $this->member[$this->member_cache['register']['verify']],
|
||||
'verify_type' => $this->member_cache['register']['verify'],
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('change.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件审核验证码
|
||||
*/
|
||||
public function email_verify_code() {
|
||||
|
||||
if (!$this->member) {
|
||||
$this->_msg(0, dr_lang('账号未登录'));
|
||||
} elseif ($this->member['is_verify']) {
|
||||
$this->_msg(0, dr_lang('此用户已经通过审核了'));
|
||||
} elseif ($this->member_cache['register']['verify'] != 'email') {
|
||||
$this->_msg(0, dr_lang('审核方式不正确'));
|
||||
}
|
||||
|
||||
// 验证操作间隔
|
||||
$name = 'member-verify-email-'.$this->uid;
|
||||
if (\Phpcmf\Service::L('cache')->check_auth_data($name, 300)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试'));
|
||||
}
|
||||
|
||||
$this->member['randcode'] = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['randcode' => $this->member['randcode']]);
|
||||
$rt = \Phpcmf\Service::M('member')->sendmail($this->member['email'], dr_lang('注册邮件验证'), 'member_verify.html', $this->member);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, dr_lang('邮件发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_auth_data($name, $this->member['randcode']);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信审核验证码
|
||||
*/
|
||||
public function phone_verify_code() {
|
||||
|
||||
if (!$this->member) {
|
||||
$this->_json(0, dr_lang('账号未登录'));
|
||||
} elseif ($this->member['is_verify']) {
|
||||
$this->_msg(0, dr_lang('此用户已经通过审核了'));
|
||||
} elseif ($this->member_cache['register']['verify'] != 'phone') {
|
||||
$this->_msg(0, dr_lang('审核方式不正确'));
|
||||
}
|
||||
|
||||
// 验证操作间隔
|
||||
$name = 'member-verify-phone-'.$this->uid;
|
||||
if (\Phpcmf\Service::L('cache')->check_auth_data($name, defined('SYS_CACHE_SMS') && SYS_CACHE_SMS ? SYS_CACHE_SMS : 60)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试'));
|
||||
}
|
||||
|
||||
$this->member['randcode'] = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['randcode' => $this->member['randcode']]);
|
||||
$rt = \Phpcmf\Service::M('member')->sendsms_code($this->member['phone'], $this->member['randcode']);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_auth_data($name, $this->member['randcode']);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证审核验证码
|
||||
*/
|
||||
public function verify_code() {
|
||||
|
||||
// 获取返回页面
|
||||
$url = dr_safe_url($_GET['back'] ? urldecode((string)\Phpcmf\Service::L('input')->get('back')) : $_SERVER['HTTP_REFERER']);
|
||||
strpos($url, 'login') !== false && $url = MEMBER_URL;
|
||||
|
||||
// 挂钩点 审核验证之前
|
||||
\Phpcmf\Hooks::trigger('member_verify_before', $this->member);
|
||||
|
||||
if (!$this->member) {
|
||||
$this->_json(0, dr_lang('账号未登录'));
|
||||
} elseif ($this->member['is_verify']) {
|
||||
$this->_json(1, dr_lang('已经验证成功'), ['url' => $url ? $url : MEMBER_URL]);
|
||||
} elseif (!$this->member['randcode']) {
|
||||
$this->_json(0, dr_lang('验证码已过期'));
|
||||
} elseif (\Phpcmf\Service::L('input')->get('code') != $this->member['randcode']) {
|
||||
$this->_json(0, dr_lang('验证码不正确'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $this->member['id'])->update(['randcode' => 0]);
|
||||
|
||||
\Phpcmf\Service::M('member')->verify_member($this->member['id']);
|
||||
if ($this->member_cache['register']['verify'] == 'phone') {
|
||||
\Phpcmf\Service::M()->db->table('member_data')->where('id', $this->member['uid'])->update(['is_mobile' => 1]);
|
||||
} elseif ($this->member_cache['register']['verify'] == 'email') {
|
||||
\Phpcmf\Service::M()->db->table('member_data')->where('id', $this->member['uid'])->update(['is_email' => 1]);
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('验证成功'), ['url' => $url ? $url : MEMBER_URL]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 找回密码验证码
|
||||
*/
|
||||
public function find_code() {
|
||||
|
||||
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
|
||||
$value = dr_safe_replace(\Phpcmf\Service::L('input')->get('value'));
|
||||
if (!$value) {
|
||||
$this->_json(0, dr_lang('账号凭证不能为空'), ['field' => 'value']);
|
||||
} elseif (!$code) {
|
||||
$this->_json(0, dr_lang('图片验证码未填写'), ['field' => 'code']);
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_captcha_value($code)) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
|
||||
}
|
||||
|
||||
// 验证操作间隔
|
||||
$name = 'member-find-password-'.$value;
|
||||
if (\Phpcmf\Service::L('cache')->check_auth_data($name, defined('SYS_CACHE_SMS') && SYS_CACHE_SMS ? SYS_CACHE_SMS : 60)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试'));
|
||||
}
|
||||
|
||||
if (strpos($value, '@') !== false) {
|
||||
// 邮箱模式
|
||||
$data = \Phpcmf\Service::M()->db->table('member')->where('email', $value)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('账号凭证不存在'), ['field' => 'value']);
|
||||
}
|
||||
$data['randcode'] = $rand = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $data['id'])->update(['randcode' => $rand]);
|
||||
$rt = \Phpcmf\Service::M('member')->sendmail($value, dr_lang('找回密码'), 'member_find.html', $data);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, dr_lang('邮件发送失败'));
|
||||
}
|
||||
} else {
|
||||
// 手机
|
||||
if (!\Phpcmf\Service::L('Form')->check_phone($value)) {
|
||||
$this->_json(0, dr_lang('账号凭证格式不正确'), ['field' => 'value']);
|
||||
}
|
||||
|
||||
// 挂钩点 短信验证之前
|
||||
\Phpcmf\Hooks::trigger('member_send_phone_before', $value);
|
||||
|
||||
$data = \Phpcmf\Service::M()->db->table('member')->where('phone', $value)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('账号凭证不存在'), ['field' => 'value']);
|
||||
}
|
||||
$rand = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $data['id'])->update(['randcode' => $rand]);
|
||||
$rt = \Phpcmf\Service::M('member')->sendsms_code($value, $rand);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('cache')->set_auth_data($name, $rand);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
/////////////////发送短信验证码部分////////////////////
|
||||
|
||||
/**
|
||||
* 注册验证码
|
||||
*/
|
||||
public function register_code() {
|
||||
|
||||
if (!defined('SYS_SMS_IMG_CODE') || SYS_SMS_IMG_CODE == 0) {
|
||||
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
|
||||
if (!$code) {
|
||||
$this->_json(0, dr_lang('图片验证码未填写'), ['field' => 'code']);
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_captcha_value($code)) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
|
||||
}
|
||||
}
|
||||
|
||||
$value = trim(dr_safe_replace(\Phpcmf\Service::L('input')->get('id')));
|
||||
if (!$value) {
|
||||
$this->_json(0, dr_lang('信息未填写'));
|
||||
}
|
||||
|
||||
if (strpos($value, '@') !== false) {
|
||||
$email = $value;
|
||||
$data = \Phpcmf\Service::M()->db->table('member')->where('email', $value)->get()->getRowArray();
|
||||
if ($data) {
|
||||
$this->_json(0, dr_lang('邮箱已经注册'), ['field' => 'email']);
|
||||
}
|
||||
$code = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
$rt = \Phpcmf\Service::M('member')->sendmail($value, dr_lang('注册验证'), 'member_register_check.html', [
|
||||
'code' => $code,
|
||||
'randcode' => $code,
|
||||
]);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, dr_lang('邮件发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Form')->set_mobile_code($email, $code);
|
||||
} else {
|
||||
$phone = $value;
|
||||
if (!\Phpcmf\Service::L('Form')->check_phone($phone)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
|
||||
} elseif (\Phpcmf\Service::M()->db->table('member')->where('phone', $phone)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('手机号码已经注册'), ['field' => 'phone']);
|
||||
} elseif (\Phpcmf\Service::L('Form')->get_mobile_code($phone)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试')); // 验证操作间隔
|
||||
}
|
||||
|
||||
// 挂钩点 短信验证之前
|
||||
\Phpcmf\Hooks::trigger('member_send_phone_before', $phone);
|
||||
|
||||
$code = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
$rt = \Phpcmf\Service::M('member')->sendsms_code($phone, $code);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Form')->set_mobile_code($phone, $code);
|
||||
}
|
||||
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录验证码
|
||||
*/
|
||||
public function login_code() {
|
||||
|
||||
if (!defined('SYS_SMS_IMG_CODE') || SYS_SMS_IMG_CODE == 0) {
|
||||
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
|
||||
if (!$code) {
|
||||
$this->_json(0, dr_lang('图片验证码未填写'), ['field' => 'code']);
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_captcha_value($code)) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
|
||||
}
|
||||
}
|
||||
|
||||
// 挂钩点 短信验证之前
|
||||
\Phpcmf\Hooks::trigger('member_send_phone_before', $phone);
|
||||
|
||||
$phone = dr_safe_replace(\Phpcmf\Service::L('input')->get('id'));
|
||||
if (!$phone) {
|
||||
$this->_json(0, dr_lang('手机号码未填写'), ['field' => 'phone']);
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_phone($phone)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
|
||||
} elseif ($this->member_cache['login']['is_auto']
|
||||
&& !\Phpcmf\Service::M()->db->table('member')->where('phone', $phone)->countAllResults()) {
|
||||
$this->_json(0, dr_lang('手机号码未注册'), ['field' => 'phone']);
|
||||
} elseif (\Phpcmf\Service::L('Form')->get_mobile_code($phone)) {
|
||||
$this->_json(0, dr_lang('已经发送稍后再试'));// 验证操作间隔
|
||||
}
|
||||
|
||||
$code = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
$rt = \Phpcmf\Service::M('member')->sendsms_code($phone, $code);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Form')->set_mobile_code($phone, $code);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
public function send_code() {
|
||||
|
||||
$phone = dr_safe_replace(\Phpcmf\Service::L('input')->get('id'));
|
||||
if (!$phone) {
|
||||
$this->_json(0, dr_lang('手机号码未填写'), ['field' => 'phone']);
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_phone($phone)) {
|
||||
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
|
||||
}
|
||||
|
||||
// 挂钩点 短信验证之前
|
||||
\Phpcmf\Hooks::trigger('send_phone_before', $phone);
|
||||
|
||||
if (!defined('SYS_SMS_IMG_CODE') || SYS_SMS_IMG_CODE == 0) {
|
||||
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
|
||||
if (!$code) {
|
||||
$this->_json(0, dr_lang('图片验证码未填写'), ['field' => 'code']);
|
||||
} elseif (!\Phpcmf\Service::L('Form')->check_captcha_value($code)) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
|
||||
}
|
||||
}
|
||||
|
||||
// 验证操作间隔
|
||||
if (\Phpcmf\Service::L('Form')->get_mobile_code($phone)) {
|
||||
$this->_json(1, dr_lang('已经发送稍后再试'));
|
||||
}
|
||||
|
||||
$code = \Phpcmf\Service::L('Form')->get_rand_value();
|
||||
$rt = \Phpcmf\Service::M('member')->sendsms_code($phone, $code);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::L('Form')->set_mobile_code($phone, $code);
|
||||
|
||||
$this->_json(1, dr_lang('验证码发送成功'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册协议
|
||||
*/
|
||||
public function protocol() {
|
||||
\Phpcmf\Service::V()->display('protocol.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录状态
|
||||
*/
|
||||
public function status() {
|
||||
if ($this->member) {
|
||||
$this->_json(1, 'ok', $this->member);
|
||||
} else {
|
||||
$this->_json(0, dr_lang('没有登录'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
class Apply extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
/**
|
||||
* 申请升级用户组
|
||||
*/
|
||||
public function index() {
|
||||
|
||||
$gid = intval(\Phpcmf\Service::L('input')->get('gid'));
|
||||
$is_xufei = 0;
|
||||
if (isset($this->member['groupid'][$gid]) && $this->member['groupid'][$gid]) {
|
||||
if (!$this->member['groupid'][$gid]['setting']['timetype']
|
||||
&& !$this->member['groupid'][$gid]['setting']['level']['auto']
|
||||
&& !$this->member['groupid'][$gid]['setting']['timeout']) {
|
||||
if (!$this->member_cache['group'][$gid]['setting']['timect']
|
||||
&& $this->member_cache['group'][$gid]['etime'] - SYS_TIME > 0) {
|
||||
// 时长叠加未开启
|
||||
$this->_msg(0, dr_lang('当前用户组没有过期,无需重复操作'));
|
||||
exit;
|
||||
}
|
||||
if ($this->member['groupid'][$gid]['level']) {
|
||||
// 开启了等级功能
|
||||
$this->level();exit;
|
||||
}
|
||||
$is_xufei = 1;
|
||||
} else {
|
||||
$this->_msg(0, dr_lang('已经申请过,无需重复申请'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$group = $this->member_cache['group'][$gid];
|
||||
if (!$group) {
|
||||
$this->_msg(0, dr_lang('用户组[%s]不存在', $gid));
|
||||
} elseif (!$group['apply']) {
|
||||
$this->_msg(0, dr_lang('用户组[%s]没有开启申请权限', $group['name']));
|
||||
}
|
||||
|
||||
// 申请用户组之前的钩子
|
||||
\Phpcmf\Hooks::trigger('member_apply_group_before', ['uid' => $this->uid, 'gid' => $gid]);
|
||||
|
||||
$is_pay = 1;
|
||||
// 判断是否已经申请
|
||||
$verify = \Phpcmf\Service::M()->db->table('member_group_verify')->where('uid', $this->uid)->where('gid', $gid)->get()->getRowArray();
|
||||
if ($verify) {
|
||||
if (!$verify['status']) {
|
||||
$this->_msg(0, dr_lang('正在审核之中'));
|
||||
}
|
||||
$verify['content'] = dr_string2array($verify['content']);
|
||||
if ($verify['price'] < $group['price']) {
|
||||
// 当审核被拒绝时,之前付款的价格小于现在价格,需要补差价
|
||||
$group['price'] = $group['price'] - $verify['price'];
|
||||
} else {
|
||||
$is_pay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$level = $group['level'] && !$group['setting']['level']['auto'] ? $group['level'] : [];
|
||||
|
||||
// 判断是否存在用户组级别,并且设置为手动模式才可以选择申请
|
||||
if ($level) {
|
||||
foreach ($level as $i => $t) {
|
||||
if (!$t['apply']) {
|
||||
unset($level[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化自定义字段类
|
||||
\Phpcmf\Service::L('Field')->app(APP_DIR);
|
||||
|
||||
// 获取该组可用字段
|
||||
$field = [];
|
||||
if ($this->member_cache['field'] && $this->member_cache['group'][$gid]['field']) {
|
||||
foreach ($this->member_cache['field'] as $fname => $t) {
|
||||
dr_in_array($fname, $this->member_cache['group'][$gid]['field']) && $field[$fname] = $t;
|
||||
}
|
||||
}
|
||||
//print_r($this->member_cache);exit;
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$lid = 0;
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$my_verify = $attach = [];
|
||||
if ($field) {
|
||||
// id设置0,表示审核被拒时还可以修改不可修改的字段
|
||||
list($data, $return, $attach) = \Phpcmf\Service::L('Form')->id(0)->validation($post, null, $field, $verify ? dr_string2array($verify['content']) : $this->member);
|
||||
// 输出错误
|
||||
$return && $this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
// 审核申请
|
||||
$my_verify['content'] = $data[1];
|
||||
}
|
||||
// 附件归档
|
||||
SYS_ATTACHMENT_DB && $attach && \Phpcmf\Service::M('Attachment')->handle(
|
||||
$this->member['id'],
|
||||
\Phpcmf\Service::M()->dbprefix('member').'-'.$this->uid,
|
||||
$attach
|
||||
);
|
||||
|
||||
// 不重复扣款
|
||||
if ($is_pay) {
|
||||
$todo = 0;
|
||||
if (!$group['setting']['level']['auto'] && $level) {
|
||||
// 不开启自动升级的时候进入
|
||||
// 价格判断
|
||||
$lid = (int)\Phpcmf\Service::L('input')->post('lid');
|
||||
if (!$lid) {
|
||||
$this->_json(0, dr_lang('用户组级别未选择'));
|
||||
} elseif (!$group['level'][$lid]) {
|
||||
$this->_json(0, dr_lang('用户组级别无效'));
|
||||
} elseif (!$group['level'][$lid]['apply']) {
|
||||
$this->_json(0, dr_lang('用户组级别不允许申请'));
|
||||
}
|
||||
$title = dr_lang(($is_xufei ? '续费' : '申请').'用户组(%s): %s', $group['name'], $group['level'][$lid]['name']);
|
||||
if ($group['level'][$lid]['value']) {
|
||||
// 存在价格时才扣钱
|
||||
if ($group['unit']) {
|
||||
// 金币
|
||||
$price = (int)$group['level'][$lid]['value'];
|
||||
// 金币不足
|
||||
if ($this->member['score'] - $price < 0) {
|
||||
$this->_json(0, dr_lang('账户%s不足', SITE_SCORE));
|
||||
}
|
||||
// 扣分
|
||||
$rt = \Phpcmf\Service::M('member')->add_score($this->uid, -$price, $title, '', '');
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
// 提醒通知
|
||||
\Phpcmf\Service::M('member')->notice($this->uid, 2, $title);
|
||||
} else {
|
||||
// rmb
|
||||
if (!dr_is_app('pay')) {
|
||||
$this->_msg(0, '没有安装「支付系统」插件');exit;
|
||||
}
|
||||
$price = (int)$group['level'][$lid]['value'];
|
||||
// 支付方式
|
||||
$pay_type = \Phpcmf\Service::L('input')->post('pay_type');
|
||||
!$pay_type && $pay_type = 'finecms';
|
||||
// 唤起支付接口
|
||||
$pay = [
|
||||
'mark' => 'group-'.$group['id'].'-'.$lid.'-'.(int)$verify['id'],
|
||||
'uid' => $this->member['uid'],
|
||||
'username' => $this->member['username'],
|
||||
'type' => $pay_type,
|
||||
'url' => '',
|
||||
'result' => dr_array2string($my_verify),
|
||||
'money' => $price,
|
||||
'title' => $title
|
||||
];
|
||||
$rt = \Phpcmf\Service::M('Pay', 'pay')->post($pay);
|
||||
if (!$rt['code']) {
|
||||
$this->_msg(0, $rt['msg']);exit;
|
||||
}
|
||||
// 必须跳转到统一的主域名中付款
|
||||
$url = PAY_URL . 'index.php?s=api&c=pay&id=' . $rt['code'];
|
||||
if (IS_AJAX || IS_API_HTTP) {
|
||||
// 回调页面
|
||||
$rt['data']['url'] = $url;
|
||||
$this->_json($rt['code'], dr_lang('请稍后'), $rt['data']);
|
||||
exit;
|
||||
} else {
|
||||
// 跳转到支付页面
|
||||
dr_redirect($url, 'auto');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
$todo = 1;
|
||||
}
|
||||
|
||||
// 其他情况按组价格来算
|
||||
if ($group['price'] > 0 && $todo == 0) {
|
||||
// 存在价格时
|
||||
$title = dr_lang(($is_xufei ? '续费' : '申请').'用户组(%s)', $group['name']);
|
||||
if ($group['unit']) {
|
||||
// 金币
|
||||
$price = (int)$group['price'];
|
||||
// 金币不足
|
||||
if ($this->member['score'] - $price < 0 ) {
|
||||
$this->_json(0, dr_lang('账户%s不足', SITE_SCORE));
|
||||
}
|
||||
// 扣分
|
||||
$rt = \Phpcmf\Service::M('member')->add_score($this->uid, -$price, $title);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
// 提醒通知
|
||||
\Phpcmf\Service::M('member')->notice($this->uid, 2, $title);
|
||||
} else {
|
||||
// rmb
|
||||
if (!dr_is_app('pay')) {
|
||||
$this->_msg(0, '没有安装「支付系统」插件');exit;
|
||||
}
|
||||
$price = floatval($group['price']);
|
||||
// 支付方式
|
||||
$pay_type = \Phpcmf\Service::L('input')->post('pay_type');
|
||||
!$pay_type && $pay_type = 'finecms';
|
||||
// 唤起支付接口
|
||||
$pay = [
|
||||
'mark' => 'group-'.$group['id'].'-0-'.(int)$verify['id'],
|
||||
'uid' => $this->member['uid'],
|
||||
'username' => $this->member['username'],
|
||||
'type' => $pay_type,
|
||||
'url' => '',
|
||||
'result' => dr_array2string($my_verify),
|
||||
'money' => $price,
|
||||
'title' => $title
|
||||
];
|
||||
$rt = \Phpcmf\Service::M('Pay', 'pay')->post($pay);
|
||||
if (!$rt['code']) {
|
||||
$this->_msg(0, $rt['msg']);exit;
|
||||
}
|
||||
// 必须跳转到统一的主域名中付款
|
||||
$url = PAY_URL . 'index.php?s=api&c=pay&id=' . $rt['code'];
|
||||
if (IS_AJAX || IS_API_HTTP) {
|
||||
// 回调页面
|
||||
$rt['data']['url'] = $url;
|
||||
$this->_json($rt['code'], dr_lang('请稍后'), $rt['data']);
|
||||
exit;
|
||||
} else {
|
||||
// 跳转到支付页面
|
||||
dr_redirect($url, 'auto');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 入库存储
|
||||
$rt = \Phpcmf\Service::M('member')->apply_group(
|
||||
$verify['id'],
|
||||
$this->member,
|
||||
$gid,
|
||||
$lid,
|
||||
$price,
|
||||
$my_verify
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
$this->_json(1, $rt['msg'], ['url' => MEMBER_URL]);
|
||||
}
|
||||
|
||||
// 付款方式
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'level' => $level,
|
||||
'group' => $group,
|
||||
'verify' => $verify,
|
||||
'myfield' => \Phpcmf\Service::L('Field')->toform(0, $field, $verify ? dr_string2array($verify['content']) : $this->member),
|
||||
'is_xufei' => $is_xufei,
|
||||
'pay_type' => dr_is_app('pay') ? \Phpcmf\Service::M('pay', 'pay')->get_pay_type(1) : [],
|
||||
'meta_title' => dr_lang(($is_xufei ? '续费' : '申请').'用户组').SITE_SEOJOIN.dr_lang('用户中心')
|
||||
]);
|
||||
\Phpcmf\Service::V()->display(is_file(dr_tpl_path(1).'apply_'.$gid.'.html') ? 'apply_'.$gid.'.html' : 'apply_index.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级用户组级别
|
||||
*/
|
||||
public function level() {
|
||||
|
||||
$gid = intval(\Phpcmf\Service::L('input')->get('gid'));
|
||||
if (!$this->member['groupid'][$gid]) {
|
||||
$this->_msg(0, dr_lang('你还不是该用户组成员'));
|
||||
}
|
||||
|
||||
$group = $this->member_cache['group'][$gid];
|
||||
if ($group['setting']['level']['auto']) {
|
||||
$this->_msg(0, dr_lang('此用户组是自动升级模式'));
|
||||
} elseif (!$group['level']) {
|
||||
if (!$this->member['groupid'][$gid]['setting']['timetype']
|
||||
&& !$this->member['groupid'][$gid]['setting']['level']['auto']
|
||||
&& !$this->member['groupid'][$gid]['setting']['timeout']
|
||||
&& !$this->member['groupid'][$gid]['level']
|
||||
) {
|
||||
// 没有开启等级,判断组是否运行续费功能
|
||||
$this->index();exit;
|
||||
}
|
||||
$this->_msg(0, dr_lang('此用户组没有创建用户级别'));
|
||||
}
|
||||
|
||||
$mylid = (int)$this->member['levelid'][$gid]; // 我的当前级别
|
||||
$myvalue = !$group['setting']['level']['price'] ? (int)$group['level'][$mylid]['value'] : 0; // 我的当前级别的升级值
|
||||
|
||||
if (!$group['level'][$mylid]['apply']) {
|
||||
$this->_msg(0, dr_lang('当前级别不允许升级'));
|
||||
}
|
||||
|
||||
// 列出当前可用的升级级别
|
||||
$level = [];
|
||||
$level2 = $group['level'];
|
||||
$is_xufei = 0;
|
||||
foreach ($level2 as $i => $t) {
|
||||
if (!$t['value']) {
|
||||
continue;
|
||||
}
|
||||
if ($mylid == $t['id'] && $group['setting']['timetype'] && !$group['setting']['level']['auto']) {
|
||||
$t['value2'] = $t['value'];
|
||||
$t['value'] = $t['setting']['xufei'] ? $t['setting']['xufei'] : $t['value'];
|
||||
$is_xufei = 1;
|
||||
} else {
|
||||
if ($mylid == $t['id']) {
|
||||
continue;
|
||||
}
|
||||
$t['value2'] = $t['value'];
|
||||
$t['value'] = $t['value'] - $myvalue;
|
||||
}
|
||||
|
||||
$level[$t['id']] = $t;
|
||||
}
|
||||
if (!$level) {
|
||||
$this->_msg(0, dr_lang('没有可用的用户组级别'));
|
||||
}
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$lid = intval($_POST['lid']);
|
||||
if (!$level[$lid]) {
|
||||
$this->_json(0, dr_lang('用户组级别不存在'));
|
||||
} elseif (!$level[$lid]['apply']) {
|
||||
$this->_json(0, dr_lang('用户组级别不允许升级'));
|
||||
} elseif ($level[$lid]['value'] < 0) {
|
||||
$this->_json(0, dr_lang('用户组级别升级值不规范'));
|
||||
}
|
||||
|
||||
// 申请用户组的级别之前的钩子
|
||||
\Phpcmf\Hooks::trigger('member_apply_level_before', ['uid' => $this->uid, 'gid' => $gid, 'lid' => $lid]);
|
||||
|
||||
$price = $level[$lid]['value'];
|
||||
if ($is_xufei) {
|
||||
$title = dr_lang('用户组(%s)续费: %s', $group['name'], $group['level'][$lid]['name']);
|
||||
} else {
|
||||
$title = dr_lang('用户组(%s)升级: %s', $group['name'], $group['level'][$lid]['name']);
|
||||
}
|
||||
|
||||
if ($price > 0) {
|
||||
// 存在价格时才扣钱
|
||||
if ($group['unit']) {
|
||||
// 金币
|
||||
$price = (int)$price;
|
||||
// 金币不足
|
||||
$this->member['score'] - $price < 0 && $this->_json(0, dr_lang('账户%s不足', SITE_SCORE));
|
||||
// 扣分
|
||||
$rt = \Phpcmf\Service::M('member')->add_score($this->uid, -$price, $title);
|
||||
if (!$rt['code']) {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
// 提醒通知
|
||||
\Phpcmf\Service::M('member')->notice($this->uid, 2, $title);
|
||||
} else {
|
||||
// rmb
|
||||
if (!dr_is_app('pay')) {
|
||||
$this->_msg(0, '没有安装「支付系统」插件');exit;
|
||||
}
|
||||
$price = floatval($price);
|
||||
// 支付方式
|
||||
$pay_type = \Phpcmf\Service::L('input')->post('pay_type');
|
||||
!$pay_type && $pay_type = 'finecms';
|
||||
// 唤起支付接口
|
||||
$pay = [
|
||||
'mark' => 'level-' . $group['id'] . '-' . $lid,
|
||||
'uid' => $this->member['uid'],
|
||||
'username' => $this->member['username'],
|
||||
'type' => $pay_type,
|
||||
'url' => '',
|
||||
'result' => '',
|
||||
'money' => $price,
|
||||
'title' => $title
|
||||
];
|
||||
$rt = \Phpcmf\Service::M('Pay', 'pay')->post($pay);
|
||||
if (!$rt['code']) {
|
||||
$this->_msg(0, $rt['msg']);
|
||||
exit;
|
||||
}
|
||||
// 必须跳转到统一的主域名中付款
|
||||
$url = PAY_URL . 'index.php?s=api&c=pay&id=' . $rt['code'];
|
||||
if (IS_AJAX || IS_API_HTTP) {
|
||||
// 回调页面
|
||||
$rt['data']['url'] = $url;
|
||||
$this->_json($rt['code'], dr_lang('请稍后'), $rt['data']);
|
||||
exit;
|
||||
} else {
|
||||
// 跳转到支付页面
|
||||
dr_redirect($url, 'auto');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M('member')->update_level($this->uid, $gid, $lid);
|
||||
if ($is_xufei) {
|
||||
$this->_json(1, dr_lang('开通成功'), ['url' => MEMBER_URL]);
|
||||
} else {
|
||||
$this->_json(1, dr_lang('续费成功'), ['url' => MEMBER_URL]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
// 删除不可用的升级级别
|
||||
if ($level) {
|
||||
foreach ($level as $i => $t) {
|
||||
if (!$t['apply']) {
|
||||
unset($level[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'level' => $level,
|
||||
'group' => $group,
|
||||
'myvalue' => $myvalue,
|
||||
'is_xufei' => $is_xufei,
|
||||
'pay_type' => dr_is_app('pay') ? \Phpcmf\Service::M('pay', 'pay')->get_pay_type(1) : [],
|
||||
'meta_title' => dr_lang(($is_xufei ? '续费' : '升级').'用户组级别').SITE_SEOJOIN.dr_lang('用户中心')
|
||||
]);
|
||||
\Phpcmf\Service::V()->display(is_file(dr_tpl_path(1).'apply_level_'.$gid.'.html') ? 'apply_level_'.$gid.'.html' : 'apply_level.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
class Content extends \Phpcmf\Table
|
||||
{
|
||||
/**
|
||||
* 兼容跳转
|
||||
*/
|
||||
public function comment() {
|
||||
|
||||
if (dr_is_app('comment')) {
|
||||
dr_redirect(dr_member_url('comment/content/index'));
|
||||
} else {
|
||||
$this->_admin_msg(0, dr_lang('系统没有安装评论插件'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
class Home extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
/**
|
||||
* 用户中心首页
|
||||
*/
|
||||
public function index() {
|
||||
|
||||
// 接口请求时返回会员数据
|
||||
IS_API_HTTP && $this->_json(1, dr_lang('认证成功'), $this->member);
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'meta_title' => dr_lang('用户中心')
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('index.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,494 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
class Login extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function __construct($object = NULL)
|
||||
{
|
||||
parent::__construct();
|
||||
if ($object) {
|
||||
foreach ($object as $var => $value) {
|
||||
$this->$var = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 正常登录
|
||||
public function index() {
|
||||
|
||||
// 获取返回页面
|
||||
$url = dr_safe_url($_GET['back'] ? urldecode((string)\Phpcmf\Service::L('input')->get('back')) : $_SERVER['HTTP_REFERER']);
|
||||
if (strpos($url, 'login') !== false || strpos($url, 'register') !== false) {
|
||||
$url = MEMBER_URL; // 当来自登录或注册页面时返回到用户中心去
|
||||
} else {
|
||||
$url = str_ireplace(['<iframe', '<', '/>'], '', $url);
|
||||
}
|
||||
|
||||
// 判断重复登录
|
||||
if ($this->uid) {
|
||||
if (IS_POST) {
|
||||
$this->_json(0, dr_lang('请退出登录账号再操作'));
|
||||
}
|
||||
$url = $url ? dr_redirect_safe_check($url) : MEMBER_URL;
|
||||
if (IS_DEV) {
|
||||
\Phpcmf\Service::C()->_admin_msg(1, '开发者模式:已经登录过了<br>正在自动跳转到用户中心(关闭开发者模式时即可自动跳转)', $url, 9);
|
||||
} else {
|
||||
dr_redirect($url);exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$back = dr_redirect_safe_check((string)\Phpcmf\Service::L('input')->xss_clean($_POST['back'] ? \Phpcmf\Service::L('input')->post('back') : MEMBER_URL, true));
|
||||
$back = str_ireplace(['<iframe', '<', '/>'], '', $back);
|
||||
// 回调钩子
|
||||
\Phpcmf\Hooks::trigger('member_login_before', $post);
|
||||
if ($this->member_cache['login']['code']
|
||||
&& !\Phpcmf\Service::L('Form')->check_captcha('code')) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'));
|
||||
} elseif (empty($post['password'])) {
|
||||
$this->_json(0, dr_lang('密码必须填写'));
|
||||
} elseif (empty($post['username'])) {
|
||||
$this->_json(0, dr_lang('账号必须填写'));
|
||||
} else {
|
||||
$rt = \Phpcmf\Service::M('member')->login(dr_safe_username($post['username']), $post['password'], (int)$_POST['remember']);
|
||||
if ($rt['code']) {
|
||||
// 登录成功
|
||||
$rt['data']['url'] = urldecode($back);
|
||||
return $this->_json(1, dr_lang('登录成功'), $rt['data'], true);
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(['back' => htmlspecialchars($url)]),
|
||||
'is_code' => $this->member_cache['login']['code'],
|
||||
'is_register' => $this->member_cache['register']['close'] ? 0 : 1,
|
||||
'meta_name' => dr_lang('用户登录'),
|
||||
'meta_title' => dr_lang('用户登录').SITE_SEOJOIN.SITE_NAME,
|
||||
]);
|
||||
return \Phpcmf\Service::V()->display('login.html');
|
||||
}
|
||||
|
||||
// 短信验证码登录
|
||||
public function sms() {
|
||||
|
||||
// 获取返回页面
|
||||
$url = dr_safe_url($_GET['back'] ? urldecode((string)\Phpcmf\Service::L('input')->get('back')) : $_SERVER['HTTP_REFERER']);
|
||||
strpos($url, 'login') !== false && $url = MEMBER_URL;
|
||||
|
||||
$is_img_code = $this->member_cache['login']['code'];
|
||||
// 当关闭图形验证码时,启用短信图形验证时,再次开启图形验证
|
||||
if (!$this->member_cache['login']['code'] && $this->member_cache['login']['sms'] && !SYS_SMS_IMG_CODE) {
|
||||
$is_img_code = 1;
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$back = dr_redirect_safe_check(\Phpcmf\Service::L('input')->xss_clean($_POST['back'] ? \Phpcmf\Service::L('input')->post('back') : MEMBER_URL));
|
||||
\Phpcmf\Hooks::trigger('member_login_before', $post);
|
||||
if ($is_img_code && !\Phpcmf\Service::L('Form')->check_captcha('code')) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'));
|
||||
} elseif (empty($post['phone'])) {
|
||||
$this->_json(0, dr_lang('手机号码必须填写'));
|
||||
} else {
|
||||
$sms = \Phpcmf\Service::L('Form')->get_mobile_code($post['phone']);
|
||||
if (!$sms) {
|
||||
$this->_json(0, dr_lang('未发送手机验证码'), ['field' => 'sms']);
|
||||
} elseif (!$_POST['sms']) {
|
||||
$this->_json(0, dr_lang('手机验证码未填写'), ['field' => 'sms']);
|
||||
} elseif ($sms != trim($_POST['sms'])) {
|
||||
$this->_json(0, dr_lang('手机验证码不正确'), ['field' => 'sms']);
|
||||
} else {
|
||||
$rt = \Phpcmf\Service::M('member')->login_sms($post['phone'], (int)$_POST['remember']);
|
||||
if ($rt['code']) {
|
||||
// 登录成功
|
||||
$rt['data']['url'] = urldecode($back);
|
||||
return $this->_json(1, 'ok', $rt['data'], true);
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_json(0, dr_lang('提交方式不正确'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权登录
|
||||
*/
|
||||
public function oauth() {
|
||||
|
||||
$id = intval(\Phpcmf\Service::L('input')->get('id'));
|
||||
$name = dr_safe_replace(\Phpcmf\Service::L('input')->get('name'));
|
||||
$auth_name = 'member_auth_login_'.$name.'_'.$id;
|
||||
$oauth_id = \Phpcmf\Service::L('cache')->get_auth_data($auth_name, SITE_ID, 300);
|
||||
if (!$oauth_id && !IS_XRDEV) {
|
||||
// 需要加强判断条件
|
||||
$this->_msg(0, IS_DEV ? dr_lang('授权信息(%s)获取失败', $name) : dr_lang('授权信息获取失败'));
|
||||
}
|
||||
|
||||
$oauth = \Phpcmf\Service::M()->table('member_oauth')->get($oauth_id);
|
||||
if (!$oauth && !IS_XRDEV) {
|
||||
$this->_msg(0, dr_lang('授权信息(#%s)不存在', $oauth_id));
|
||||
}
|
||||
|
||||
// 查询关联用户
|
||||
$member = [];
|
||||
if ($oauth['uid']) {
|
||||
$member = \Phpcmf\Service::M('member')->get_member($oauth['uid']);
|
||||
} elseif ($oauth['unionid']) {
|
||||
$row = \Phpcmf\Service::M()->table('member_oauth')->where('unionid', $oauth['unionid'])->where('uid>0')->getRow();
|
||||
if ($row) {
|
||||
// 直接绑定unionid用户
|
||||
\Phpcmf\Service::M()->table('member_oauth')->update($oauth['id'], [
|
||||
'uid' => $row['uid']
|
||||
]);
|
||||
$member = \Phpcmf\Service::M('member')->get_member($row['uid']);
|
||||
}
|
||||
}
|
||||
|
||||
// 跳转地址
|
||||
$back = urldecode(dr_redirect_safe_check(dr_safe_replace((string)\Phpcmf\Service::L('input')->get('back'))));
|
||||
$state = \Phpcmf\Service::L('input')->get('state');
|
||||
$goto_url = $back ? $back : MEMBER_URL;
|
||||
if ($state && $state != 'member') {
|
||||
$goto_url = strpos($state, 'http') === 0 ? $state : OAUTH_URL.'index.php?s=weixin&c='.$state.'&oid='.$oauth['oid'];
|
||||
}
|
||||
|
||||
if ($member) {
|
||||
|
||||
// 已经绑定,直接登录
|
||||
$sso = '';
|
||||
$member['uid'] = $oauth['uid'];
|
||||
$rt = \Phpcmf\Service::M('member')->login_oauth($name, $member);
|
||||
foreach ($rt as $url) {
|
||||
$sso.= '<script src="'.$url.'"></script>';
|
||||
}
|
||||
|
||||
// 删除认证缓存
|
||||
\Phpcmf\Service::L('cache')->del_auth_data($auth_name);
|
||||
|
||||
if (strpos($goto_url, 'is_admin_call')) {
|
||||
// 存储后台回话
|
||||
\Phpcmf\Service::M('auth')->save_login_auth($name, $member['uid']);
|
||||
$goto_url.= '&name='.$name.'&uid='.$member['uid'];
|
||||
return $this->_admin_msg(1, dr_lang('欢迎回来').$sso, \Phpcmf\Service::L('input')->xss_clean($goto_url), 0, true);
|
||||
} else {
|
||||
return $this->_msg(1, dr_lang('欢迎回来').$sso, \Phpcmf\Service::L('input')->xss_clean($goto_url), 0, true);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// 来自后台
|
||||
if (strpos($goto_url, 'is_admin_call')) {
|
||||
$this->_admin_msg(0, dr_lang('%s,没有绑定本站账号', dr_html2emoji($oauth['nickname'])));
|
||||
} elseif ($this->member_cache['register']['close']) {
|
||||
$this->_msg(0, dr_lang('系统关闭了注册功能'));
|
||||
} elseif (!$this->member_cache['register']['group']) {
|
||||
$this->_msg(0, dr_lang('系统没有可注册的用户组'));
|
||||
}
|
||||
|
||||
// 验证用户组
|
||||
$groupid = (int)\Phpcmf\Service::L('input')->get('groupid');
|
||||
if (!$groupid) {
|
||||
$groupid = (int)$this->member_cache['register']['groupid'];
|
||||
if (!$groupid) {
|
||||
$this->_msg(0, dr_lang('系统没有设置默认注册的用户组'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$groupid) {
|
||||
$this->_msg(0, dr_lang('无效的用户组'));
|
||||
} elseif (!$this->member_cache['group'][$groupid]['register']) {
|
||||
$this->_msg(0, dr_lang('该用户组不允许注册'));
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
'oauth' => $oauth,
|
||||
'group' => $this->member_cache['group'],
|
||||
'groupid' => $groupid,
|
||||
'register' => $this->member_cache['register'],
|
||||
]);
|
||||
|
||||
// 没有绑定账号
|
||||
if ($this->member_cache['oauth']['login']) {
|
||||
// 直接登录 就直接创建账号
|
||||
if ($this->member_cache['register']['group'] && dr_count($this->member_cache['register']['group']) > 1) {
|
||||
// 多个组需要选择
|
||||
if (IS_POST) {
|
||||
$groupid = (int)\Phpcmf\Service::L('input')->post('groupid');
|
||||
if (!$this->member_cache['group'][$groupid]['register']) {
|
||||
$this->_json(0, dr_lang('该用户组不允许注册'));
|
||||
}
|
||||
// 注册
|
||||
$rt = \Phpcmf\Service::M('member')->register_oauth($groupid, $oauth);
|
||||
if ($rt['code']) {
|
||||
// 登录成功
|
||||
$rt['data']['url'] = \Phpcmf\Service::L('input')->xss_clean($goto_url);
|
||||
// 删除认证缓存
|
||||
\Phpcmf\Service::L('cache')->del_auth_data($auth_name);
|
||||
if (dr_is_app('weixin') && $oauth['oauth'] == 'wechat') {
|
||||
$url = SITE_URL.'index.php?s=weixin&c=go&url='.urlencode($goto_url);
|
||||
$this->_json(1, dr_lang('登录成功'), ['url' => $url, 'sso' => ''], true);exit;
|
||||
}
|
||||
return $this->_json(1, 'ok', $rt['data'], true);
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'meta_name' => dr_lang('授权登录'),
|
||||
'meta_title' => dr_lang('授权登录').SITE_SEOJOIN.SITE_NAME,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('login_select.html');
|
||||
} else {
|
||||
// 单个用户组组直接注册
|
||||
$rt = \Phpcmf\Service::M('member')->register_oauth(0, $oauth);
|
||||
if ($rt['code']) {
|
||||
// 登录成功
|
||||
$rt['data']['url'] = \Phpcmf\Service::L('input')->xss_clean($goto_url);
|
||||
// 删除认证缓存
|
||||
\Phpcmf\Service::L('cache')->del_auth_data($auth_name);
|
||||
$sso = '';
|
||||
foreach ($rt['data']['sso'] as $url) {
|
||||
$sso.= '<script src="'.$url.'"></script>';
|
||||
}
|
||||
if (dr_is_app('weixin') && $oauth['oauth'] == 'wechat') {
|
||||
$url = SITE_URL.'index.php?s=weixin&c=go&url='.urlencode($goto_url);
|
||||
$this->_json(1, dr_lang('登录成功'), ['url' => $url, 'sso' => ''], true);exit;
|
||||
}
|
||||
return $this->_msg(1, dr_lang('登录成功').$sso, $goto_url, true);
|
||||
} else {
|
||||
$this->_msg(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 绑定账号 绑定已有的账号或者注册新账号
|
||||
$type = intval(\Phpcmf\Service::L('input')->get('type'));
|
||||
if ($type) {
|
||||
// 获取该组可用注册字段
|
||||
$field = [];
|
||||
if ($this->member_cache['group'][$groupid]['register_field']) {
|
||||
foreach ($this->member_cache['group'][$groupid]['register_field'] as $fname) {
|
||||
$field[$fname] = $this->member_cache['field'][$fname];
|
||||
$field[$fname]['ismember'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IS_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
if (!\Phpcmf\Service::L('input')->post('is_protocol')) {
|
||||
$this->_json(0, dr_lang('你没有同意注册协议'));
|
||||
}
|
||||
if ($type) {
|
||||
// 注册绑定
|
||||
if (empty($post['password'])) {
|
||||
$this->_json(0, dr_lang('密码必须填写'), ['field' => 'password']);
|
||||
} elseif ($post['password'] != $post['password2']) {
|
||||
$this->_json(0, dr_lang('确认密码不一致'), ['field' => 'password2']);
|
||||
} else {
|
||||
// 注册之前的钩子
|
||||
\Phpcmf\Hooks::trigger('member_register_before', $post);
|
||||
// 验证操作
|
||||
if ($this->member_cache['register']['sms']) {
|
||||
$sms = \Phpcmf\Service::L('Form')->get_mobile_code($post['phone']);
|
||||
if (!$sms) {
|
||||
$this->_json(0, dr_lang('未发送手机验证码'), ['field' => 'sms']);
|
||||
} elseif (!$_POST['sms']) {
|
||||
$this->_json(0, dr_lang('手机验证码未填写'), ['field' => 'sms']);
|
||||
} elseif ($sms != (string)$_POST['sms']) {
|
||||
$this->_json(0, dr_lang('手机验证码不正确'), ['field' => 'sms']);
|
||||
}
|
||||
}
|
||||
// 验证字段
|
||||
if ($this->member_cache['oauth']['field']) {
|
||||
list($data, $return, $attach) = \Phpcmf\Service::L('Form')->validation($post, null, $field);
|
||||
// 输出错误
|
||||
if ($return) {
|
||||
$this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
}
|
||||
} else {
|
||||
$data = [1 => []];
|
||||
$attach = [];
|
||||
}
|
||||
|
||||
// 入库记录
|
||||
$rt = \Phpcmf\Service::M('member')->register_oauth_bang($oauth, $groupid, [
|
||||
'username' => (string)$post['username'],
|
||||
'phone' => (string)$post['phone'],
|
||||
'email' => (string)$post['email'],
|
||||
'password' => dr_safe_password($post['password']),
|
||||
'name' => dr_safe_replace($post['name']),
|
||||
], $data[1]);
|
||||
if ($rt['code']) {
|
||||
// 注册绑定成功
|
||||
$this->member = $rt['data'];
|
||||
\Phpcmf\Service::M('member')->save_cookie($this->member, 1);
|
||||
// 附件归档
|
||||
SYS_ATTACHMENT_DB && $attach && \Phpcmf\Service::M('Attachment')->handle(
|
||||
$this->member['id'],
|
||||
\Phpcmf\Service::M()->dbprefix('member').'-'.$rt['code'],
|
||||
$attach
|
||||
);
|
||||
// 手机认证成功
|
||||
if ($this->member_cache['register']['sms']) {
|
||||
\Phpcmf\Service::M()->db->table('member_data')->where('id', $this->member['id'])->update(['is_mobile' => 1]);
|
||||
}
|
||||
$rt['data']['url'] = \Phpcmf\Service::L('input')->xss_clean($goto_url);
|
||||
// 删除认证缓存
|
||||
\Phpcmf\Service::L('cache')->del_auth_data($auth_name);
|
||||
if (dr_is_app('weixin') && $oauth['oauth'] == 'wechat') {
|
||||
$url = SITE_URL.'index.php?s=weixin&c=go&url='.urlencode($goto_url);
|
||||
$this->_json(1, dr_lang('绑定成功'), ['url' => $url, 'sso' => ''], true);exit;
|
||||
}
|
||||
$this->_json(1, dr_lang('注册成功'), $rt['data'], true);
|
||||
} else {
|
||||
$this->_json(0, $rt['msg'], ['field' => $rt['data']['field']]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 登录绑定
|
||||
if (empty($post['username']) || empty($post['password'])) {
|
||||
$this->_json(0, dr_lang('账号或密码必须填写'));
|
||||
} else {
|
||||
\Phpcmf\Hooks::trigger('member_login_before', $post);
|
||||
$rt = \Phpcmf\Service::M('member')->login($post['username'], $post['password'], (int)$_POST['remember']);
|
||||
if ($rt['code']) {
|
||||
// 登录成功
|
||||
$rt['data']['url'] = \Phpcmf\Service::L('input')->xss_clean($goto_url);
|
||||
// 删除认证缓存
|
||||
\Phpcmf\Service::L('cache')->del_auth_data($auth_name);
|
||||
// 删除旧账号
|
||||
\Phpcmf\Service::M()->db->table('member_oauth')->where('oauth', $oauth['oauth'])->where('uid', $rt['data']['member']['id'])->delete();
|
||||
// 更改状态
|
||||
\Phpcmf\Service::M()->db->table('member_oauth')->where('id', $oauth['id'])->update(['uid' => $rt['data']['member']['id']]);
|
||||
if (dr_is_app('weixin') && $oauth['oauth'] == 'wechat') {
|
||||
\Phpcmf\Service::M()->db->table('weixin_user')->where('openid', $oauth['oid'])->update([
|
||||
'uid' => $rt['data']['member']['id'],
|
||||
'username' => $rt['data']['member']['username'],
|
||||
]);
|
||||
$url = SITE_URL.'index.php?s=weixin&c=go&url='.urlencode($goto_url);
|
||||
$this->_json(1, dr_lang('绑定成功'), ['url' => $url, 'sso' => ''], true);exit;
|
||||
}
|
||||
$this->_json(1, dr_lang('绑定成功'), $rt['data'], true);
|
||||
} else {
|
||||
$this->_json(0, $rt['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$is_img_code = $this->member_cache['register']['code'];
|
||||
|
||||
// 当关闭图形验证码时,启用短信图形验证时,再次开启图形验证
|
||||
if (!$this->member_cache['register']['code'] && $this->member_cache['register']['sms'] && !SYS_SMS_IMG_CODE) {
|
||||
$is_img_code = 1;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'type' => $type,
|
||||
'form' => dr_form_hidden(['type' => $type]),
|
||||
'myfield' => $type && $this->member_cache['oauth']['field'] ? \Phpcmf\Service::L('field')->toform(0, $field) : '',
|
||||
'register' => $this->member_cache['register'],
|
||||
'meta_name' => dr_lang('绑定账号'),
|
||||
'meta_title' => dr_lang('绑定账号').SITE_SEOJOIN.SITE_NAME,
|
||||
'is_img_code' => $is_img_code,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('login_oauth.html');
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找回密码
|
||||
*/
|
||||
public function find() {
|
||||
|
||||
if (IS_POST) {
|
||||
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$value = dr_safe_replace($post['value']);
|
||||
if (strpos($value, '@') !== false) {
|
||||
// 邮箱模式
|
||||
$data = \Phpcmf\Service::M()->db->table('member')->where('email', $value)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('账号凭证不存在'), ['field' => 'value']);
|
||||
}
|
||||
} elseif (is_numeric($value) && strlen($value) == 11) {
|
||||
// 手机
|
||||
$data = \Phpcmf\Service::M()->db->table('member')->where('phone', $value)->get()->getRowArray();
|
||||
if (!$data) {
|
||||
$this->_json(0, dr_lang('账号凭证不存在'), ['field' => 'value']);
|
||||
}
|
||||
} else {
|
||||
$this->_json(0, dr_lang('账号凭证格式不正确'), ['field' => 'value']);
|
||||
}
|
||||
|
||||
// 防止验证码猜测
|
||||
if (dr_is_app('xrsafe')) {
|
||||
// 如果安装迅睿安全插件,进入插件验证机制
|
||||
\Phpcmf\Service::M('safe', 'xrsafe')->find_check($value);
|
||||
} else {
|
||||
// 普通验证
|
||||
$sn = 'fc_pass_find_'.date('Ymd', SYS_TIME).$value;
|
||||
$count = (int)\Phpcmf\Service::L('cache')->get_data($sn);
|
||||
if ($count > 20) {
|
||||
$this->_json(0, dr_lang('今日找回密码次数达到上限'));
|
||||
}
|
||||
\Phpcmf\Service::L('cache')->set_data($sn, $count + 1, 3600 * 24);
|
||||
}
|
||||
|
||||
if ((!$post['code'] || !$data['randcode'] || $post['code'] != $data['randcode'])) {
|
||||
$this->_json(0, dr_lang('凭证验证码不正确'), ['field' => 'code']);
|
||||
} elseif (!$post['password']) {
|
||||
$this->_json(0, dr_lang('密码不能为空'), ['field' => 'password']);
|
||||
} elseif ($post['password'] != $post['password2']) {
|
||||
$this->_json(0, dr_lang('两次密码不一致'), ['field' => 'password2']);
|
||||
}
|
||||
|
||||
// 修改密码
|
||||
\Phpcmf\Service::M('member')->edit_password($data, $post['password']);
|
||||
\Phpcmf\Service::M()->db->table('member')->where('id', $data['id'])->update(['randcode' => 0]);
|
||||
|
||||
$this->_json(-1, dr_lang('账号[%s]密码修改成功', $data['username']), $data);
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(),
|
||||
'api_url' => dr_member_url('api/find_code'),
|
||||
'meta_name' => dr_lang('找回密码'),
|
||||
'meta_title' => dr_lang('找回密码').SITE_SEOJOIN.SITE_NAME,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('find.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
public function out() {
|
||||
|
||||
// 注销授权登陆的会员
|
||||
if ($this->session()->get('member_auth_uid')) {
|
||||
\Phpcmf\Service::C()->session()->delete('member_auth_uid');
|
||||
$this->_json(0, dr_lang('当前状态无法退出账号'));
|
||||
}
|
||||
|
||||
$this->_json(1, dr_lang('您的账号已退出系统'), [
|
||||
'url' => dr_safe_url(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : SITE_URL),
|
||||
'sso' => \Phpcmf\Service::M('member')->logout(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
$file = dr_get_app_dir('pay').'Controllers/Member/Pay.php';
|
||||
if (is_file($file)) {
|
||||
require_once $file;
|
||||
} else {
|
||||
\dr_exit_msg(0, '没有安装「支付系统」插件');
|
||||
}
|
||||
|
||||
// 付款
|
||||
class Pay extends \Phpcmf\Controllers\Member\Pay
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
$file = dr_get_app_dir('pay').'Controllers/Member/Paylog.php';
|
||||
if (is_file($file)) {
|
||||
require_once $file;
|
||||
} else {
|
||||
\dr_exit_msg(0, '没有安装「支付系统」插件');
|
||||
}
|
||||
|
||||
class Paylog extends \Phpcmf\Controllers\Member\Paylog
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
$file = dr_get_app_dir('pay').'Controllers/Member/Recharge.php';
|
||||
if (is_file($file)) {
|
||||
require_once $file;
|
||||
} else {
|
||||
\dr_exit_msg(0, '没有安装「支付系统」插件');
|
||||
}
|
||||
|
||||
class Recharge extends \Phpcmf\Controllers\Member\Recharge
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
class Register extends \Phpcmf\Common
|
||||
{
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function __construct($object = NULL)
|
||||
{
|
||||
parent::__construct();
|
||||
if ($object) {
|
||||
foreach ($object as $var => $value) {
|
||||
$this->$var = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 注册
|
||||
public function index() {
|
||||
|
||||
// 获取返回URL
|
||||
$url = dr_safe_url($_GET['back'] ? urldecode((string)\Phpcmf\Service::L('input')->get('back')) : $_SERVER['HTTP_REFERER']);
|
||||
$url && parse_str($url, $arr);
|
||||
if (isset($arr['back']) && $arr['back']) {
|
||||
$url = \Phpcmf\Service::L('input')->xss_clean($arr['back']);
|
||||
}
|
||||
if (strpos($url, 'login') !== false || strpos($url, 'register') !== false) {
|
||||
$url = MEMBER_URL; // 当来自登录或注册页面时返回到用户中心去
|
||||
} else {
|
||||
$url = \Phpcmf\Service::L('input')->xss_clean($url, true);
|
||||
$url = str_ireplace(['<iframe', '<', '/>'], '', $url);
|
||||
}
|
||||
|
||||
// 判断重复登录
|
||||
if ($this->uid) {
|
||||
if (IS_POST) {
|
||||
$this->_json(0, dr_lang('请退出登录账号再操作'));
|
||||
}
|
||||
dr_redirect($url ? $url : MEMBER_URL);exit;
|
||||
}
|
||||
|
||||
// 验证系统是否支持注册
|
||||
if ($this->member_cache['register']['close']) {
|
||||
$this->_msg(0, dr_lang('系统关闭了注册功能'));
|
||||
} elseif (!$this->member_cache['register']['groupid']) {
|
||||
$this->_msg(0, dr_lang('系统没有设置默认注册的用户组'));
|
||||
} elseif (!$this->member_cache['register']['group']) {
|
||||
$this->_msg(0, dr_lang('系统没有可注册的用户组'));
|
||||
} elseif (!$this->member_cache['register']['field']) {
|
||||
$this->_msg(0, dr_lang('系统没有可用的注册字段'));
|
||||
} elseif (!dr_array_intersect($this->member_cache['register']['field'], ['username', 'email', 'phone'])) {
|
||||
$this->_msg(0, dr_lang('必须设置用户名、邮箱、手机的其中一个设为可注册字段'));
|
||||
}
|
||||
|
||||
// 验证用户组
|
||||
$groupid = (int)\Phpcmf\Service::L('input')->get('groupid');
|
||||
!$groupid && $groupid = (int)$this->member_cache['register']['groupid'];
|
||||
if (!$groupid) {
|
||||
$this->_msg(0, dr_lang('无效的用户组'));
|
||||
} elseif (!$this->member_cache['group'][$groupid]['register']) {
|
||||
$this->_msg(0, dr_lang('用户组[%s]不允许注册', $this->member_cache['group'][$groupid]['name']));
|
||||
}
|
||||
// 初始化自定义字段类
|
||||
\Phpcmf\Service::L('Field')->app(APP_DIR);
|
||||
|
||||
// 获取该组可用注册字段
|
||||
$field = [];
|
||||
if ($this->member_cache['group'][$groupid]['register_field']) {
|
||||
foreach ($this->member_cache['group'][$groupid]['register_field'] as $fname) {
|
||||
$field[$fname] = $this->member_cache['field'][$fname];
|
||||
$field[$fname]['ismember'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_AJAX_POST) {
|
||||
$post = \Phpcmf\Service::L('input')->post('data');
|
||||
$back = dr_redirect_safe_check(\Phpcmf\Service::L('input')->xss_clean($_POST['back'] ? \Phpcmf\Service::L('input')->post('back') : MEMBER_URL, true));
|
||||
if (!\Phpcmf\Service::L('input')->post('is_protocol')) {
|
||||
$this->_json(0, dr_lang('你没有同意注册协议'));
|
||||
} elseif ($this->member_cache['register']['code']
|
||||
&& !\Phpcmf\Service::L('Form')->check_captcha('code')) {
|
||||
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
|
||||
} elseif (empty($post['password'])) {
|
||||
$this->_json(0, dr_lang('密码必须填写'), ['field' => 'password']);
|
||||
} elseif ($post['password'] != $post['password2']) {
|
||||
$this->_json(0, dr_lang('确认密码不一致'), ['field' => 'password2']);
|
||||
} else {
|
||||
// 注册之前的钩子
|
||||
$arr = ['username' => '账号', 'email' => '邮箱', 'phone' => '电话'];
|
||||
foreach ($this->member_cache['register']['field'] as $k) {
|
||||
if (!isset($post[$k]) || !$post[$k]) {
|
||||
$this->_json(0, dr_lang('%s必须填写', dr_lang($arr[$k])), ['field' => $k]);
|
||||
}
|
||||
}
|
||||
\Phpcmf\Hooks::trigger('member_register_before', $post);
|
||||
// 验证操作
|
||||
$check = '';
|
||||
if ($this->member_cache['register']['sms'] || $this->member_cache['register']['email']) {
|
||||
$sms = \Phpcmf\Service::L('Form')->get_mobile_code($post['phone']);
|
||||
$email = \Phpcmf\Service::L('Form')->get_mobile_code($post['email']);
|
||||
if ($sms) {
|
||||
$check = 'sms';
|
||||
} elseif ($email) {
|
||||
$check = 'email';
|
||||
} else {
|
||||
$this->_json(0, dr_lang('未发送验证码'));
|
||||
}
|
||||
}
|
||||
if ($check == 'sms') {
|
||||
if (!$_POST['sms']) {
|
||||
$this->_json(0, dr_lang('手机验证码未填写'), ['field' => 'sms']);
|
||||
} elseif ($sms != trim($_POST['sms'])) {
|
||||
$this->_json(0, dr_lang('手机验证码不正确'), ['field' => 'sms']);
|
||||
}
|
||||
} elseif ($check == 'email') {
|
||||
if (!$_POST['email_code']) {
|
||||
$this->_json(0, dr_lang('邮箱验证码未填写'), ['field' => 'sms']);
|
||||
} elseif ($sms != trim($_POST['email_code'])) {
|
||||
$this->_json(0, dr_lang('邮箱验证码不正确'), ['field' => 'sms']);
|
||||
}
|
||||
}
|
||||
|
||||
// 验证字段
|
||||
list($data, $return, $attach) = \Phpcmf\Service::L('Form')->validation($post, null, $field);
|
||||
// 输出错误
|
||||
if ($return) {
|
||||
$this->_json(0, $return['error'], ['field' => $return['name']]);
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('member')->register($groupid, [
|
||||
'username' => (string)$post['username'],
|
||||
'phone' => (string)$post['phone'],
|
||||
'email' => (string)$post['email'],
|
||||
'password' => dr_safe_password($post['password']),
|
||||
'name' => dr_safe_replace($post['name']),
|
||||
], $data[1]);
|
||||
if ($rt['code']) {
|
||||
// 注册成功
|
||||
$remember = 0;
|
||||
$this->member = $rt['data'];
|
||||
// 保存本地会话
|
||||
\Phpcmf\Service::M('member')->save_cookie($this->member, $remember);
|
||||
// 附件归档
|
||||
SYS_ATTACHMENT_DB && $attach && \Phpcmf\Service::M('Attachment')->handle(
|
||||
$this->member['id'],
|
||||
\Phpcmf\Service::M()->dbprefix('member').'-'.$rt['code'],
|
||||
$attach
|
||||
);
|
||||
// 手机认证成功
|
||||
if ($this->member_cache['register']['sms']) {
|
||||
\Phpcmf\Service::M()->db->table('member_data')->where('id', $this->member['id'])->update(['is_mobile' => 1]);
|
||||
}
|
||||
$back = str_ireplace(['<iframe', '<', '/>'], '', $back);
|
||||
return $this->_json(1, $rt['msg'], [
|
||||
'url' => urldecode($back),
|
||||
'sso' => \Phpcmf\Service::M('member')->sso($this->member, $remember),
|
||||
'member' => $this->member,
|
||||
], true);
|
||||
} else {
|
||||
$this->_json(0, $rt['msg'], ['field' => $rt['data']['field']]);
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$is_img_code = $this->member_cache['register']['code'];
|
||||
|
||||
// 当关闭图形验证码时,启用短信图形验证时,再次开启图形验证
|
||||
if (!$this->member_cache['register']['code'] && $this->member_cache['register']['sms'] && !SYS_SMS_IMG_CODE) {
|
||||
$is_img_code = 1;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'form' => dr_form_hidden(['back' => htmlspecialchars($url)]),
|
||||
'group' => $this->member_cache['group'],
|
||||
'groupid' => $groupid,
|
||||
'is_code' => $this->member_cache['register']['code'],
|
||||
'myfield' => \Phpcmf\Service::L('field')->toform(0, $field),
|
||||
'register' => $this->member_cache['register'],
|
||||
'meta_name' => dr_lang('用户注册'),
|
||||
'meta_title' => dr_lang('用户注册').SITE_SEOJOIN.SITE_NAME,
|
||||
'is_img_code' => $is_img_code,
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('register.html');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user