Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
UNRELEASED CHANGES:

* Redirect to registration page if there is no account
* Improve heroku integration
* Add bullet points to lists in call log

Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"scripts": {
"postdeploy": "php artisan setup:production --force [email protected] --password=admin"
"postdeploy": "php artisan setup:production --force"
},
"env": {
"APP_KEY": {
Expand Down
10 changes: 10 additions & 0 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public static function createDefault($first_name, $last_name, $email, $password)
return $account;
}

/**
* Get if any account exists on the database.
*
* @return bool
*/
public static function hasAny()
{
return DB::table('accounts')->count() > 0;
}

/**
* Populates all the default column that should be there when a new account
* is created or reset.
Expand Down
30 changes: 15 additions & 15 deletions app/Console/Commands/SetupProduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ public function handle()
$this->callSilent('storage:link');
$this->info('✓ Symlinked the storage folder for the avatars');

$email = $this->option('email');
if (! $email) {
$email = $this->ask('Account creation: what should be your email address to login?');
}

$password = $this->option('password');
if (! $password) {
$password = $this->secret('Please choose a password:');
}

Account::createDefault('John', 'Doe', $email, $password);

$this->line('');
$this->line('-----------------------------');
$this->line('|');
$this->line('| Welcome to Monica v'.config('monica.app_version'));
$this->line('|');
$this->line('-----------------------------');
$this->info('| You can now sign in to your account:');
$this->line('| username: '.$email);
$this->line('| password: <hidden>');

$email = $this->option('email');
$password = $this->option('password');
if (! empty($email) && ! empty($password)) {
Account::createDefault('John', 'Doe', $email, $password);

$this->info('| You can now sign in to your account:');
$this->line('| username: '.$email);
$this->line('| password: <hidden>');
} elseif (Account::hasAny()) {
$this->info('| You can now log in to your account');
} else {
$this->info('| You can now register to the first account by opening the application:');
}

$this->line('| URL: '.config('app.url'));
$this->line('-----------------------------');

Expand Down
11 changes: 11 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Auth;

use App\Account;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

Expand Down Expand Up @@ -36,4 +37,14 @@ public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}

public function showLoginOrRegister()
{
$first = ! Account::hasAny();
if ($first) {
return redirect('/register');
}

return $this->showLoginForm();
}
}
12 changes: 8 additions & 4 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ public function __construct()
*/
public function showRegistrationForm()
{
if (config('monica.disable_signup') == 'true') {
$first = ! Account::hasAny();
if (config('monica.disable_signup') == 'true' && ! $first) {
abort(403, trans('auth.signup_disabled'));
}

return view('auth.register');
return view('auth.register', ['first' => $first]);
}

/**
Expand All @@ -80,11 +81,14 @@ protected function validator(array $data)
*/
protected function create(array $data)
{
$first = ! Account::hasAny();
$account = Account::createDefault($data['first_name'], $data['last_name'], $data['email'], $data['password']);
$user = $account->users()->first();

// send me an alert
dispatch(new SendNewUserAlert($user));
if (! $first) {
// send me an alert
dispatch(new SendNewUserAlert($user));
}

return $user;
}
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"/js/app.js": "/js/app.js?id=d05ffc9de1c53b7a7c81",
"/css/app.css": "/css/app.css?id=f52285cef1e0853aec3f",
"/js/app.js": "/js/app.js?id=228f0f6f7ab7c035c695",
"/css/app.css": "/css/app.css?id=2984556e5f69d69788e7",
"/css/stripe.css": "/css/stripe.css?id=956554a2e96db30fafa3",
"/js/app.js.map": "/js/app.js.map?id=457e24747d8dd360c138",
"/js/app.js.map": "/js/app.js.map?id=2578c3d8eb82998b6142",
"/css/app.css.map": "/css/app.css.map?id=516bf3da4d93de8e038d",
"/css/stripe.css.map": "/css/stripe.css.map?id=2be6f42e97a043f30026",
"/js/stripe.js": "/js/stripe.js?id=2ab8adacb3b594bc272d",
Expand Down
7 changes: 6 additions & 1 deletion resources/assets/sass/marketing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@
padding: 50px 20px 20px;

.logo {
left: 45%;
left: 40%;
position: absolute;
top: -33px;
}

h1 {
font-weight: 700;
text-align: center;
}

h2, h3 {
font-weight: 300;
text-align: center;
Expand Down
2 changes: 2 additions & 0 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<li>Forget your password? <a href="/password/reset">Reset your password</a></li>
@if(! config('monica.disable_signup'))
<li>Don't have an account? <a href="/register">Sign up</a></li>
@elseif(! \App\Account::hasAny())
<li>Create the first account by <a href="/register">signing up</a></li>
@endif
</ul>
</div>
Expand Down
9 changes: 7 additions & 2 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

<div class="signup-box">
<img class="logo" src="/img/small-logo.png" alt="">
<h2>Create your Monica account</h2>
<h3><a href="/login">Log in</a> if you already have an account.</h3>
@if($first)
<h1>Welcome to your newly installed Monica instance</h1>
<h2>You need to create an account to use Monica</h2>
@else
<h2>Create your Monica account</h2>
<h3><a href="/login">Log in</a> if you already have an account.</h3>
@endif

@include ('partials.errors')

Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
URL::forceScheme('https');
}

Route::get('/', 'Auth\LoginController@showLoginForm')->name('login');
Route::get('/', 'Auth\LoginController@showLoginOrRegister')->name('login');

Auth::routes();

Expand Down
17 changes: 7 additions & 10 deletions scripts/docker/test-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
MONICADIR=/var/www/monica
ARTISAN="php ${MONICADIR}/artisan"

if [[ -z ${APP_KEY:-} || "$APP_KEY" == "ChangeMeBy32KeyLengthOrGenerated" ]]; then
${ARTISAN} key:generate --no-interaction
else
echo "APP_KEY already set"
fi
${ARTISAN} migrate --force
${ARTISAN} storage:link
${ARTISAN} db:seed --class ActivityTypesTableSeeder --force
${ARTISAN} db:seed --class CountriesSeederTable --force

# Ensure storage directories are present
STORAGE=${MONICADIR}/storage
mkdir -p ${STORAGE}/logs
Expand All @@ -23,6 +13,13 @@ mkdir -p ${STORAGE}/framework/sessions
chown -R monica:apache ${STORAGE}
chmod -R g+rw ${STORAGE}

if [[ -z ${APP_KEY:-} || "$APP_KEY" == "ChangeMeBy32KeyLengthOrGenerated" ]]; then
${ARTISAN} key:generate --no-interaction
else
echo "APP_KEY already set"
fi
${ARTISAN} setup:production --force

# Run cron
crond -b &

Expand Down
16 changes: 8 additions & 8 deletions scripts/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
VAGRANTFILE_API_VERSION ||= "2"

$script = <<SCRIPT
MONICA_USER=${MONICA_USER:[email protected]}
MONICA_PASSWORD=${MONICA_PASSWORD:-admin}

DESTDIR=/var/www/html/monica

cd $DESTDIR
cd /var/www/html/monica

echo -e "\n\033[4;32mConfiguring Monica\033[0;40m"

sudo -u www-data php artisan key:generate
sudo -u www-data php artisan setup:production --force --email=$MONICA_USER --password=$MONICA_PASSWORD
APP_KEY=$(source .env 2>/dev/null || echo $APP_KEY)
if [[ -z ${APP_KEY:-} || "$APP_KEY" == "ChangeMeBy32KeyLengthOrGenerated" ]]; then
${ARTISAN} key:generate --no-interaction
else
echo "APP_KEY already set"
fi
sudo -u www-data php artisan setup:production --force
sudo -u www-data php artisan passport:install

echo -e "\n\n\033[1;32mDone! You can access Monica by visiting \033[4;96mhttp://localhost:8080\033[0;40m\033[1;32m from your host machine\033[0;40m"
Expand Down