firefly-iii/app/Http/Controllers/Auth/ConfirmationController.php
2016-04-01 16:44:46 +02:00

84 lines
2.3 KiB
PHP

<?php
declare(strict_types = 1);
/**
* ConfirmationController.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Http\Controllers\Auth;
use Auth;
use Config;
use FireflyIII\Events\ResendConfirmation;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Preferences;
use Session;
/**
* Class ConfirmationController
*
* @package FireflyIII\Http\Controllers\Auth
*/
class ConfirmationController extends Controller
{
/**
* @return mixed
*/
public function confirmationError()
{
return view('auth.confirmation.error');
}
/**
* @param string $code
*
* @return mixed
* @throws FireflyException
*/
public function doConfirmation(string $code)
{
// check user_confirmed_last_mail
$database = Preferences::get('user_confirmed_code')->data;
$time = Preferences::get('user_confirmed_last_mail', 0)->data;
$now = time();
$maxDiff = Config::get('firefly.confirmation_age');
if ($database === $code && ($now - $time <= $maxDiff)) {
Preferences::setForUser(Auth::user(), 'user_confirmed', true);
Preferences::setForUser(Auth::user(), 'user_confirmed_confirmed', time());
Session::flash('success', strval(trans('firefly.account_is_confirmed')));
return redirect(route('home'));
} else {
throw new FireflyException(trans('firefly.invalid_activation_code'));
}
}
/**
* @param Request $request
*/
public function resendConfirmation(Request $request)
{
$time = Preferences::get('user_confirmed_last_mail', 0)->data;
$now = time();
$maxDiff = Config::get('firefly.resend_confirmation');
$owner = env('SITE_OWNER', 'mail@example.com');
if ($now - $time > $maxDiff) {
event(new ResendConfirmation(Auth::user(), $request->ip()));
return view('auth.confirmation.resent', ['owner' => $owner]);
} else {
return view('auth.confirmation.no-resent', ['owner' => $owner]);
}
}
}