This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/Controllers/Settings/AdvancedController.php

114 lines
3.4 KiB
PHP
Raw Normal View History

<?php
/**
* Holds the advanced section controller.
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
2016-04-01 21:44:31 +00:00
use Sakura\ActiveUser;
use Sakura\DB;
2016-04-03 21:29:46 +00:00
use Sakura\Perms\Site;
2016-04-01 21:44:31 +00:00
/**
* Advanced settings.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class AdvancedController extends Controller
{
2016-08-05 02:35:37 +00:00
/**
* Renders the session management page.
* @return string
*/
public function sessions()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!ActiveUser::$user->permission(Site::MANAGE_SESSIONS)) {
$message = "You aren't allowed to manage sessions.";
2016-08-02 20:35:12 +00:00
$redirect = route('settings.index');
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
$id = $_POST['id'] ?? null;
$all = isset($_POST['all']);
2016-08-02 20:35:12 +00:00
if (session_check() && ($id || $all)) {
$redirect = route('settings.advanced.sessions');
2016-04-03 21:29:46 +00:00
// End all sessions
if ($all) {
DB::table('sessions')
->where('user_id', ActiveUser::$user->id)
->delete();
$message = "Deleted all active session associated with your account!";
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
// Create the session statement
$session = DB::table('sessions')
->where('user_id', ActiveUser::$user->id)
->where('session_id', $id);
// Check if the session exists
if (!$session->count()) {
$message = "This session doesn't exist!";
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
// Delete it
$session->delete();
$message = "Deleted the session!";
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
2016-04-01 21:44:31 +00:00
$sessions = DB::table('sessions')
->where('user_id', ActiveUser::$user->id)
->get();
2016-04-25 02:01:14 +00:00
$active = ActiveUser::$session->sessionId;
2016-04-01 21:44:31 +00:00
2016-08-02 20:35:12 +00:00
return view('settings/advanced/sessions', compact('sessions', 'active'));
}
2016-08-05 02:35:37 +00:00
/**
* Renders the deactivation page.
* @return string
*/
public function deactivate()
{
2016-04-03 21:29:46 +00:00
// Check permission
if (!ActiveUser::$user->permission(Site::DEACTIVATE_ACCOUNT)) {
$message = "You aren't allowed to deactivate your account.";
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
$password = $_POST['password'] ?? null;
2016-08-02 20:35:12 +00:00
if (session_check() && $password) {
$redirect = route('settings.advanced.deactivate');
2016-04-03 21:29:46 +00:00
// Check password
2016-08-01 21:09:27 +00:00
if (!ActiveUser::$user->verifyPassword($password)) {
2016-04-03 21:29:46 +00:00
$message = "Your password was invalid!";
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
// Deactivate account
ActiveUser::$user->removeRanks(array_keys(ActiveUser::$user->ranks));
ActiveUser::$user->addRanks([1]);
ActiveUser::$user->setMainRank(1);
// Destroy all active sessions
ActiveUser::$session->destroyAll();
2016-08-02 20:35:12 +00:00
$redirect = route('main.index');
2016-04-03 21:29:46 +00:00
$message = "Farewell!";
2016-08-02 20:35:12 +00:00
return view('global/information', compact('message', 'redirect'));
2016-04-03 21:29:46 +00:00
}
2016-08-02 20:35:12 +00:00
return view('settings/advanced/deactivate');
}
}