From 76e9f107e74ed4a915ec9549009ff8c58ad165ce Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 19 Oct 2014 23:03:57 +0300 Subject: [PATCH] Added support for a demo account --- app/controllers/AccountController.php | 16 ++++++++++++++++ app/controllers/InvoiceController.php | 2 +- app/libraries/utils.php | 12 +++++++++++- app/models/User.php | 5 +++++ app/ninja/repositories/InvoiceRepository.php | 2 +- app/routes.php | 2 ++ app/views/master.blade.php | 2 +- app/views/public/faq.blade.php | 9 +++++++++ 8 files changed, 46 insertions(+), 4 deletions(-) diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 4535567eb9f5..b0ffefda5461 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -64,6 +64,22 @@ class AccountController extends \BaseController { return Redirect::to('/'); } */ + + public function demo() + { + $demoAccountId = Utils::getDemoAccountId(); + + if (!$demoAccountId) { + return Redirect::to('/'); + } + + $account = Account::find($demoAccountId); + $user = $account->users()->first(); + + Auth::login($user, true); + + return Redirect::to('invoices/create'); + } public function getStarted() { diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 585a774f6e2f..197db91f41cd 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -357,7 +357,7 @@ class InvoiceController extends \BaseController { } else if ($action == 'email') { - if (Auth::user()->confirmed) + if (Auth::user()->confirmed && !Auth::user()->isDemo()) { $message = trans("texts.emailed_{$entityType}"); $this->mailer->sendInvoice($invoice); diff --git a/app/libraries/utils.php b/app/libraries/utils.php index 493a9168b7f1..ee9318c4d7b1 100755 --- a/app/libraries/utils.php +++ b/app/libraries/utils.php @@ -31,7 +31,7 @@ class Utils { return isset($_ENV['NINJA_DEV']) && $_ENV['NINJA_DEV']; } - + public static function isPro() { return Auth::check() && Auth::user()->isPro(); @@ -46,6 +46,16 @@ class Utils } } + public static function getDemoAccountId() + { + return isset($_ENV[DEMO_ACCOUNT_ID]) ? $_ENV[DEMO_ACCOUNT_ID] : false; + } + + public static function isDemo() + { + return Auth::check() && Auth::user()->isDemo(); + } + public static function getNewsFeedResponse($userType = false) { if (!$userType) { diff --git a/app/models/User.php b/app/models/User.php index 130fc139c05c..60e7500c9dcd 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -80,6 +80,11 @@ class User extends ConfideUser implements UserInterface, RemindableInterface return $this->account->isPro(); } + public function isDemo() + { + return $this->account->id == Utils::getDemoAccountId(); + } + public function getDisplayName() { if ($this->getFullName()) diff --git a/app/ninja/repositories/InvoiceRepository.php b/app/ninja/repositories/InvoiceRepository.php index 47bd82257944..808d7757aecb 100755 --- a/app/ninja/repositories/InvoiceRepository.php +++ b/app/ninja/repositories/InvoiceRepository.php @@ -207,7 +207,7 @@ class InvoiceRepository $invoice->client_id = $data['client_id']; $invoice->discount = Utils::parseFloat($data['discount']); $invoice->invoice_number = trim($data['invoice_number']); - $invoice->is_recurring = $data['is_recurring'] ? true : false; + $invoice->is_recurring = $data['is_recurring'] && !Utils::isDemo() ? true : false; $invoice->invoice_date = Utils::toSqlDate($data['invoice_date']); if ($invoice->is_recurring) diff --git a/app/routes.php b/app/routes.php index 10babb252cdf..f41f95a68728 100755 --- a/app/routes.php +++ b/app/routes.php @@ -67,6 +67,7 @@ Route::get('logout', 'UserController@logout'); if (Utils::isNinja()) { Route::get('/news_feed/{user_type}/{version}/', 'HomeController@newsFeed'); + Route::get('/demo', 'AccountController@demo'); } Route::group(array('before' => 'auth'), function() @@ -239,6 +240,7 @@ define('EVENT_CREATE_QUOTE', 3); define('EVENT_CREATE_PAYMENT', 4); define('REQUESTED_PRO_PLAN', 'REQUESTED_PRO_PLAN'); +define('DEMO_ACCOUNT_ID', 'DEMO_ACCOUNT_ID'); define('NINJA_ACCOUNT_KEY', 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx79h'); define('NINJA_GATEWAY_ID', GATEWAY_AUTHORIZE_NET); define('NINJA_GATEWAY_CONFIG', '{"apiLoginId":"626vWcD5","transactionKey":"4bn26TgL9r4Br4qJ","testMode":"","developerMode":""}'); diff --git a/app/views/master.blade.php b/app/views/master.blade.php index feb91b4e6377..b3a1c0673b05 100755 --- a/app/views/master.blade.php +++ b/app/views/master.blade.php @@ -1,7 +1,7 @@ - Invoice Ninja | {{ isset($title) ? $title : ' Free Open-Source Online Invoicing' }} + Invoice Ninja | {{ isset($title) ? $title : ' Free Open-Source Online Invoice Software' }} diff --git a/app/views/public/faq.blade.php b/app/views/public/faq.blade.php index 912449426bc3..e075ea1786ff 100644 --- a/app/views/public/faq.blade.php +++ b/app/views/public/faq.blade.php @@ -162,6 +162,15 @@

+ @if (Utils::getDemoAccountId()) +
+ Can I see what the application looks like with sample data? +
+

Sure, click here to try out our demo account. +

+
+
+ @endif
I hear that there's a version of Invoice Ninja that I can install myself on my own servers? Where can I learn more about this?