Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglelecc committed Mar 18, 2018
1 parent 9a1cf97 commit d23d02a
Show file tree
Hide file tree
Showing 958 changed files with 247,806 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

BAIDU_TRANSLATE_APPID=
BAIDU_TRANSLATE_KEY=

DEBUGBAR_ENABLED=true

API_STANDARDS_TREE=prs
API_SUBTYPE=laracms
API_DOMAIN=
API_PREFIX=api
API_VERSION=v1
API_DEBUG=true

WEIXIN_KEY=
WEIXIN_SECRET=

JWT_SECRET=HSKxIUfwCdJj5gadbqfQo5im9zje95g9
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
33 changes: 33 additions & 0 deletions app/Console/Commands/GenerateToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;

class GenerateToken extends Command
{
protected $signature = 'laracms:generate-token';

protected $description = '快速为用户生成 token';

public function __construct()
{
parent::__construct();
}

public function handle()
{
$userId = $this->ask('输入用户 id');

$user = User::find($userId);

if (!$user) {
return $this->error('用户不存在');
}

// 一年以后过期
$ttl = 365*24*60;
$this->info(\Auth::guard('api')->setTTL($ttl)->fromUser($user));
}
}
67 changes: 67 additions & 0 deletions app/Console/Commands/SyncBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Block;

class SyncBlock extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'laracms:sync-block';

/**
* The console command description.
*
* @var string
*/
protected $description = 'synchronous block structure...';

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

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$blocks = config('blocks.structure');
foreach($blocks as $block){
$this->synchronousBlock($block);
}
$this->info("Block structure Synchronization completed.");
}

// 同步区块

public function synchronousBlock($block){
if( Block::where('object_id', $block['object_id'])->first() ){
return false;
}
if(Block::create($block)){
$this->info("Block {$block['object_id']} Synchronization Success!");
}else{
$this->info("Block {$block['object_id']} Synchronization Failed!");
}
}

// 示例调用其它命令
public function demo(){
$this->call('email:send', [
'user' => 1, '--queue' => 'default'
]);
}
}
42 changes: 42 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
72 changes: 72 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Auth\Access\AuthorizationException;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof AuthorizationException) {
return redirect()->guest(route('administrator.permission-denied'));
}

return parent::render($request, $exception);
}

protected function unauthenticated($request, AuthenticationException $exception)
{
$action = $request->route()->getAction();
$redirectUrl = (config('administrator.domain') == $action['domain']) || ('/'. config('administrator.domain') == $action['prefix']) ?
route('administrator.login') : route('login');

return $request->expectsJson()
? response()->json(['message' => $exception->getMessage()], 401)
: redirect()->guest($redirectUrl);
}

// Illuminate\Auth\Access\AuthorizationException
}
73 changes: 73 additions & 0 deletions app/Handlers/AdministratorMenuHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Created by PhpStorm.
* User: lele.wang
* Date: 2018/2/1
* Time: 16:24
*/
namespace App\Handlers;

class AdministratorMenuHandler
{
static $administratorMenu = [];

/**
* 获取后台菜单
* @return array
*/
public function getAdministratorMenu(){
if(empty(static::$administratorMenu)){
static::$administratorMenu = $this->filterPermissionWith(config('administrator.menu'));
}

return static::$administratorMenu;
}

/**
* 获取后台当前子菜单
*
* @return array
*/
public function getChildrenAdministratorMenu($menuId){
return $this->filterChildrenAdministratorMenuWith($this->getAdministratorMenu(), $menuId);
}
//
// protected function filterWith($menu)
// {
//
// }

protected function filterChildrenAdministratorMenuWith($menus,$menuId)
{
foreach($menus as $menu){
if($menu['id'] == $menuId){
return isset($menu['children']) ? $menu['children'] : [];
}else{
return isset($menu['children']) && is_array($menu['children'])
? call_user_func_array([$this, __FUNCTION__], [$menu['children'], $menuId]) : [];
}
}

return [];
}

protected function filterPermissionWith($menus){
$newMenu = [];
foreach($menus as $menu){
$permission = call_user_func($menu['permission']);
if($permission == true){
if(!empty($menu['children'])){
$menu['children'] = call_user_func_array([$this, __FUNCTION__], [$menu['children']]);
}else{
$menu['children'] = [];
}
$newMenu[] = $menu;
}
}
return $newMenu;

}



}
Loading

0 comments on commit d23d02a

Please sign in to comment.