1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 01:41:34 +02:00
invoiceninja/app/Http/Controllers/Auth/AuthController.php

95 lines
2.6 KiB
PHP
Raw Normal View History

2015-03-23 05:20:33 +01:00
<?php namespace App\Http\Controllers\Auth;
2015-03-16 22:45:25 +01:00
2015-03-31 19:42:37 +02:00
use Auth;
use Event;
2015-04-28 22:13:52 +02:00
use Utils;
2015-06-16 21:35:35 +02:00
use Session;
2015-03-31 19:42:37 +02:00
use Illuminate\Http\Request;
2015-04-28 22:13:52 +02:00
use App\Models\User;
2015-03-31 19:42:37 +02:00
use App\Events\UserLoggedIn;
2015-03-23 05:20:33 +01:00
use App\Http\Controllers\Controller;
2015-06-16 21:35:35 +02:00
use App\Ninja\Repositories\AccountRepository;
2015-03-16 22:45:25 +01:00
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller {
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers;
2015-03-29 14:37:42 +02:00
protected $loginPath = '/login';
protected $redirectTo = '/dashboard';
2015-06-16 21:35:35 +02:00
protected $accountRepo;
2015-03-29 14:37:42 +02:00
2015-03-16 22:45:25 +01:00
/**
* Create a new authentication controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
* @param \Illuminate\Contracts\Auth\Registrar $registrar
* @return void
*/
2015-06-16 21:35:35 +02:00
public function __construct(Guard $auth, Registrar $registrar, AccountRepository $repo)
2015-03-16 22:45:25 +01:00
{
$this->auth = $auth;
$this->registrar = $registrar;
2015-06-16 21:35:35 +02:00
$this->accountRepo = $repo;
2015-03-16 22:45:25 +01:00
2015-06-16 21:35:35 +02:00
//$this->middleware('guest', ['except' => 'getLogout']);
2015-03-16 22:45:25 +01:00
}
2015-04-28 22:13:52 +02:00
public function getLoginWrapper()
{
if (!Utils::isNinja() && !User::count()) {
return redirect()->to('invoice_now');
}
return self::getLogin();
}
2015-03-31 19:42:37 +02:00
public function postLoginWrapper(Request $request)
{
2015-06-16 21:35:35 +02:00
$userId = Auth::check() ? Auth::user()->id : null;
2015-03-31 19:42:37 +02:00
$response = self::postLogin($request);
if (Auth::check()) {
Event::fire(new UserLoggedIn());
2015-06-16 21:35:35 +02:00
if (Utils::isPro()) {
$users = false;
// we're linking a new account
if ($userId && Auth::user()->id != $userId) {
$users = $this->accountRepo->associateAccounts($userId, Auth::user()->id);
Session::flash('message', trans('texts.associated_accounts'));
// check if other accounts are linked
} else {
$users = $this->accountRepo->loadAccounts(Auth::user()->id);
}
Session::put(SESSION_USER_ACCOUNTS, $users);
}
2015-03-31 19:42:37 +02:00
}
return $response;
}
2015-06-16 21:35:35 +02:00
public function getLogoutWrapper()
{
$response = self::getLogout();
Session::flush();
return $response;
}
2015-03-16 22:45:25 +01:00
}