update: user privacy settings

This commit is contained in:
Roardom
2022-12-31 03:02:42 -06:00
parent aaf9c1e4f4
commit 35c69b8f2f
11 changed files with 756 additions and 1312 deletions
@@ -341,38 +341,6 @@ class UserController extends Controller
->withSuccess('Your Email Was Updated Successfully!');
}
/**
* Change User Privacy Level.
*/
public function makePrivate(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$user->private_profile = 1;
$user->save();
return \to_route('users.show', ['username' => $user->username])
->withSuccess('You Have Gone Private!');
}
/**
* Change User Privacy Level.
*/
public function makePublic(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$user->private_profile = 0;
$user->save();
return \to_route('users.show', ['username' => $user->username])
->withSuccess('You Have Gone Public!');
}
/**
* Change User Notification Setting.
*/
@@ -405,38 +373,6 @@ class UserController extends Controller
->withSuccess('You Have Enabled Notifications!');
}
/**
* Change User Hidden Value.
*/
public function makeHidden(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$user->hidden = 1;
$user->save();
return \to_route('users.show', ['username' => $user->username])
->withSuccess('You Have Disappeared Like A Ninja!');
}
/**
* Change User Hidden Value.
*/
public function makeVisible(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$user->hidden = 0;
$user->save();
return \to_route('users.show', ['username' => $user->username])
->withSuccess('You Have Given Up Your Ninja Ways And Become Visible!');
}
/**
* Change User PID.
*
@@ -457,198 +393,6 @@ class UserController extends Controller
->withSuccess('Your PID Was Changed Successfully!');
}
/**
* User Other Privacy Change.
*/
protected function changeOther(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_other_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_online = ($request->input('show_online') && $request->input('show_online') == 1 ? 1 : 0);
$privacy->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#other'])
->withSuccess('Your Other Privacy Settings Have Been Saved!');
}
/**
* User Request Privacy Change.
*/
protected function changeRequest(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_request_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_requested = ($request->input('show_requested') && $request->input('show_requested') == 1 ? 1 : 0);
$privacy->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#request'])
->withSuccess('Your Request Privacy Settings Have Been Saved!');
}
/**
* User Achievement Privacy Change.
*/
protected function changeAchievement(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_achievement_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_achievement = ($request->input('show_achievement') && $request->input('show_achievement') == 1 ? 1 : 0);
$privacy->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#achievement'])
->withSuccess('Your Achievement Privacy Settings Have Been Saved!');
}
/**
* User Forum Privacy Change.
*/
protected function changeForum(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_forum_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_topic = ($request->input('show_topic') && $request->input('show_topic') == 1 ? 1 : 0);
$privacy->show_post = ($request->input('show_post') && $request->input('show_post') == 1 ? 1 : 0);
$privacy->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#forum'])
->withSuccess('Your Forum History Privacy Settings Have Been Saved!');
}
/**
* User Follower Privacy Change.
*/
protected function changeFollower(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_follower_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_follower = ($request->input('show_follower') && $request->input('show_follower') == 1 ? 1 : 0);
$privacy->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#follower'])
->withSuccess('Your Follower Privacy Settings Have Been Saved!');
}
/**
* User Torrent Privacy Change.
*/
protected function changeTorrent(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_torrent_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_upload = ($request->input('show_upload') && $request->input('show_upload') == 1 ? 1 : 0);
$privacy->show_download = ($request->input('show_download') && $request->input('show_download') == 1 ? 1 : 0);
$privacy->show_peer = ($request->input('show_peer') && $request->input('show_peer') == 1 ? 1 : 0);
$privacy->save();
$user->peer_hidden = 0;
$user->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#torrent'])
->withSuccess('Your Torrent History Privacy Settings Have Been Saved!');
}
/**
* User Account Notification Change.
*/
@@ -911,50 +655,6 @@ class UserController extends Controller
->withSuccess('Your Forum Notification Settings Have Been Saved!');
}
/**
* User Profile Privacy Change.
*/
protected function changeProfile(Request $request, string $username): \Illuminate\Http\RedirectResponse
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$privacy = $user->privacy;
if (! $privacy) {
$privacy = new UserPrivacy();
$privacy->setDefaultValues();
$privacy->user_id = $user->id;
}
$approved = $request->input('approved');
$groups = Group::all();
$tomerge = [];
foreach ($groups as $group) {
$tomerge[$group->id] = \is_array($approved) && \in_array($group->id, $approved) ? 1 : 0;
}
$privacy->json_profile_groups = \array_merge($privacy->expected_groups, ['default_groups' => $tomerge]);
$privacy->show_profile_torrent_count = ($request->input('show_profile_torrent_count') && $request->input('show_profile_torrent_count') == 1 ? 1 : 0);
$privacy->show_profile_torrent_ratio = ($request->input('show_profile_torrent_ratio') && $request->input('show_profile_torrent_ratio') == 1 ? 1 : 0);
$privacy->show_profile_torrent_seed = ($request->input('show_profile_torrent_seed') && $request->input('show_profile_torrent_seed') == 1 ? 1 : 0);
$privacy->show_profile_torrent_extra = ($request->input('show_profile_torrent_extra') && $request->input('show_profile_torrent_extra') == 1 ? 1 : 0);
$privacy->show_profile_about = ($request->input('show_profile_about') && $request->input('show_profile_about') == 1 ? 1 : 0);
$privacy->show_profile_achievement = ($request->input('show_profile_achievement') && $request->input('show_profile_achievement') == 1 ? 1 : 0);
$privacy->show_profile_badge = ($request->input('show_profile_badge') && $request->input('show_profile_badge') == 1 ? 1 : 0);
$privacy->show_profile_follower = ($request->input('show_profile_follower') && $request->input('show_profile_follower') == 1 ? 1 : 0);
$privacy->show_profile_title = ($request->input('show_profile_title') && $request->input('show_profile_title') == 1 ? 1 : 0);
$privacy->show_profile_bon_extra = ($request->input('show_profile_bon_extra') && $request->input('show_profile_bon_extra') == 1 ? 1 : 0);
$privacy->show_profile_comment_extra = ($request->input('show_profile_comment_extra') && $request->input('show_profile_comment_extra') == 1 ? 1 : 0);
$privacy->show_profile_forum_extra = ($request->input('show_profile_forum_extra') && $request->input('show_profile_forum_extra') == 1 ? 1 : 0);
$privacy->show_profile_request_extra = ($request->input('show_profile_request_extra') && $request->input('show_profile_request_extra') == 1 ? 1 : 0);
$privacy->show_profile_warning = ($request->input('show_profile_warning') && $request->input('show_profile_warning') == 1 ? 1 : 0);
$privacy->save();
return \to_route('user_privacy', ['username' => $user->username, 'hash' => '#profile'])
->withSuccess('Your Profile Privacy Settings Have Been Saved!');
}
/**
* Change User RID.
*/
@@ -987,34 +687,6 @@ class UserController extends Controller
->withSuccess('Your API Token Was Changed Successfully!');
}
/**
* User Privacy Settings.
*/
public function privacy(Request $request, string $username): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$groups = Group::where('level', '>', 0)->latest('level')->get();
return \view('user.settings.privacy.index', ['user' => $user, 'groups'=> $groups]);
}
/**
* User Notification Settings.
*/
public function notification(Request $request, string $username): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = User::where('username', '=', $username)->firstOrFail();
\abort_unless($request->user()->id == $user->id, 403);
$groups = Group::where('level', '>', 0)->latest('level')->get();
return \view('user.settings.notification.index', ['user' => $user, 'groups'=> $groups]);
}
/**
* Accept Site Rules.
*/