firefly-iii/app/Http/Controllers/Auth/LoginController.php

117 lines
3.7 KiB
PHP
Raw Normal View History

2016-09-15 23:19:40 -05:00
<?php
2017-10-21 01:40:00 -05:00
/**
* LoginController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2017-09-14 10:40:02 -05:00
declare(strict_types=1);
/**
* LoginController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
2016-09-15 23:19:40 -05:00
namespace FireflyIII\Http\Controllers\Auth;
2017-09-14 09:13:25 -05:00
use FireflyConfig;
2016-09-15 23:19:40 -05:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
2017-09-14 09:13:25 -05:00
use FireflyIII\User;
use Illuminate\Cookie\CookieJar;
2016-09-15 23:19:40 -05:00
use Illuminate\Foundation\Auth\AuthenticatesUsers;
2017-09-14 09:13:25 -05:00
use Illuminate\Http\Request;
use Schema;
2017-09-14 09:13:25 -05:00
2016-09-15 23:19:40 -05:00
class LoginController extends Controller
{
2017-09-09 15:03:27 -05:00
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
2016-09-15 23:19:40 -05:00
use AuthenticatesUsers;
/**
2017-09-09 15:03:27 -05:00
* Where to redirect users after login.
2016-09-15 23:19:40 -05:00
*
2017-09-09 15:03:27 -05:00
* @var string
2016-09-15 23:19:40 -05:00
*/
2017-09-09 15:03:27 -05:00
protected $redirectTo = '/home';
2016-09-16 00:22:57 -05:00
/**
2017-09-09 15:03:27 -05:00
* Create a new controller instance.
2016-12-28 11:49:30 -06:00
*
*/
2017-09-09 15:03:27 -05:00
public function __construct()
2016-12-28 11:49:30 -06:00
{
2017-09-12 11:24:42 -05:00
parent::__construct();
2017-09-09 15:03:27 -05:00
$this->middleware('guest')->except('logout');
2016-12-28 11:49:30 -06:00
}
2017-09-14 09:13:25 -05:00
/**
* Show the application's login form.
*
* @return \Illuminate\Http\Response
*/
public function showLoginForm(Request $request, CookieJar $cookieJar)
{
// check for presence of tables:
$hasTable = Schema::hasTable('users');
if(!$hasTable) {
$message = 'Firefly III could not find the "users" table. This is a strong indication your database credentials are wrong or the database has not been initialized. Did you follow the installation instructions correctly?';
return view('error',compact('message'));
}
// check for presence of currency:
$currency = TransactionCurrency::where('code','EUR')->first();
2017-11-06 13:17:54 -06:00
if(is_null($currency)) {
$message = 'Firefly III could not find the EURO currency. This is a strong indication the database has not been initialized correctly. Did you follow the installation instructions?';
return view('error',compact('message'));
}
2017-09-14 09:13:25 -05:00
// forget 2fa cookie:
$cookie = $cookieJar->forever('twoFactorAuthenticated', 'false');
// is allowed to?
$singleUserMode = FireflyConfig::get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
$userCount = User::count();
$allowRegistration = true;
if ($singleUserMode === true && $userCount > 0) {
$allowRegistration = false;
}
$email = $request->old('email');
$remember = $request->old('remember');
return view('auth.login', compact('allowRegistration', 'email', 'remember'))->withCookie($cookie);
}
2016-09-15 23:19:40 -05:00
}