2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
2015-03-12 01:44:39 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Libraries\Utils;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Ninja\Mailers\Mailer;
|
2015-03-26 15:35:57 +01:00
|
|
|
use Auth;
|
2015-03-30 21:45:10 +02:00
|
|
|
use Input;
|
2016-12-25 18:43:42 +01:00
|
|
|
use Mail;
|
2017-01-30 20:40:43 +01:00
|
|
|
use Redirect;
|
|
|
|
use Request;
|
|
|
|
use Response;
|
2015-04-13 09:54:51 +02:00
|
|
|
use Session;
|
2017-01-30 20:40:43 +01:00
|
|
|
use View;
|
2015-03-12 04:39:52 +01:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class HomeController.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
class HomeController extends BaseController
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var Mailer
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
protected $mailer;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* HomeController constructor.
|
|
|
|
*
|
|
|
|
* @param Mailer $mailer
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
public function __construct(Mailer $mailer)
|
|
|
|
{
|
2016-03-02 14:36:42 +01:00
|
|
|
//parent::__construct();
|
2015-03-12 04:39:52 +01:00
|
|
|
|
|
|
|
$this->mailer = $mailer;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
public function showIndex()
|
|
|
|
{
|
2015-04-27 14:28:40 +02:00
|
|
|
Session::reflash();
|
2016-11-06 13:16:18 +01:00
|
|
|
|
2017-01-30 20:40:43 +01: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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2015-09-10 19:50:09 +02:00
|
|
|
public function viewLogo()
|
|
|
|
{
|
|
|
|
return View::make('public.logo');
|
|
|
|
}
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
public function invoiceNow()
|
|
|
|
{
|
2015-09-20 23:05:02 +02:00
|
|
|
// Track the referral/campaign code
|
2016-11-06 13:16:18 +01:00
|
|
|
if (Input::has('rc')) {
|
|
|
|
Session::set(SESSION_REFERRAL_CODE, Input::get('rc'));
|
2015-09-20 23:05:02 +02:00
|
|
|
}
|
|
|
|
|
2015-03-12 04:39:52 +01:00
|
|
|
if (Auth::check()) {
|
2017-06-01 20:05:01 +02:00
|
|
|
$redirectTo = Input::get('redirect_to') ? SITE_URL . '/' . ltrim(Input::get('redirect_to'), '/') : 'invoices/create';
|
2015-08-12 21:16:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $userType
|
|
|
|
* @param $version
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
public function newsFeed($userType, $version)
|
|
|
|
{
|
|
|
|
$response = Utils::getNewsFeedResponse($userType);
|
|
|
|
|
|
|
|
return Response::json($response);
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2016-11-06 13:16:18 +01:00
|
|
|
|
2015-08-04 16:33:30 +02:00
|
|
|
Session::forget('news_feed_message');
|
2015-03-12 04:39:52 +01:00
|
|
|
|
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-03-12 04:39:52 +01:00
|
|
|
public function logError()
|
|
|
|
{
|
|
|
|
return Utils::logError(Input::get('error'), 'JavaScript');
|
|
|
|
}
|
2015-05-19 21:14:00 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-05-19 21:14:00 +02:00
|
|
|
public function keepAlive()
|
|
|
|
{
|
2015-09-28 22:37:32 +02:00
|
|
|
return RESULT_SUCCESS;
|
2015-05-19 21:14:00 +02:00
|
|
|
}
|
2016-12-25 18:43:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function contactUs()
|
|
|
|
{
|
2017-08-29 11:43:57 +02:00
|
|
|
$message = request()->contact_us_message;
|
|
|
|
|
|
|
|
if (request()->include_errors) {
|
|
|
|
$message .= "\n\n" . join("\n", Utils::getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
Mail::raw($message, function ($message) {
|
2017-07-31 21:42:01 +02:00
|
|
|
$subject = 'Customer Message: ';
|
2017-08-29 11:43:57 +02:00
|
|
|
if (Utils::isNinjaProd()) {
|
2017-07-31 21:42:01 +02:00
|
|
|
$subject .= config('database.default');
|
|
|
|
} else {
|
2017-08-29 11:43:57 +02:00
|
|
|
$subject .= 'Self-Host';
|
2016-12-25 18:43:42 +01:00
|
|
|
}
|
2017-02-09 20:13:12 +01:00
|
|
|
$message->to(env('CONTACT_EMAIL', 'contact@invoiceninja.com'))
|
2016-12-25 18:43:42 +01:00
|
|
|
->from(CONTACT_EMAIL, Auth::user()->present()->fullName)
|
|
|
|
->replyTo(Auth::user()->email, Auth::user()->present()->fullName)
|
|
|
|
->subject($subject);
|
|
|
|
});
|
|
|
|
|
2017-02-09 20:11:23 +01:00
|
|
|
return RESULT_SUCCESS;
|
2016-12-25 18:43:42 +01:00
|
|
|
}
|
2015-03-12 01:44:39 +01:00
|
|
|
}
|