mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
Code reordering and reformatting. I should really start employing style CI.
This commit is contained in:
@@ -93,49 +93,6 @@ class ProfileController extends Controller
|
||||
$this->middleware(IsDemoUser::class)->except(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function logoutOtherSessions()
|
||||
{
|
||||
if (!$this->internalAuth) {
|
||||
session()->flash('info', (string)trans('firefly.external_auth_disabled'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
return prefixView('profile.logout-other-sessions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Application|RedirectResponse|Redirector
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function postLogoutOtherSessions(Request $request)
|
||||
{
|
||||
if (!$this->internalAuth) {
|
||||
session()->flash('info', (string)trans('firefly.external_auth_disabled'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
$creds = [
|
||||
'email' => auth()->user()->email,
|
||||
'password' => $request->get('password'),
|
||||
];
|
||||
if (Auth::once($creds)) {
|
||||
Auth::logoutOtherDevices($request->get('password'));
|
||||
session()->flash('info', (string)trans('firefly.other_sessions_logged_out'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
session()->flash('error', (string)trans('auth.failed'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change your email address.
|
||||
*
|
||||
@@ -388,6 +345,20 @@ class ProfileController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function logoutOtherSessions()
|
||||
{
|
||||
if (!$this->internalAuth) {
|
||||
session()->flash('info', (string)trans('firefly.external_auth_disabled'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
return prefixView('profile.logout-other-sessions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
@@ -548,6 +519,49 @@ class ProfileController extends Controller
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* See reference nr. 64
|
||||
*
|
||||
* @param string $mfaCode
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function addToMFAHistory(string $mfaCode): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$entry = [
|
||||
'time' => time(),
|
||||
'code' => $mfaCode,
|
||||
];
|
||||
$mfaHistory[] = $entry;
|
||||
|
||||
app('preferences')->set('mfa_history', $mfaHistory);
|
||||
$this->filterMFAHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old entries from the preferences array.
|
||||
*/
|
||||
private function filterMFAHistory(): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$newHistory = [];
|
||||
$now = time();
|
||||
foreach ($mfaHistory as $entry) {
|
||||
$time = $entry['time'];
|
||||
$code = $entry['code'];
|
||||
if ($now - $time <= 300) {
|
||||
$newHistory[] = [
|
||||
'time' => $time,
|
||||
'code' => $code,
|
||||
];
|
||||
}
|
||||
}
|
||||
app('preferences')->set('mfa_history', $newHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit delete account.
|
||||
*
|
||||
@@ -580,6 +594,35 @@ class ProfileController extends Controller
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Application|RedirectResponse|Redirector
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function postLogoutOtherSessions(Request $request)
|
||||
{
|
||||
if (!$this->internalAuth) {
|
||||
session()->flash('info', (string)trans('firefly.external_auth_disabled'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
$creds = [
|
||||
'email' => auth()->user()->email,
|
||||
'password' => $request->get('password'),
|
||||
];
|
||||
if (Auth::once($creds)) {
|
||||
Auth::logoutOtherDevices($request->get('password'));
|
||||
session()->flash('info', (string)trans('firefly.other_sessions_logged_out'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
}
|
||||
session()->flash('error', (string)trans('auth.failed'));
|
||||
|
||||
return redirect(route('profile.index'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate access token.
|
||||
*
|
||||
@@ -659,46 +702,4 @@ class ProfileController extends Controller
|
||||
|
||||
return redirect(route('login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* See reference nr. 64
|
||||
*
|
||||
* @param string $mfaCode
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function addToMFAHistory(string $mfaCode): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$entry = [
|
||||
'time' => time(),
|
||||
'code' => $mfaCode,
|
||||
];
|
||||
$mfaHistory[] = $entry;
|
||||
|
||||
app('preferences')->set('mfa_history', $mfaHistory);
|
||||
$this->filterMFAHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old entries from the preferences array.
|
||||
*/
|
||||
private function filterMFAHistory(): void
|
||||
{
|
||||
/** @var array $mfaHistory */
|
||||
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
|
||||
$newHistory = [];
|
||||
$now = time();
|
||||
foreach ($mfaHistory as $entry) {
|
||||
$time = $entry['time'];
|
||||
$code = $entry['code'];
|
||||
if ($now - $time <= 300) {
|
||||
$newHistory[] = [
|
||||
'time' => $time,
|
||||
'code' => $code,
|
||||
];
|
||||
}
|
||||
}
|
||||
app('preferences')->set('mfa_history', $newHistory);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user