Skip to content

Commit

Permalink
新增:支持设置用户私聊权限
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Feb 14, 2023
1 parent 34aafc1 commit 4b6e17e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
4 changes: 0 additions & 4 deletions app/CodeFec/View/HyperfViewEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public function render($template, $data, $config): string
foreach ($plugin_list as $value) {
$factory->addNamespace($value, plugin_path($value . '/resources/views'));
}
// 替换
foreach (Themes()->get() as $namespace => $hints) {
$factory->replaceNamespace($namespace, $hints);
}
// 主题
$name = get_options('theme', 'CodeFec');
$factory->replaceNamespace('App', theme_path($name . '/resources/views'));
Expand Down
2 changes: 2 additions & 0 deletions app/Plugins/Core/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
Authority()->add('admin_report', '受理举报');
Authority()->add('upload_file', '上传附件');
Authority()->add('upload_image', '上传图片');
Authority()->add('user_private_chat', '私聊');
Authority()->add('core_shortCode_InvitationCode', '使用邀请码ShortCode');

Itf()->add('core_auth_selected', 'topic_edit', 'topic_edit');
Itf()->add('core_auth_selected', 'user_private_chat', 'user_private_chat');
Itf()->add('core_auth_selected', 'topic_create', 'topic_create');
Itf()->add('core_auth_selected', 'comment_create', 'comment_create');
Itf()->add('core_auth_selected', 'comment_edit', 'comment_edit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class IndexController
#[GetMapping(path: '{user_id}')]
public function index($user_id)
{
if (! Authority()->check('user_private_chat')) {
return admin_abort('你所在的用户组无私聊权限');
}
if (! User::query()->where('id', $user_id)->exists()) {
return redirect()->back()->with('danger', '用户不存在')->go();
}
Expand Down Expand Up @@ -51,6 +54,6 @@ public function index($user_id)
$contacts[$key]['msgCount'] = $count;
}
$msgExists = UsersPm::query()->where([['from_id', auth()->id()], ['to_id', $user_id]])->Orwhere([['to_id', auth()->id()], ['from_id', $user_id]])->exists();
return view('User::pm.index', ['user' => $user, 'messagesCount' => $messagesCount, 'messages' => $messages, 'contacts' => $contacts,'msgExists' => $msgExists]);
return view('User::pm.index', ['user' => $user, 'messagesCount' => $messagesCount, 'messages' => $messages, 'contacts' => $contacts, 'msgExists' => $msgExists]);
}
}
6 changes: 6 additions & 0 deletions app/Plugins/User/src/Controller/Api/PmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class PmController
#[PostMapping(path: 'send_msg')]
public function send_msg()
{
if (! Authority()->check('user_private_chat')) {
return admin_abort('你所在的用户组无私聊权限');
}
$user_id = request()->input('user_id');
$msg = request()->input('content');
if (! $user_id || ! User::query()->where('id', $user_id)->exists()) {
Expand All @@ -54,6 +57,9 @@ public function send_msg()
#[PostMapping(path: 'get_msg')]
public function get_msg()
{
if (! Authority()->check('user_private_chat')) {
return admin_abort('你所在的用户组无私聊权限');
}
$user_id = request()->input('user_id');
if (! $user_id || ! User::query()->where('id', $user_id)->exists()) {
return json_api(403, false, ['msg' => '私信用户不存在']);
Expand Down
4 changes: 2 additions & 2 deletions app/Plugins/User/src/Middleware/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
}
// 邮箱验证
if ((int) get_options('core_user_email_ver', 1) === 1 && ! strtotime(@$auth->email_ver_time?:'1') && request()->path() !== 'user/ver_email' && request()->path() !== 'user/ver_phone' && request()->path() !== 'user/ver_phone/send') {
if ((int) get_options('core_user_email_ver', 1) === 1 && ! strtotime(@$auth->email_ver_time ?: '1') && request()->path() !== 'user/ver_email' && request()->path() !== 'user/ver_phone' && request()->path() !== 'user/ver_phone/send') {
return redirect()->url('/user/ver_email')->go();
}
// 手机号验证
if (get_options('core_user_sms', '关闭') === '开启' && ! strtotime(@$auth->phone_ver_time?:'1') && request()->path() !== 'user/ver_phone' && request()->path() !== 'user/ver_email'
if (get_options('core_user_sms', '关闭') === '开启' && ! strtotime(@$auth->phone_ver_time ?: '1') && request()->path() !== 'user/ver_phone' && request()->path() !== 'user/ver_email'
&& request()->path() !== 'user/ver_phone/send'
) {
return redirect()->url('/user/ver_phone')->go();
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'connection' => 'default',
'path' => BASE_PATH . '/runtime/session',
'gc_maxlifetime' => 72 * 60 * 60,
'session_name' => env('APP_NAME', 'CODEFEC_SESSION_ID'),
'session_name' => env('APP_KEY', 'CODEFEC_SESSION_ID'),
'domain' => null,
'cookie_lifetime' => 72 * 60 * 60,
],
Expand Down
19 changes: 5 additions & 14 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

declare(strict_types=1);
/**
* This file is part of Hyperf.
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/SForum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/SForum/blob/master/LICENSE
*/
use App\CodeFec\Plugins;
use App\Controller\AdminController;
use Hyperf\HttpServer\Router\Router;

Expand All @@ -23,11 +22,3 @@
}, [
'middleware' => [\App\Middleware\AdminMiddleware::class],
]);

// 扩展路由

foreach ((new Plugins())->getEnPlugins() as $value) {
if (file_exists(plugin_path($value . '/routes.php'))) {
require plugin_path($value . '/routes.php');
}
}

0 comments on commit 4b6e17e

Please sign in to comment.