Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
feat: add demo mode to instance (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored May 25, 2021
1 parent cfe2cc0 commit 70b6fa2
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ APP_KEY=
APP_DEBUG=true
APP_URL=https://officelife.test

# Demo mode
DEMO_MODE=false

# Enable or disable signups on the instance
ENABLE_SIGNUPS=true

# Database to store information
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
Expand All @@ -29,7 +35,7 @@ QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

# Redis, if you need it
# Redis, if you need it for the queues
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function showLoginForm(): \Inertia\Response
{
return Inertia::render('Auth/Login', [
'registerUrl' => route('signup'),
'enableSignup' => config('officelife.enable_signups'),
]);
}

Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function index()
return redirect('/home');
}

if (! config('officelife.enable_signups')) {
return redirect()->route('login');
}

return Inertia::render('Auth/Register', [
'signInUrl' => route('login'),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Inertia\Response;
use Illuminate\Http\Request;
use App\Helpers\InstanceHelper;
use Illuminate\Http\JsonResponse;
use App\Helpers\NotificationHelper;
use App\Http\Controllers\Controller;
use App\Services\Company\Adminland\Company\DestroyCompany;
Expand All @@ -30,10 +29,14 @@ public function index(): Response
*
* @param Request $request
* @param int $companyId
* @return JsonResponse
* @return mixed
*/
public function destroy(Request $request, int $companyId): JsonResponse
public function destroy(Request $request, int $companyId)
{
if (config('officelife.demo_mode')) {
return redirect()->route('home');
}

$loggedEmployee = InstanceHelper::getLoggedEmployee();
$loggedCompany = InstanceHelper::getLoggedCompany();

Expand Down
12 changes: 10 additions & 2 deletions app/Http/Controllers/Company/Adminland/AdminEmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ public function create(): Response
*
* @param Request $request
* @param int $companyId
* @return JsonResponse
* @return mixed
*/
public function store(Request $request, int $companyId): JsonResponse
public function store(Request $request, int $companyId): mixed
{
if (config('officelife.demo_mode')) {
return redirect()->route('home');
}

$loggedEmployee = InstanceHelper::getLoggedEmployee();
$loggedCompany = InstanceHelper::getLoggedCompany();

Expand Down Expand Up @@ -306,6 +310,10 @@ public function unlockAccount(Request $request, int $companyId, int $employeeId)
*/
public function delete(Request $request, int $companyId, int $employeeId)
{
if (config('officelife.demo_mode')) {
return redirect()->route('home');
}

$loggedCompany = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function share(Request $request)
],
] : null,
],
'demo_mode' => fn () => config('officelife.demo_mode'),
'help_links' => fn () => config('officelife.help_links'),
'flash' => [
'message' => fn () => $request->session()->get('message'),
Expand Down
23 changes: 23 additions & 0 deletions config/officelife.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@
*/
'name' => 'OfficeLife',

/*
|--------------------------------------------------------------------------
| Demo mode
|--------------------------------------------------------------------------
|
| The demo mode puts OfficeLife in a mode that is used to showcase what's
| OfficeLife can do to people who don't know what it can do.
| This mode is used on demo.officelife.io.
|
*/
'demo_mode' => env('DEMO_MODE', false),

/*
|--------------------------------------------------------------------------
| Enable signups
|--------------------------------------------------------------------------
|
| This setup enables new users to signup to this instance. If set to false,
| new users won't be able to signup.
|
*/
'enable_signups' => env('ENABLE_SIGNUPS', true),

/*
|--------------------------------------------------------------------------
| Email address of the system administrators of the instance
Expand Down
9 changes: 8 additions & 1 deletion resources/js/Pages/Adminland/Employee/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,15 @@ input[type=radio] {
</div>
</div>

<!-- disable actions if instance is in demo mode -->
<div v-if="$page.props.demo_mode" class="cf pa3 tc">
<span class="mr1">
⚠️
</span> {{ $t('app.demo_mode_deactivated') }}
</div>

<!-- Actions -->
<div class="cf pa3">
<div v-if="!$page.props.demo_mode" class="cf pa3">
<div class="flex-ns justify-between">
<div>
<inertia-link :href="'/' + $page.props.auth.company.id + '/account/employees'" class="btn dib tc w-auto-ns w-100 pv2 ph3 mb0-ns mb2">
Expand Down
9 changes: 8 additions & 1 deletion resources/js/Pages/Adminland/Employee/Delete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@
<p class="lh-copy">{{ $t('account.employee_delete_description', { name: employee.name}) }}</p>
</div>

<!-- disable actions if instance is in demo mode -->
<div v-if="$page.props.demo_mode" class="cf pa3 tc">
<span class="mr1">
⚠️
</span> {{ $t('app.demo_mode_deactivated') }}
</div>

<!-- Actions -->
<div class="cf pa3 bb-gray bb">
<div v-if="!$page.props.demo_mode" class="cf pa3 bb-gray bb">
<div class="flex-ns justify-between">
<div>
<inertia-link :href="'/' + $page.props.auth.company.id + '/account/employees'" class="btn dib tc w-auto-ns w-100 pv2 ph3 mb0-ns mb2" data-cy="cancel-button">
Expand Down
9 changes: 8 additions & 1 deletion resources/js/Pages/Adminland/Employee/Import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ input[type=radio] {
</uploadcare>
</div>

<!-- disable actions if instance is in demo mode -->
<div v-if="$page.props.demo_mode" class="cf pa3 tc">
<span class="mr1">
⚠️
</span> {{ $t('app.demo_mode_deactivated') }}
</div>

<!-- Actions -->
<div class="cf pa3">
<div v-if="!$page.props.demo_mode" class="cf pa3">
<div class="flex-ns justify-between">
<div>
<inertia-link :href="'/' + $page.props.auth.company.id + '/account/employees'" class="btn dib tc w-auto-ns w-100 pv2 ph3 mb0-ns mb2">
Expand Down
10 changes: 9 additions & 1 deletion resources/js/Pages/Adminland/General/Cancel/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@
<p class="lh-copy">{{ $t('account.cancel_account_data_lost_forever') }}</p>
</div>

<form class="cf pa3" @submit.prevent="destroy">
<!-- disable actions if instance is in demo mode -->
<div v-if="$page.props.demo_mode" class="cf pa3 tc">
<span class="mr1">
⚠️
</span> {{ $t('app.demo_mode_deactivated') }}
</div>

<!-- actions -->
<form v-if="!$page.props.demo_mode" class="cf pa3" @submit.prevent="destroy">
<div class="flex-ns justify-between">
<div>
<inertia-link :href="'/' + $page.props.auth.company.id + '/account'" class="btn dib tc w-auto-ns w-100 pv2 ph3 mb0-ns mb2">
Expand Down
20 changes: 19 additions & 1 deletion resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
width: 102px;
top: -78px;
}
.demo-mode {
box-shadow: 0 0 0 1px #e3e8ee;
background-color: #f6fafc;
}
</style>

<template>
Expand All @@ -18,6 +23,13 @@
</h2>
<p class="tc mb4">🥳 {{ $t('auth.login_title') }}</p>
</div>

<div v-if="$page.props.demo_mode" class="demo-mode pa3 mb3">
<p>{{ $t('app.demo_mode_login') }}</p>
<p class="pl3 mt0 mb2">{{ $t('app.demo_mode_email') }}: <span class="fw6">admin@admin.com</span></p>
<p class="pl3 ma0">{{ $t('app.demo_mode_password') }}: <span class="fw6">admin</span></p>
</div>

<div class="">
<!-- Form Errors -->
<errors :errors="form.errors" :class="'mb3'" />
Expand Down Expand Up @@ -46,7 +58,9 @@
</form>
</div>
</div>
<div class="tc">

<!-- link to signup -->
<div v-if="enableSignup" class="tc">
<p class="f6">{{ $t('auth.login_no_account') }} <inertia-link :href="registerUrl">{{ $t('auth.login_register') }}</inertia-link></p>
</div>
</div>
Expand All @@ -70,6 +84,10 @@ export default {
type: String,
default: null,
},
enableSignup: {
type: Boolean,
default: false,
}
},
data() {
Expand Down
13 changes: 13 additions & 0 deletions resources/js/Shared/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ nav {
}
}
}
&.demo-mode {
background-color: #fff9cb;
}
}
.ball-pulse {
Expand All @@ -55,11 +59,20 @@ nav {
<template>
<div>
<div class="dn db-m db-l">
<!-- DEMO MODE -->
<nav v-if="$page.props.demo_mode" class="bb b--white-10 tc pa3 demo-mode">
<span class="mr1">
⚠️
</span> {{ $t('app.demo_mode_desc') }} <a href="">{{ $t('app.demo_mode_read_more') }}</a>
</nav>

<nav class="flex justify-between bb b--white-10">
<div class="flex-grow pa2 flex items-center">
<inertia-link href="/home" class="mr3 no-underline pa2 bb-0">
<img loading="lazy" src="/img/logo.png" height="30" width="30" alt="logo" />
</inertia-link>

<!-- MENU -->
<div v-if="!noMenu">
<inertia-link v-if="$page.props.auth.employee.display_welcome_message" :href="'/' + $page.props.auth.company.id + '/welcome'" data-cy="header-desktop-welcome-tab" class="mr1 no-underline pa2 bb-0 special">
<span class="mr1">👋</span> {{ $t('app.header_welcome') }}
Expand Down
7 changes: 7 additions & 0 deletions resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
'error_exception' => 'Exception:',
'error_email_already_taken' => 'This email is already taken.',

'demo_mode_desc' => 'This is a demo account. Some features are deactivated. Data resets every 5 minutes.',
'demo_mode_deactivated' => 'This feature is deactivated in demo mode.',
'demo_mode_read_more' => 'Read more',
'demo_mode_login' => 'This is a demo account. Please use the following credentials:',
'demo_mode_email' => 'Email',
'demo_mode_password' => 'Password',

'previous' => 'Previous',
'next' => 'Next',

Expand Down

0 comments on commit 70b6fa2

Please sign in to comment.