This commit is contained in:
James Cole 2020-10-13 06:48:11 +02:00
parent 13e15d0476
commit 4b1f4ae319
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
3 changed files with 40 additions and 23 deletions

View File

@ -60,7 +60,8 @@ class ProfileController extends Controller
{
use RequestInformation, CreateStuff;
protected bool $externalIdentity;
protected bool $internalAuth;
protected bool $internalIdentity;
/**
* ProfileController constructor.
@ -81,7 +82,8 @@ class ProfileController extends Controller
);
$loginProvider = config('firefly.login_provider');
$authGuard = config('firefly.authentication_guard');
$this->externalIdentity = 'web' !== $authGuard;
$this->internalAuth = 'web' === $authGuard;
$this->internalIdentity = 'eloquent' === $loginProvider;
Log::debug(sprintf('ProfileController::__construct(). Login provider is "%s", authentication guard is "%s"', $loginProvider, $authGuard));
$this->middleware(IsDemoUser::class)->except(['index']);
@ -92,7 +94,10 @@ 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 view('profile.logout-other-sessions');
}
@ -103,6 +108,10 @@ class ProfileController extends Controller
*/
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'),
@ -128,7 +137,7 @@ class ProfileController extends Controller
*/
public function changeEmail(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -151,7 +160,7 @@ class ProfileController extends Controller
*/
public function changePassword(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -173,7 +182,7 @@ class ProfileController extends Controller
*/
public function code(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -229,7 +238,7 @@ class ProfileController extends Controller
*/
public function confirmEmailChange(UserRepositoryInterface $repository, string $token)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
// @codeCoverageIgnoreStart
throw new FireflyException(trans('firefly.external_user_mgt_disabled'));
// @codeCoverageIgnoreEnd
@ -265,7 +274,7 @@ class ProfileController extends Controller
*/
public function deleteAccount(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -284,7 +293,7 @@ class ProfileController extends Controller
*/
public function deleteCode(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -309,7 +318,7 @@ class ProfileController extends Controller
*/
public function enable2FA(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -340,7 +349,8 @@ class ProfileController extends Controller
{
/** @var User $user */
$user = auth()->user();
$isExternalIdentity = $this->externalIdentity;
$isInternalAuth = $this->internalAuth;
$isInternalIdentity = $this->internalIdentity;
$count = DB::table('oauth_clients')->where('personal_access_client', 1)->whereNull('user_id')->count();
$subTitle = $user->email;
$userId = $user->id;
@ -360,7 +370,7 @@ class ProfileController extends Controller
$accessToken = app('preferences')->set('access_token', $token);
}
return view('profile.index', compact('subTitle', 'mfaBackupCount', 'userId', 'accessToken', 'enabled2FA', 'isExternalIdentity'));
return view('profile.index', compact('subTitle', 'mfaBackupCount', 'userId', 'accessToken', 'enabled2FA', 'isInternalAuth','isInternalIdentity'));
}
/**
@ -368,7 +378,7 @@ class ProfileController extends Controller
*/
public function newBackupCodes(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -399,7 +409,7 @@ class ProfileController extends Controller
*/
public function postChangeEmail(EmailFormRequest $request, UserRepositoryInterface $repository)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -450,7 +460,7 @@ class ProfileController extends Controller
*/
public function postChangePassword(ProfileFormRequest $request, UserRepositoryInterface $repository)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -485,7 +495,7 @@ class ProfileController extends Controller
*/
public function postCode(TokenFormRequest $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -530,7 +540,7 @@ class ProfileController extends Controller
*/
public function postDeleteAccount(UserRepositoryInterface $repository, DeleteAccountFormRequest $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -559,7 +569,7 @@ class ProfileController extends Controller
*/
public function regenerate(Request $request)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));
return redirect(route('profile.index'));
@ -587,7 +597,7 @@ class ProfileController extends Controller
*/
public function undoEmailChange(UserRepositoryInterface $repository, string $token, string $hash)
{
if ($this->externalIdentity) {
if (!$this->internalAuth || !$this->internalIdentity) {
throw new FireflyException(trans('firefly.external_user_mgt_disabled'));
}

View File

@ -754,6 +754,7 @@ return [
'login_with_old_email' => 'You can now login with your old email address again.',
'login_provider_local_only' => 'This action is not available when authenticating through ":login_provider".',
'external_user_mgt_disabled' => 'This action is not available when Firefly III isn\'t responsible for user management or authentication handling.',
'external_auth_disabled' => 'This action is not available when Firefly III isn\'t responsible for authentication handling.',
'delete_local_info_only' => "Because Firefly III isn't responsible for user management or authentication handling, this function will only delete local Firefly III information.",
'oauth' => 'OAuth',
'profile_oauth_clients' => 'OAuth Clients',

View File

@ -18,17 +18,21 @@
<li role="presentation">
<a href="#cmd" aria-controls="profile" role="tab" data-toggle="tab">{{ 'command_line_token'|_ }}</a>
</li>
{% if false == isExternalIdentity %}
{% if true == isInternalAuth %}
<li role="presentation">
<a href="#oauth" aria-controls="messages" role="tab" data-toggle="tab">{{ 'oauth'|_ }}</a>
</li>
{% endif %}
{% if true == isInternalAuth and true == isInternalIdentity %}
<li role="presentation">
<a href="#mfa" aria-controls="settings" role="tab" data-toggle="tab">{{ 'pref_two_factor_auth'|_ }}</a>
</li>
{% endif %}
{% if true == isInternalAuth and true == isInternalIdentity %}
<li role="presentation">
<a href="#delete" aria-controls="settings" role="tab" data-toggle="tab">{{ 'delete_stuff_header'|_ }}</a>
</li>
{% endif %}
</ul>
<div class="tab-content">
@ -42,7 +46,7 @@
<div class="row">
<div class="col-lg-6">
<ul>
{% if false == isExternalIdentity %}
{% if true == isInternalAuth and true == isInternalIdentity %}
<li>
<a href="{{ route('profile.change-email') }}">{{ 'change_your_email'|_ }}</a>
</li>
@ -52,7 +56,7 @@
{% endif %}
<li><a href="{{ route('logout') }}">{{ 'logout'|_ }}</a></li>
{% if false == isExternalIdentity %}
{% if true == isInternalAuth and true == isInternalIdentity %}
<li>
<a href="{{ route('profile.logout-others') }}">{{ 'logout_other_sessions'|_ }}</a>
</li>
@ -93,12 +97,14 @@
</div>
</div>
{% if false == isExternalIdentity %}
{% if true == isInternalAuth %}
<!-- OAuth -->
<div role="tabpanel" class="tab-pane" id="oauth">
<div id="passport_clients"></div>
</div>
{% endif %}
{% if true == isInternalAuth and true == isInternalIdentity %}
<!-- MFA -->
<div role="tabpanel" class="tab-pane" id="mfa">
<div class="box box-default">