2015-03-16 22:45:25 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
2015-03-12 01:44:39 +01:00
|
|
|
|
2015-06-10 10:34:20 +02:00
|
|
|
use Response;
|
2015-05-19 21:14:00 +02:00
|
|
|
use Request;
|
2015-03-17 02:30:56 +01:00
|
|
|
use Redirect;
|
2015-03-26 15:35:57 +01:00
|
|
|
use Auth;
|
|
|
|
use View;
|
2015-03-30 21:45:10 +02:00
|
|
|
use Input;
|
2015-04-13 09:54:51 +02:00
|
|
|
use Session;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Libraries\Utils;
|
|
|
|
use App\Ninja\Mailers\Mailer;
|
2015-05-19 21:14:00 +02:00
|
|
|
use Symfony\Component\Security\Core\Util\StringUtils;
|
2015-03-12 04:39:52 +01:00
|
|
|
|
|
|
|
class HomeController extends BaseController
|
|
|
|
{
|
|
|
|
protected $mailer;
|
|
|
|
|
|
|
|
public function __construct(Mailer $mailer)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->mailer = $mailer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showIndex()
|
|
|
|
{
|
2015-04-27 14:28:40 +02:00
|
|
|
Session::reflash();
|
2015-05-08 10:21:29 +02:00
|
|
|
|
2015-06-20 19:40:50 +02:00
|
|
|
if (!Utils::isNinja() && (!Utils::isDatabaseSetup() || Account::count() == 0)) {
|
2015-03-12 04:39:52 +01:00
|
|
|
return Redirect::to('/setup');
|
2015-04-28 22:13:52 +02:00
|
|
|
} elseif (Auth::check()) {
|
|
|
|
return Redirect::to('/dashboard');
|
2015-03-12 04:39:52 +01:00
|
|
|
} else {
|
|
|
|
return Redirect::to('/login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showTerms()
|
|
|
|
{
|
|
|
|
return View::make('public.terms', ['hideHeader' => true]);
|
|
|
|
}
|
2015-09-10 19:50:09 +02:00
|
|
|
|
|
|
|
public function viewLogo()
|
|
|
|
{
|
|
|
|
return View::make('public.logo');
|
|
|
|
}
|
2015-03-12 04:39:52 +01:00
|
|
|
|
|
|
|
public function invoiceNow()
|
|
|
|
{
|
2015-07-30 16:44:47 +02:00
|
|
|
if (Auth::check() && Input::get('new_company')) {
|
2015-07-07 22:08:16 +02:00
|
|
|
Session::put(PREV_USER_ID, Auth::user()->id);
|
2015-06-16 21:35:35 +02:00
|
|
|
Auth::user()->clearSession();
|
|
|
|
Auth::logout();
|
|
|
|
}
|
|
|
|
|
2015-03-12 04:39:52 +01:00
|
|
|
if (Auth::check()) {
|
2015-08-12 21:16:02 +02:00
|
|
|
$redirectTo = Input::get('redirect_to', 'invoices/create');
|
|
|
|
return Redirect::to($redirectTo)->with('sign_up', Input::get('sign_up'));
|
2015-03-12 04:39:52 +01:00
|
|
|
} else {
|
2015-09-07 11:07:55 +02:00
|
|
|
return View::make('public.invoice_now');
|
2015-03-12 04:39:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newsFeed($userType, $version)
|
|
|
|
{
|
|
|
|
$response = Utils::getNewsFeedResponse($userType);
|
|
|
|
|
|
|
|
return Response::json($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hideMessage()
|
|
|
|
{
|
|
|
|
if (Auth::check() && Session::has('news_feed_id')) {
|
|
|
|
$newsFeedId = Session::get('news_feed_id');
|
|
|
|
if ($newsFeedId != NEW_VERSION_AVAILABLE && $newsFeedId > Auth::user()->news_feed_id) {
|
|
|
|
$user = Auth::user();
|
|
|
|
$user->news_feed_id = $newsFeedId;
|
|
|
|
$user->save();
|
|
|
|
}
|
|
|
|
}
|
2015-08-04 16:33:30 +02:00
|
|
|
|
|
|
|
Session::forget('news_feed_message');
|
2015-03-12 04:39:52 +01:00
|
|
|
|
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logError()
|
|
|
|
{
|
|
|
|
return Utils::logError(Input::get('error'), 'JavaScript');
|
|
|
|
}
|
2015-05-19 21:14:00 +02:00
|
|
|
|
|
|
|
public function keepAlive()
|
|
|
|
{
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2015-03-12 01:44:39 +01:00
|
|
|
}
|