Skip to content

Commit 8504558

Browse files
committed
move hashid to env, add artisan cmd to populate
1 parent f6cc606 commit 8504558

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ MAILGUN_SECRET=
2727
APP_PHASE=1
2828
REGISTER_ENABLED=true
2929
APPLICATIONS_OPEN=false
30-
SNAPCHATCODE=false
30+
SNAPCHATCODE=false
31+
HASHID_SALT=
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
namespace App\Console\Commands;
3+
use Illuminate\Support\Str;
4+
use Illuminate\Console\Command;
5+
class HashidSalt extends Command
6+
{
7+
/**
8+
* The name and signature of the console command.
9+
*
10+
* @var string
11+
*/
12+
protected $signature = 'hashid:generate';
13+
/**
14+
* The console command description.
15+
*
16+
* @var string
17+
*/
18+
protected $description = 'Set the hashid salt in .env';
19+
/**
20+
* Execute the console command.
21+
*
22+
* @return void
23+
*/
24+
public function handle()
25+
{
26+
$key = $this->generateRandomKey();
27+
$this->setKeyInEnvironmentFile($key);
28+
$this->laravel['config']['hashids.connections.main.salt'] = $key;
29+
$this->info("JWT key [$key] set successfully.");
30+
}
31+
/**
32+
* Set the application key in the environment file.
33+
*
34+
* @param string $key
35+
* @return void
36+
*/
37+
protected function setKeyInEnvironmentFile($key)
38+
{
39+
file_put_contents($this->laravel->environmentFilePath(), str_replace(
40+
'HASHID_SALT='.$this->laravel['config']['hashids.connections.main.salt'],
41+
'HASHID_SALT='.$key,
42+
file_get_contents($this->laravel->environmentFilePath())
43+
));
44+
}
45+
/**
46+
* Generate a random key for the application.
47+
*
48+
* @return string
49+
*/
50+
protected function generateRandomKey()
51+
{
52+
return str_random(10);
53+
}
54+
}

app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
1313
* @var array
1414
*/
1515
protected $commands = [
16-
//
16+
Commands\HashidSalt::class,
1717
];
1818

1919
/**

config/hashids.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'connections' => [
4141

4242
'main' => [
43-
'salt' => 'n5caQO5Rkw',
43+
'salt' => env('HASHID_SALT'),
4444
'length' => '10',
4545
],
4646
],

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ LaunchPad is an open source Content Management System built with Laravel, and is
1111

1212
## Setup
1313
First, ensure that you have the following prerequisites installed:
14-
- PHP >= 7.0.0
14+
- PHP >= 7.1.3
1515
- Database Server (MySQL, MariaDB, or PostgreSQL)
1616
- [Composer](https://getcomposer.org/)
1717
- OpenSSL PHP Extension
1818
- PDO PHP Extension
1919
- Mbstring PHP Extension
2020
- Tokenizer PHP Extension
2121
- XML PHP Extension
22+
- Ctype PHP Extension
23+
- JSON PHP Extension
2224

2325
Download the source via `git clone` or the .zip option. Enter the directory through a command prompt, and run `composer install`.
2426

2527
Then, copy `.env.example` to `.env`, and fill in the all the relevant values (especially your `DB_` database configuration values).
2628

2729
Finally, run:
2830
- `php artisan key:generate`
31+
- `php artisan hashid:generate`
2932
- `php artisan migrate`
3033
- `php artisan db:seed`
3134
- `php artisan storage:link`

0 commit comments

Comments
 (0)