-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
16,179 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/storage/*.key | ||
/vendor | ||
/.idea | ||
/.vscode | ||
/.vagrant | ||
Homestead.json | ||
Homestead.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,6 @@ class EncryptCookies extends Middleware | |
* @var array | ||
*/ | ||
protected $except = [ | ||
// | ||
'locale' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.