2020-02-18 07:22:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use Cache, DB;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\ModLog;
|
2020-02-20 03:45:11 +00:00
|
|
|
use App\Profile;
|
2020-02-18 07:22:47 +00:00
|
|
|
use App\User;
|
|
|
|
use App\Mail\AdminMessage;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
use App\Services\ModLogService;
|
2020-02-20 05:55:10 +00:00
|
|
|
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
2020-02-18 07:22:47 +00:00
|
|
|
|
|
|
|
trait AdminUserController
|
|
|
|
{
|
|
|
|
public function users(Request $request)
|
|
|
|
{
|
|
|
|
$col = $request->query('col') ?? 'id';
|
|
|
|
$dir = $request->query('dir') ?? 'desc';
|
|
|
|
$users = User::select('id', 'username', 'status')
|
|
|
|
->withCount('statuses')
|
|
|
|
->orderBy($col, $dir)
|
|
|
|
->simplePaginate(10);
|
|
|
|
|
|
|
|
return view('admin.users.home', compact('users'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userShow(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
return view('admin.users.show', compact('user', 'profile'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userEdit(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
return view('admin.users.edit', compact('user', 'profile'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userEditSubmit(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$changed = false;
|
2020-02-20 06:23:52 +00:00
|
|
|
$fields = [];
|
2020-02-18 07:22:47 +00:00
|
|
|
|
|
|
|
if($request->filled('name') && $request->input('name') != $user->name) {
|
2020-02-20 06:23:52 +00:00
|
|
|
$fields['name'] = ['old' => $user->name, 'new' => $request->input('name')];
|
2020-02-18 07:22:47 +00:00
|
|
|
$user->name = $profile->name = $request->input('name');
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
if($request->filled('username') && $request->input('username') != $user->username) {
|
2020-02-20 06:23:52 +00:00
|
|
|
$fields['username'] = ['old' => $user->username, 'new' => $request->input('username')];
|
2020-02-18 07:22:47 +00:00
|
|
|
$user->username = $profile->username = $request->input('username');
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
if($request->filled('email') && $request->input('email') != $user->email) {
|
|
|
|
if(filter_var($request->input('email'), FILTER_VALIDATE_EMAIL) == false) {
|
|
|
|
abort(500, 'Invalid email address');
|
|
|
|
}
|
2020-02-20 06:23:52 +00:00
|
|
|
$fields['email'] = ['old' => $user->email, 'new' => $request->input('email')];
|
2020-02-18 07:22:47 +00:00
|
|
|
$user->email = $request->input('email');
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
if($request->input('bio') != $profile->bio) {
|
2020-02-20 06:23:52 +00:00
|
|
|
$fields['bio'] = ['old' => $user->bio, 'new' => $request->input('bio')];
|
2020-02-18 07:22:47 +00:00
|
|
|
$profile->bio = $request->input('bio');
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
if($request->input('website') != $profile->website) {
|
2020-02-20 06:23:52 +00:00
|
|
|
$fields['website'] = ['old' => $user->website, 'new' => $request->input('website')];
|
2020-02-18 07:22:47 +00:00
|
|
|
$profile->website = $request->input('website');
|
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($changed == true) {
|
2020-02-20 07:01:18 +00:00
|
|
|
ModLogService::boot()
|
|
|
|
->objectUid($user->id)
|
|
|
|
->objectId($user->id)
|
|
|
|
->objectType('App\User::class')
|
|
|
|
->user($request->user())
|
|
|
|
->action('admin.user.edit')
|
|
|
|
->metadata([
|
|
|
|
'fields' => $fields
|
|
|
|
])
|
|
|
|
->accessLevel('admin')
|
|
|
|
->save();
|
2020-02-18 07:22:47 +00:00
|
|
|
$profile->save();
|
|
|
|
$user->save();
|
|
|
|
}
|
2020-02-20 06:23:52 +00:00
|
|
|
|
|
|
|
|
2020-02-18 07:22:47 +00:00
|
|
|
return redirect('/i/admin/users/show/' . $user->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userActivity(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$logs = $user->accountLog()->orderByDesc('created_at')->paginate(10);
|
|
|
|
return view('admin.users.activity', compact('user', 'profile', 'logs'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userMessage(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
return view('admin.users.message', compact('user', 'profile'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userMessageSend(Request $request, $id)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'message' => 'required|string|min:5|max:500'
|
|
|
|
]);
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$message = $request->input('message');
|
|
|
|
Mail::to($user->email)->send(new AdminMessage($message));
|
|
|
|
ModLogService::boot()
|
|
|
|
->objectUid($user->id)
|
|
|
|
->objectId($user->id)
|
|
|
|
->objectType('App\User::class')
|
|
|
|
->user($request->user())
|
|
|
|
->action('admin.user.mail')
|
|
|
|
->metadata([
|
|
|
|
'message' => $message
|
|
|
|
])
|
|
|
|
->accessLevel('admin')
|
|
|
|
->save();
|
|
|
|
return redirect('/i/admin/users/show/' . $user->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userModTools(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
return view('admin.users.modtools', compact('user', 'profile'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userModLogs(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$logs = ModLog::whereObjectUid($user->id)
|
|
|
|
->orderByDesc('created_at')
|
|
|
|
->simplePaginate(10);
|
|
|
|
return view('admin.users.modlogs', compact('user', 'profile', 'logs'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userModLogsMessage(Request $request, $id)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'message' => 'required|string|min:5|max:500'
|
|
|
|
]);
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
$msg = $request->input('message');
|
|
|
|
ModLogService::boot()
|
|
|
|
->objectUid($user->id)
|
|
|
|
->objectId($user->id)
|
|
|
|
->objectType('App\User::class')
|
|
|
|
->user($request->user())
|
|
|
|
->message($msg)
|
|
|
|
->accessLevel('admin')
|
|
|
|
->save();
|
|
|
|
return redirect('/i/admin/users/modlogs/' . $user->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userDelete(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
return view('admin.users.delete', compact('user', 'profile'));
|
|
|
|
}
|
2020-02-20 03:45:11 +00:00
|
|
|
|
2020-02-20 05:55:10 +00:00
|
|
|
public function userDeleteProcess(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
|
|
|
|
if(config('pixelfed.account_deletion') == false) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($user->is_admin == true) {
|
|
|
|
$mid = $request->user()->id;
|
|
|
|
abort_if($user->id < $mid, 403);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ts = now()->addMonth();
|
|
|
|
$user->status = 'delete';
|
|
|
|
$profile->status = 'delete';
|
|
|
|
$user->delete_after = $ts;
|
|
|
|
$profile->delete_after = $ts;
|
|
|
|
$user->save();
|
|
|
|
$profile->save();
|
2020-02-20 06:23:52 +00:00
|
|
|
|
|
|
|
ModLogService::boot()
|
|
|
|
->objectUid($user->id)
|
|
|
|
->objectId($user->id)
|
|
|
|
->objectType('App\User::class')
|
|
|
|
->user($request->user())
|
|
|
|
->action('admin.user.delete')
|
|
|
|
->accessLevel('admin')
|
|
|
|
->save();
|
|
|
|
|
2020-02-20 05:55:10 +00:00
|
|
|
Cache::forget('profiles:private');
|
|
|
|
DeleteAccountPipeline::dispatch($user)->onQueue('high');
|
|
|
|
|
|
|
|
$msg = "Successfully deleted {$user->username}!";
|
|
|
|
$request->session()->flash('status', $msg);
|
|
|
|
return redirect('/i/admin/users/list');
|
|
|
|
}
|
|
|
|
|
2020-02-20 03:45:11 +00:00
|
|
|
public function userModerate(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'profile_id' => 'required|exists:profiles,id',
|
|
|
|
'action' => 'required|in:cw,no_autolink,unlisted'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$pid = $request->input('profile_id');
|
|
|
|
$action = $request->input('action');
|
|
|
|
$profile = Profile::findOrFail($pid);
|
|
|
|
|
2020-02-20 04:15:49 +00:00
|
|
|
if($profile->user->is_admin == true) {
|
|
|
|
$mid = $request->user()->id;
|
|
|
|
abort_if($profile->user_id < $mid, 403);
|
|
|
|
}
|
|
|
|
|
2020-02-20 03:45:11 +00:00
|
|
|
switch ($action) {
|
|
|
|
case 'cw':
|
2020-02-20 04:15:49 +00:00
|
|
|
$profile->cw = !$profile->cw;
|
|
|
|
$msg = "Success!";
|
2020-02-20 03:45:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'no_autolink':
|
2020-02-20 04:15:49 +00:00
|
|
|
$profile->no_autolink = !$profile->no_autolink;
|
|
|
|
$msg = "Success!";
|
2020-02-20 03:45:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unlisted':
|
2020-02-20 04:15:49 +00:00
|
|
|
$profile->unlisted = !$profile->unlisted;
|
|
|
|
$msg = "Success!";
|
2020-02-20 03:45:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-02-20 04:15:49 +00:00
|
|
|
|
2020-02-20 03:45:11 +00:00
|
|
|
$profile->save();
|
2020-02-20 04:15:49 +00:00
|
|
|
|
|
|
|
ModLogService::boot()
|
|
|
|
->objectUid($profile->user_id)
|
|
|
|
->objectId($profile->user_id)
|
|
|
|
->objectType('App\User::class')
|
|
|
|
->user($request->user())
|
|
|
|
->action('admin.user.moderate')
|
|
|
|
->metadata([
|
|
|
|
'action' => $action,
|
|
|
|
'message' => $msg
|
|
|
|
])
|
|
|
|
->accessLevel('admin')
|
|
|
|
->save();
|
|
|
|
|
2020-02-20 03:45:11 +00:00
|
|
|
$request->session()->flash('status', $msg);
|
2020-02-20 04:15:49 +00:00
|
|
|
return redirect('/i/admin/users/modtools/' . $profile->user_id);
|
2020-02-20 03:45:11 +00:00
|
|
|
}
|
2020-02-18 07:22:47 +00:00
|
|
|
}
|