Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesPong committed Mar 26, 2018
2 parents 9622fbf + 6535b55 commit 8f531cd
Show file tree
Hide file tree
Showing 121 changed files with 16,179 additions and 717 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
Expand Down Expand Up @@ -34,6 +36,9 @@ PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

YOUDAO_APP_KEY=
YOUDAO_APP_SECRET=

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/storage/*.key
/vendor
/.idea
/.vscode
/.vagrant
Homestead.json
Homestead.yaml
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "docker"]
path = docker
url = https://github.com/MilesPong/docker-lnmp.git
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

## 1.1.0 - 2018-03-26
### Added
- Docker support ([defe382](https://github.com/MilesPong/indigo/commit/defe3824d538163e5ad0cb52838963d7d03bc359), [4730e0f](https://github.com/MilesPong/indigo/commit/4730e0fc6480ebfcad3b73a5bb29a48a07c3a0c8))
- `user:add` command
- Show Algolia logo when using `algolia` driver
- Localization support

### Changed
- Upgrade npm packages
- Seeder and ModelFactory ([da69855](https://github.com/MilesPong/indigo/commit/da698558b3f13e66e14e29645e21019c37fc9266))
- Upgrade to Laravel 5.6

### Fixed
- Bug of updating `updated_at` after saving counter

### Removed
- Column `user_id` on Page model

## 1.0.4 - 2018-03-19
### Added
- [README.md](README.md)
Expand Down
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Indigo

A blog application built with [Laravel](https://laravel.com), [Materialize](http://materializecss.com) and [Vue.js](https://vuejs.org/).
Expand Down Expand Up @@ -39,12 +40,19 @@ Also, additional services below may be used and **recommended**

## Installation

### Use Docker

> **To avoid some deployment issues, you can run this application in [Docker](https://www.docker.com/) as well.
> Please check this [document](https://github.com/MilesPong/docker-lnmp/blob/indigo/README.md) for more details.**
### Configuration

```bash
$ git clone https://github.com/MilesPong/indigo
$ git clone https://github.com/MilesPong/indigo.git
$ cd indigo
$ cp .env.example .env
$ composer install
$ php artisan key:generate
$ cp .env.example .env
```

Change your DB settings and other services' configurations
Expand Down Expand Up @@ -77,6 +85,14 @@ SCOUT_QUEUE=false
SCOUT_DRIVER=null
```

Change **log channel** in case you are not using `slack` channel which is enabled in `stack` channel by default, such as `LOG_CHANNEL=single`.

Create a symbolic link for `public` driver of **filesystem**

```bash
$ php artisan storage:link
```

**Schedule** are required by default, set it up as follow

```bash
Expand All @@ -89,10 +105,20 @@ $ crontab -e

### Migration

*Default user(admin) info is in [InitializationSeeder](database/seeds/InitializationSeeder.php ), you can modify it before running the seed task.*
```bash
$ php artisan migrate --seed
```

Create the first user (admin) by using command below:

```bash
$ php artisan user:add
```

Fake data is support for development, just seed the database:

```bash
$ php artisan migrate --seed # Migration and seeding
$ php artisan db:seed --class=FakeDataSeeder
```

### Compiling Assets
Expand All @@ -116,7 +142,7 @@ Check this out in [Gist](https://gist.github.com/MilesPong/7529f9586fb7070a7f4c5
## Links

- [Materialize](http://materializecss.com)
- [Vuejs](https://vuejs.org)
- [Vue.js](https://vuejs.org)
- [Laravel](https://laravel.com)

## Contributing
Expand Down
85 changes: 85 additions & 0 deletions app/Console/Commands/AddUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;

/**
* Class AddUser
* @package App\Console\Commands
*/
class AddUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:add';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add a user (admin)';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$email = $this->ask('What is your E-mail?');
$name = $this->ask('What is your name?');
$password = $this->secret('What is the password?');
$password_confirmation = $this->secret('Confirm password again:');

$data = compact('email', 'name', 'password', 'password_confirmation');

$this->validate($data);

$this->createUser($data);

$this->info("Account create successfully! Welcome, {$name}");
}

/**
* @param array $data
*/
protected function validate(array $data)
{
$validator = Validator::make($data, [
'email' => 'required|email|unique:users',
'name' => 'required|min:2',
'password' => 'required|min:6|confirmed'
]);

if ($validator->fails()) {
$this->error($validator->errors()->first());
exit;
}
}

/**
* @param $data
*/
protected function createUser($data)
{
User::create(array_merge($data, [
'password' => bcrypt($data['password'])
]));
}
}
2 changes: 2 additions & 0 deletions app/Console/Commands/SaveCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ private function updateCount($viewable, array $data = [])
$tableData = [];

foreach ($data as $identifier => $increment) {
// Just update "view_count" without touching "updated_at".
$viewable->timestamps = false;
$viewable->newQuery()->where($viewable->getKeyName(), $identifier)->increment($viewable->getCountField(),
$increment);
array_push($tableData, [$identifier, $increment]);
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Auth\Traits\AuthRedirect;
use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

Expand Down Expand Up @@ -68,7 +69,7 @@ protected function create(array $data)
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'password' => Hash::make($data['password']),
]);
}
}
4 changes: 4 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,

\App\Http\Middleware\SetLocale::class
],

'api' => [
Expand All @@ -54,8 +56,10 @@ class Kernel extends HttpKernel
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class EncryptCookies extends Middleware
* @var array
*/
protected $except = [
//
'locale'
];
}
98 changes: 98 additions & 0 deletions app/Http/Middleware/SetLocale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Http\Middleware;

use App\Indigo\Tools\Localization;
use Carbon\Carbon;
use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Cookie;

/**
* Class SetLocale
* @package App\Http\Middleware
*/
class SetLocale
{
/**
* @var string
*/
protected $localeName = 'locale';

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// See if it has locale request via query string.
// If it doesn't have one or a fail request, we will check the request header named "Accept-Language".
if ($locale = Localization::getValidLocaleFromRequest($request, $this->localeName)) {
// Set cookie and redirect to path without query string.
return $this->redirectResponseWithCookie($request, $locale);
}

$locale = Localization::retrieveLocale($request, $this->localeName);

if ($locale) {
$this->setLocale($locale);
}

return $next($request);
}

/**
* @param \Illuminate\Http\Request $request
* @param $locale
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectResponseWithCookie(Request $request, $locale)
{
return RedirectResponse::create($this->getRedirectUrl($request))->withCookie(new Cookie($this->localeName,
$locale, Carbon::now()->addMonth()));
}

/**
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function getRedirectUrl(Request $request)
{
$originalQueries = $request->query();

unset($originalQueries[$this->localeName]);

$question = $request->getBaseUrl() . $request->getPathInfo() == '/' ? '/?' : '?';

return count($originalQueries) > 0 ? $request->url() . $question . http_build_query($originalQueries) : $request->url();
}

/**
* @param $locale
* @return void
*/
protected function setLocale($locale)
{
app()->setLocale($locale);

setlocale(LC_TIME, str_replace('-', '_', $locale) . '.utf8', 'en_US.utf8');

$this->setCarbonLocale($locale);
}

/**
* Set Carbon's locale.
*
* @param $locale
* @return bool
*/
protected function setCarbonLocale($locale)
{
// e.g. en-US to en, zh-CN to zh, zh-TW to zh
return Carbon::setLocale(strtolower(substr($locale, 0, 2)));
}
}
12 changes: 3 additions & 9 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ class TrustProxies extends Middleware
protected $proxies;

/**
* The current proxy header mappings.
* The headers that should be used to detect proxies.
*
* @var array
* @var string
*/
protected $headers = [
Request::HEADER_FORWARDED => 'FORWARDED',
Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
Loading

0 comments on commit 8f531cd

Please sign in to comment.