├── .env.example ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── Console │ ├── Commands │ │ └── Inspire.php │ └── Kernel.php ├── Events │ └── Event.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── AuthController.php │ │ │ └── PasswordController.php │ │ └── Controller.php │ ├── Kernel.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── EncryptCookies.php │ │ ├── RedirectIfAuthenticated.php │ │ └── VerifyCsrfToken.php │ ├── Requests │ │ └── Request.php │ ├── Validators │ │ └── UserValidate.php │ └── routes.php ├── Jobs │ └── Job.php ├── Listeners │ └── .gitkeep ├── Providers │ ├── AppServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php └── User.php ├── artisan ├── bootstrap ├── app.php ├── autoload.php └── cache │ └── .gitignore ├── composer.json ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── compile.php ├── database.php ├── entrust.php ├── filesystems.php ├── jwt.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ └── ModelFactory.php ├── migrations │ ├── .gitkeep │ ├── 2014_10_12_000000_create_users_table.php │ └── 2014_10_12_100000_create_password_resets_table.php └── seeds │ ├── .gitkeep │ └── DatabaseSeeder.php ├── gulpfile.js ├── package.json ├── packages └── Users │ ├── Commands │ ├── MigrationCommand.php │ └── migrations │ │ ├── 2015_07_25_145818_entrust_setup_tables.php │ │ ├── 2015_08_20_084811_users_add_profiles_field.php │ │ ├── 2015_08_30_031807_users_create_table_route_permission.php │ │ ├── 2015_09_01_075306_users_add_status_field.php │ │ ├── 2015_09_04_021739_users_add_birthday_gender_field.php │ │ └── 2015_12_11_072547_users_add_soft_delete_field.php │ ├── Contracts │ └── Validator.php │ ├── Controllers │ ├── AuthController.php │ ├── Controller.php │ ├── PasswordController.php │ ├── PermissionController.php │ ├── RoleController.php │ ├── RoutePermissionController.php │ └── UserController.php │ ├── Middleware │ ├── Authenticate.php │ ├── Permission.php │ ├── RoutePermission.php │ └── Validate.php │ ├── Models │ ├── Permission.php │ ├── Role.php │ ├── RoutePermission.php │ ├── User.php │ └── UserTrait.php │ ├── Providers │ └── UserServiceProvider.php │ ├── config │ ├── entrust.php │ └── jwt.php │ ├── database │ ├── .gitkeep │ └── seeds │ │ └── UserModuleSeeder.php │ └── resources │ └── views │ ├── errors │ ├── authenticate.array.php │ └── validation.array.php │ ├── helpers │ └── links.helper.php │ ├── partials │ ├── permission.array.php │ ├── role.array.php │ ├── routePermission.array.php │ └── user.array.php │ ├── permission │ ├── browse.array.php │ └── read.array.php │ ├── role │ ├── browse.array.php │ └── read.array.php │ ├── route │ └── browse.array.php │ ├── routePermission │ ├── browse.array.php │ └── read.array.php │ ├── tokens │ └── show.array.php │ └── user │ ├── browse.array.php │ └── read.array.php ├── phpspec.yml ├── phpunit.xml ├── public ├── .htaccess ├── favicon.ico ├── index.php └── robots.txt ├── resources ├── assets │ └── sass │ │ └── app.scss ├── lang │ └── en │ │ ├── auth.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php └── views │ ├── emails │ └── password.blade.php │ ├── errors │ └── 503.blade.php │ ├── vendor │ └── .gitkeep │ └── welcome.blade.php ├── server.php ├── storage ├── app │ └── .gitignore ├── database.sqlite ├── database.sqlite.blank ├── framework │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore └── tests ├── TestCase.php ├── Users ├── Controllers │ ├── AuthControllerTest.php │ ├── ControllerTest.php │ ├── PasswordControllerTest.php │ ├── PermissionControllerTest.php │ ├── RoleControllerTest.php │ ├── RoutePermissionControllerTest.php │ └── UserControllerTest.php └── Middleware │ ├── AuthenticateTest.php │ ├── PermissionTest.php │ ├── RoutePermissionTest.php │ └── ValidateTest.php └── build ├── bin ├── phpcs ├── phpmd ├── phpqunit └── phpunit ├── config ├── phpcs.xml ├── phpmd.xml └── phpunit.quick.xml ├── coverage └── .gitignore ├── logs └── .gitignore └── scripts ├── ColorCLI.php ├── checkstyle.php ├── junit.php └── pmd.php /.env.example: -------------------------------------------------------------------------------- 1 | APP_ENV=local 2 | APP_DEBUG=true 3 | APP_KEY=SomeRandomString 4 | 5 | DB_HOST=localhost 6 | DB_DATABASE=homestead 7 | DB_USERNAME=homestead 8 | DB_PASSWORD=secret 9 | 10 | CACHE_DRIVER=file 11 | SESSION_DRIVER=file 12 | QUEUE_DRIVER=sync 13 | 14 | MAIL_DRIVER=smtp 15 | MAIL_HOST=mailtrap.io 16 | MAIL_PORT=2525 17 | MAIL_USERNAME=null 18 | MAIL_PASSWORD=null 19 | MAIL_ENCRYPTION=null 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.less linguist-vendored 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /node_modules 3 | Homestead.yaml 4 | .env 5 | /composer.lock 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.5.9 5 | 6 | before_script: 7 | - composer self-update 8 | - composer install --prefer-source --no-interaction --dev 9 | 10 | script: 11 | - vendor/bin/phpunit --configuration phpunit.xml 12 | - php tests/build/scripts/junit.php 13 | - . tests/build/bin/phpcs 14 | - . tests/build/bin/phpmd 15 | 16 | notifications: 17 | on_success: always 18 | on_failure: always 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PHP Software Development 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /app/Console/Commands/Inspire.php: -------------------------------------------------------------------------------- 1 | comment(PHP_EOL.Inspiring::quote().PHP_EOL); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | ->hourly(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Events/Event.php: -------------------------------------------------------------------------------- 1 | json([ 'message' => $e->getMessage() ], 500); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/AuthController.php: -------------------------------------------------------------------------------- 1 | middleware('guest', ['except' => 'getLogout']); 34 | } 35 | 36 | /** 37 | * Get a validator for an incoming registration request. 38 | * 39 | * @param array $data 40 | * @return \Illuminate\Contracts\Validation\Validator 41 | */ 42 | protected function validator(array $data) 43 | { 44 | return Validator::make($data, [ 45 | 'name' => 'required|max:255', 46 | 'email' => 'required|email|max:255|unique:users', 47 | 'password' => 'required|confirmed|min:6', 48 | ]); 49 | } 50 | 51 | /** 52 | * Create a new user instance after a valid registration. 53 | * 54 | * @param array $data 55 | * @return User 56 | */ 57 | protected function create(array $data) 58 | { 59 | return User::create([ 60 | 'name' => $data['name'], 61 | 'email' => $data['email'], 62 | 'password' => bcrypt($data['password']), 63 | ]); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | \App\Http\Middleware\Authenticate::class, 30 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 31 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 32 | 'jwt.auth' => \PhpSoft\Users\Middleware\Authenticate::class, 33 | 'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class, 34 | 'permission' => \PhpSoft\Users\Middleware\Permission::class, 35 | 'routePermission'=> \PhpSoft\Users\Middleware\RoutePermission::class, 36 | 'validate' => \PhpSoft\Users\Middleware\Validate::class, 37 | ]; 38 | } 39 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 26 | } 27 | 28 | /** 29 | * Handle an incoming request. 30 | * 31 | * @param \Illuminate\Http\Request $request 32 | * @param \Closure $next 33 | * @return mixed 34 | */ 35 | public function handle($request, Closure $next) 36 | { 37 | if ($this->auth->guest()) { 38 | if ($request->ajax()) { 39 | return response('Unauthorized.', 401); 40 | } else { 41 | return redirect()->guest('auth/login'); 42 | } 43 | } 44 | 45 | return $next($request); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 26 | } 27 | 28 | /** 29 | * Handle an incoming request. 30 | * 31 | * @param \Illuminate\Http\Request $request 32 | * @param \Closure $next 33 | * @return mixed 34 | */ 35 | public function handle($request, Closure $next) 36 | { 37 | if ($this->auth->check()) { 38 | return redirect('/home'); 39 | } 40 | 41 | return $next($request); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyCsrfToken.php: -------------------------------------------------------------------------------- 1 | 'required|max:255|validate_name', 40 | 'email' => 'required|email', 41 | 'password' => 'required|confirmed|min:6' 42 | ]; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Http/routes.php: -------------------------------------------------------------------------------- 1 | 'jwt.auth'], function() { 20 | 21 | Route::post('/auth/logout', '\PhpSoft\Users\Controllers\AuthController@logout'); 22 | Route::get('/me', '\PhpSoft\Users\Controllers\UserController@authenticated'); 23 | Route::patch('/me', '\PhpSoft\Users\Controllers\UserController@update'); 24 | Route::put('/me/password', '\PhpSoft\Users\Controllers\PasswordController@change'); 25 | 26 | Route::get('/routePermissions', '\PhpSoft\Users\Controllers\RoutePermissionController@index'); 27 | Route::get('/routePermissions/{id}', '\PhpSoft\Users\Controllers\RoutePermissionController@show'); 28 | Route::post('/routePermissions', '\PhpSoft\Users\Controllers\RoutePermissionController@store'); 29 | Route::patch('/routePermissions/{id}', '\PhpSoft\Users\Controllers\RoutePermissionController@update'); 30 | Route::delete('/routePermissions/{id}', '\PhpSoft\Users\Controllers\RoutePermissionController@destroy'); 31 | }); 32 | 33 | Route::post('/passwords/forgot', '\PhpSoft\Users\Controllers\PasswordController@forgot'); 34 | Route::post('/passwords/reset', '\PhpSoft\Users\Controllers\PasswordController@reset'); 35 | Route::group(['middleware'=>'routePermission'], function() { 36 | 37 | Route::get('/users/trash', '\PhpSoft\Users\Controllers\UserController@index'); 38 | Route::post('/users', '\PhpSoft\Users\Controllers\UserController@store'); 39 | Route::get('/users/{id}', '\PhpSoft\Users\Controllers\UserController@show'); 40 | Route::get('/users', '\PhpSoft\Users\Controllers\UserController@index'); 41 | Route::delete('/users/{id}', '\PhpSoft\Users\Controllers\UserController@destroy'); 42 | Route::post('/users/{id}/trash', '\PhpSoft\Users\Controllers\UserController@moveToTrash'); 43 | Route::post('/users/{id}/restore', '\PhpSoft\Users\Controllers\UserController@restoreFromTrash'); 44 | Route::patch('/users/{id}', '\PhpSoft\Users\Controllers\UserController@update'); 45 | Route::post('/users/{id}/block', '\PhpSoft\Users\Controllers\UserController@block'); 46 | Route::post('/users/{id}/unblock', '\PhpSoft\Users\Controllers\UserController@unblock'); 47 | Route::post('/users/{id}/roles', '\PhpSoft\Users\Controllers\UserController@assignRole'); 48 | Route::get('/users/{id}/roles', '\PhpSoft\Users\Controllers\RoleController@indexByUser'); 49 | 50 | Route::get('/permissions', '\PhpSoft\Users\Controllers\PermissionController@index'); 51 | Route::get('/permissions/{id}', '\PhpSoft\Users\Controllers\PermissionController@show'); 52 | Route::post('/permissions', '\PhpSoft\Users\Controllers\PermissionController@store'); 53 | Route::patch('/permissions/{id}', '\PhpSoft\Users\Controllers\PermissionController@update'); 54 | Route::delete('/permissions/{id}', '\PhpSoft\Users\Controllers\PermissionController@destroy'); 55 | 56 | Route::get('/roles', '\PhpSoft\Users\Controllers\RoleController@index'); 57 | Route::get('/roles/{id}', '\PhpSoft\Users\Controllers\RoleController@show'); 58 | Route::post('/roles', '\PhpSoft\Users\Controllers\RoleController@store'); 59 | Route::patch('/roles/{id}', '\PhpSoft\Users\Controllers\RoleController@update'); 60 | Route::delete('/roles/{id}', '\PhpSoft\Users\Controllers\RoleController@destroy'); 61 | }); 62 | 63 | Route::get('/routes', '\PhpSoft\Users\Controllers\RoutePermissionController@getAllRoutes'); 64 | -------------------------------------------------------------------------------- /app/Jobs/Job.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'App\Listeners\EventListener', 18 | ], 19 | ]; 20 | 21 | /** 22 | * Register any other events for your application. 23 | * 24 | * @param \Illuminate\Contracts\Events\Dispatcher $events 25 | * @return void 26 | */ 27 | public function boot(DispatcherContract $events) 28 | { 29 | parent::boot($events); 30 | 31 | // 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | group(['namespace' => $this->namespace], function ($router) { 41 | require app_path('Http/routes.php'); 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/User.php: -------------------------------------------------------------------------------- 1 | make(Illuminate\Contracts\Console\Kernel::class); 32 | 33 | $status = $kernel->handle( 34 | $input = new Symfony\Component\Console\Input\ArgvInput, 35 | new Symfony\Component\Console\Output\ConsoleOutput 36 | ); 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Shutdown The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once Artisan has finished running. We will fire off the shutdown events 44 | | so that any final work may be done by the application before we shut 45 | | down the process. This is the last thing to happen to the request. 46 | | 47 | */ 48 | 49 | $kernel->terminate($input, $status); 50 | 51 | exit($status); 52 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/autoload.php: -------------------------------------------------------------------------------- 1 | =5.5.9", 19 | "laravel/framework": "5.1.*", 20 | "php-soft/laravel-array-view": "1.1.x", 21 | "tymon/jwt-auth": "0.5.*", 22 | "zizaco/entrust": "dev-laravel-5", 23 | "doctrine/dbal": "^2.5" 24 | }, 25 | "require-dev": { 26 | "fzaninotto/faker": "~1.4", 27 | "mockery/mockery": "0.9.*", 28 | "phpunit/phpunit": "~4.0", 29 | "phpspec/phpspec": "~2.1", 30 | "squizlabs/php_codesniffer": "1.4.*@stable", 31 | "phpmd/phpmd": "2.2.*" 32 | }, 33 | "autoload": { 34 | "classmap": [ 35 | "packages/Users/database" 36 | ], 37 | "psr-4": { 38 | "PhpSoft\\Users\\": "packages/Users" 39 | } 40 | }, 41 | "autoload-dev": { 42 | "classmap": [ 43 | "database", 44 | "tests/TestCase.php" 45 | ], 46 | "psr-4": { 47 | "App\\": "app/" 48 | } 49 | }, 50 | "scripts": { 51 | "post-install-cmd": [ 52 | "php artisan clear-compiled", 53 | "php artisan optimize" 54 | ], 55 | "post-update-cmd": [ 56 | "php artisan optimize" 57 | ], 58 | "post-root-package-install": [ 59 | "php -r \"copy('.env.example', '.env');\"" 60 | ], 61 | "post-create-project-cmd": [ 62 | "php artisan key:generate" 63 | ] 64 | }, 65 | "config": { 66 | "preferred-install": "dist" 67 | }, 68 | "extra": { 69 | "branch-alias": { 70 | "dev-master": "1.0-dev" 71 | } 72 | }, 73 | "minimum-stability": "dev" 74 | } 75 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | 'eloquent', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Authentication Model 23 | |-------------------------------------------------------------------------- 24 | | 25 | | When using the "Eloquent" authentication driver, we need to know which 26 | | Eloquent model should be used to retrieve your users. Of course, it 27 | | is often just the "User" model but you may use whatever you like. 28 | | 29 | */ 30 | 31 | 'model' => App\User::class, 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Authentication Table 36 | |-------------------------------------------------------------------------- 37 | | 38 | | When using the "Database" authentication driver, we need to know which 39 | | table should be used to retrieve your users. We have chosen a basic 40 | | default value but you may easily change it to any table you like. 41 | | 42 | */ 43 | 44 | 'table' => 'users', 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Password Reset Settings 49 | |-------------------------------------------------------------------------- 50 | | 51 | | Here you may set the options for resetting passwords including the view 52 | | that is your password reset e-mail. You can also set the name of the 53 | | table that maintains all of the reset tokens for your application. 54 | | 55 | | The expire time is the number of minutes that the reset token should be 56 | | considered valid. This security feature keeps tokens short-lived so 57 | | they have less time to be guessed. You may change this as needed. 58 | | 59 | */ 60 | 61 | 'password' => [ 62 | 'email' => 'emails.password', 63 | 'table' => 'password_resets', 64 | 'expire' => 60, 65 | ], 66 | 67 | ]; 68 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'pusher'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Broadcast Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may define all of the broadcast connections that will be used 24 | | to broadcast events to other systems or over websockets. Samples of 25 | | each available type of connection are provided inside this array. 26 | | 27 | */ 28 | 29 | 'connections' => [ 30 | 31 | 'pusher' => [ 32 | 'driver' => 'pusher', 33 | 'key' => env('PUSHER_KEY'), 34 | 'secret' => env('PUSHER_SECRET'), 35 | 'app_id' => env('PUSHER_APP_ID'), 36 | ], 37 | 38 | 'redis' => [ 39 | 'driver' => 'redis', 40 | 'connection' => 'default', 41 | ], 42 | 43 | 'log' => [ 44 | 'driver' => 'log', 45 | ], 46 | 47 | ], 48 | 49 | ]; 50 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Cache Stores 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may define all of the cache "stores" for your application as 24 | | well as their drivers. You may even define multiple stores for the 25 | | same cache driver to group types of items stored in your caches. 26 | | 27 | */ 28 | 29 | 'stores' => [ 30 | 31 | 'apc' => [ 32 | 'driver' => 'apc', 33 | ], 34 | 35 | 'array' => [ 36 | 'driver' => 'array', 37 | ], 38 | 39 | 'database' => [ 40 | 'driver' => 'database', 41 | 'table' => 'cache', 42 | 'connection' => null, 43 | ], 44 | 45 | 'file' => [ 46 | 'driver' => 'file', 47 | 'path' => storage_path('framework/cache'), 48 | ], 49 | 50 | 'memcached' => [ 51 | 'driver' => 'memcached', 52 | 'servers' => [ 53 | [ 54 | 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 100, 55 | ], 56 | ], 57 | ], 58 | 59 | 'redis' => [ 60 | 'driver' => 'redis', 61 | 'connection' => 'default', 62 | ], 63 | 64 | ], 65 | 66 | /* 67 | |-------------------------------------------------------------------------- 68 | | Cache Key Prefix 69 | |-------------------------------------------------------------------------- 70 | | 71 | | When utilizing a RAM based store such as APC or Memcached, there might 72 | | be other applications utilizing the same cache. So, we'll specify a 73 | | value to get prefixed to all our keys so we can avoid collisions. 74 | | 75 | */ 76 | 77 | 'prefix' => 'laravel', 78 | 79 | ]; 80 | -------------------------------------------------------------------------------- /config/compile.php: -------------------------------------------------------------------------------- 1 | [ 17 | // 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled File Providers 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may list service providers which define a "compiles" function 26 | | that returns additional files that should be compiled, providing an 27 | | easy way to get common files from any packages you are utilizing. 28 | | 29 | */ 30 | 31 | 'providers' => [ 32 | // 33 | ], 34 | 35 | ]; 36 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | PDO::FETCH_CLASS, 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Database Connection Name 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may specify which of the database connections below you wish 24 | | to use as your default connection for all database work. Of course 25 | | you may use many connections at once using the Database library. 26 | | 27 | */ 28 | 29 | 'default' => env('DB_CONNECTION', 'mysql'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Database Connections 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here are each of the database connections setup for your application. 37 | | Of course, examples of configuring each database platform that is 38 | | supported by Laravel is shown below to make development simple. 39 | | 40 | | 41 | | All database work in Laravel is done through the PHP PDO facilities 42 | | so make sure you have the driver for your particular database of 43 | | choice installed on your machine before you begin development. 44 | | 45 | */ 46 | 47 | 'connections' => [ 48 | 49 | 'sqlite' => [ 50 | 'driver' => 'sqlite', 51 | 'database' => storage_path('database.sqlite'), 52 | 'prefix' => '', 53 | ], 54 | 55 | 'mysql' => [ 56 | 'driver' => 'mysql', 57 | 'host' => env('DB_HOST', 'localhost'), 58 | 'database' => env('DB_DATABASE', 'forge'), 59 | 'username' => env('DB_USERNAME', 'forge'), 60 | 'password' => env('DB_PASSWORD', ''), 61 | 'charset' => 'utf8', 62 | 'collation' => 'utf8_unicode_ci', 63 | 'prefix' => '', 64 | 'strict' => false, 65 | ], 66 | 67 | 'pgsql' => [ 68 | 'driver' => 'pgsql', 69 | 'host' => env('DB_HOST', 'localhost'), 70 | 'database' => env('DB_DATABASE', 'forge'), 71 | 'username' => env('DB_USERNAME', 'forge'), 72 | 'password' => env('DB_PASSWORD', ''), 73 | 'charset' => 'utf8', 74 | 'prefix' => '', 75 | 'schema' => 'public', 76 | ], 77 | 78 | 'sqlsrv' => [ 79 | 'driver' => 'sqlsrv', 80 | 'host' => env('DB_HOST', 'localhost'), 81 | 'database' => env('DB_DATABASE', 'forge'), 82 | 'username' => env('DB_USERNAME', 'forge'), 83 | 'password' => env('DB_PASSWORD', ''), 84 | 'charset' => 'utf8', 85 | 'prefix' => '', 86 | ], 87 | 88 | ], 89 | 90 | /* 91 | |-------------------------------------------------------------------------- 92 | | Migration Repository Table 93 | |-------------------------------------------------------------------------- 94 | | 95 | | This table keeps track of all the migrations that have already run for 96 | | your application. Using this information, we can determine which of 97 | | the migrations on disk haven't actually been run in the database. 98 | | 99 | */ 100 | 101 | 'migrations' => 'migrations', 102 | 103 | /* 104 | |-------------------------------------------------------------------------- 105 | | Redis Databases 106 | |-------------------------------------------------------------------------- 107 | | 108 | | Redis is an open source, fast, and advanced key-value store that also 109 | | provides a richer set of commands than a typical key-value systems 110 | | such as APC or Memcached. Laravel makes it easy to dig right in. 111 | | 112 | */ 113 | 114 | 'redis' => [ 115 | 116 | 'cluster' => false, 117 | 118 | 'default' => [ 119 | 'host' => '127.0.0.1', 120 | 'port' => 6379, 121 | 'database' => 0, 122 | ], 123 | 124 | ], 125 | 126 | ]; 127 | -------------------------------------------------------------------------------- /config/entrust.php: -------------------------------------------------------------------------------- 1 | PhpSoft\Users\Models\Role::class, 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Entrust Roles Table 27 | |-------------------------------------------------------------------------- 28 | | 29 | | This is the roles table used by Entrust to save roles to the database. 30 | | 31 | */ 32 | 'roles_table' => 'roles', 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Entrust Permission Model 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the Permission model used by Entrust to create correct relations. 40 | | Update the permission if it is in a different namespace. 41 | | 42 | */ 43 | 'permission' => PhpSoft\Users\Models\Permission::class, 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | Entrust Permissions Table 48 | |-------------------------------------------------------------------------- 49 | | 50 | | This is the permissions table used by Entrust to save permissions to the 51 | | database. 52 | | 53 | */ 54 | 'permissions_table' => 'permissions', 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Entrust permission_role Table 59 | |-------------------------------------------------------------------------- 60 | | 61 | | This is the permission_role table used by Entrust to save relationship 62 | | between permissions and roles to the database. 63 | | 64 | */ 65 | 'permission_role_table' => 'permission_role', 66 | 67 | /* 68 | |-------------------------------------------------------------------------- 69 | | Entrust role_user Table 70 | |-------------------------------------------------------------------------- 71 | | 72 | | This is the role_user table used by Entrust to save assigned roles to the 73 | | database. 74 | | 75 | */ 76 | 'role_user_table' => 'role_user', 77 | 78 | ]; 79 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | 'local', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Default Cloud Filesystem Disk 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Many applications store files both locally and in the cloud. For this 26 | | reason, you may specify a default "cloud" driver here. This driver 27 | | will be bound as the Cloud disk implementation in the container. 28 | | 29 | */ 30 | 31 | 'cloud' => 's3', 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Filesystem Disks 36 | |-------------------------------------------------------------------------- 37 | | 38 | | Here you may configure as many filesystem "disks" as you wish, and you 39 | | may even configure multiple disks of the same driver. Defaults have 40 | | been setup for each driver as an example of the required options. 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'ftp' => [ 52 | 'driver' => 'ftp', 53 | 'host' => 'ftp.example.com', 54 | 'username' => 'your-username', 55 | 'password' => 'your-password', 56 | 57 | // Optional FTP Settings... 58 | // 'port' => 21, 59 | // 'root' => '', 60 | // 'passive' => true, 61 | // 'ssl' => true, 62 | // 'timeout' => 30, 63 | ], 64 | 65 | 's3' => [ 66 | 'driver' => 's3', 67 | 'key' => 'your-key', 68 | 'secret' => 'your-secret', 69 | 'region' => 'your-region', 70 | 'bucket' => 'your-bucket', 71 | ], 72 | 73 | 'rackspace' => [ 74 | 'driver' => 'rackspace', 75 | 'username' => 'your-username', 76 | 'key' => 'your-key', 77 | 'container' => 'your-container', 78 | 'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/', 79 | 'region' => 'IAD', 80 | 'url_type' => 'publicURL', 81 | ], 82 | 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /config/jwt.php: -------------------------------------------------------------------------------- 1 | env('JWT_SECRET', 'Wb0PbZXXOkaLwW7PR0ZBnuPRhM9e0idS'), 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | JWT time to live 20 | |-------------------------------------------------------------------------- 21 | | 22 | | Specify the length of time (in minutes) that the token will be valid for. 23 | | Defaults to 1 hour 24 | | 25 | */ 26 | 27 | 'ttl' => 60, 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | Refresh time to live 32 | |-------------------------------------------------------------------------- 33 | | 34 | | Specify the length of time (in minutes) that the token can be refreshed 35 | | within. I.E. The user can refresh their token within a 2 week window of 36 | | the original token being created until they must re-authenticate. 37 | | Defaults to 2 weeks 38 | | 39 | */ 40 | 41 | 'refresh_ttl' => 20160, 42 | 43 | /* 44 | |-------------------------------------------------------------------------- 45 | | JWT hashing algorithm 46 | |-------------------------------------------------------------------------- 47 | | 48 | | Specify the hashing algorithm that will be used to sign the token. 49 | | 50 | | See here: https://github.com/namshi/jose/tree/2.2.0/src/Namshi/JOSE/Signer 51 | | for possible values 52 | | 53 | */ 54 | 55 | 'algo' => 'HS256', 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | User Model namespace 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Specify the full namespace to your User model. 63 | | e.g. 'Acme\Entities\User' 64 | | 65 | */ 66 | 67 | 'user' => 'App\User', 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | User identifier 72 | |-------------------------------------------------------------------------- 73 | | 74 | | Specify a unique property of the user that will be added as the 'sub' 75 | | claim of the token payload. 76 | | 77 | */ 78 | 79 | 'identifier' => 'id', 80 | 81 | /* 82 | |-------------------------------------------------------------------------- 83 | | Required Claims 84 | |-------------------------------------------------------------------------- 85 | | 86 | | Specify the required claims that must exist in any token. 87 | | A TokenInvalidException will be thrown if any of these claims are not 88 | | present in the payload. 89 | | 90 | */ 91 | 92 | 'required_claims' => ['iss', 'iat', 'exp', 'nbf', 'sub', 'jti'], 93 | 94 | /* 95 | |-------------------------------------------------------------------------- 96 | | Blacklist Enabled 97 | |-------------------------------------------------------------------------- 98 | | 99 | | In order to invalidate tokens, you must have the the blacklist enabled. 100 | | If you do not want or need this functionality, then set this to false. 101 | | 102 | */ 103 | 104 | 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Providers 109 | |-------------------------------------------------------------------------- 110 | | 111 | | Specify the various providers used throughout the package. 112 | | 113 | */ 114 | 115 | 'providers' => [ 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | User Provider 120 | |-------------------------------------------------------------------------- 121 | | 122 | | Specify the provider that is used to find the user based 123 | | on the subject claim 124 | | 125 | */ 126 | 127 | 'user' => 'Tymon\JWTAuth\Providers\User\EloquentUserAdapter', 128 | 129 | /* 130 | |-------------------------------------------------------------------------- 131 | | JWT Provider 132 | |-------------------------------------------------------------------------- 133 | | 134 | | Specify the provider that is used to create and decode the tokens. 135 | | 136 | */ 137 | 138 | 'jwt' => 'Tymon\JWTAuth\Providers\JWT\NamshiAdapter', 139 | 140 | /* 141 | |-------------------------------------------------------------------------- 142 | | Authentication Provider 143 | |-------------------------------------------------------------------------- 144 | | 145 | | Specify the provider that is used to authenticate users. 146 | | 147 | */ 148 | 149 | 'auth' => function ($app) { 150 | return new Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter($app['auth']); 151 | }, 152 | 153 | /* 154 | |-------------------------------------------------------------------------- 155 | | Storage Provider 156 | |-------------------------------------------------------------------------- 157 | | 158 | | Specify the provider that is used to store tokens in the blacklist 159 | | 160 | */ 161 | 162 | 'storage' => function ($app) { 163 | return new Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter($app['cache']); 164 | } 165 | 166 | ] 167 | 168 | ]; 169 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | SMTP Host Address 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may provide the host address of the SMTP server used by your 26 | | applications. A default option is provided that is compatible with 27 | | the Mailgun mail service which will provide reliable deliveries. 28 | | 29 | */ 30 | 31 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | SMTP Host Port 36 | |-------------------------------------------------------------------------- 37 | | 38 | | This is the SMTP port used by your application to deliver e-mails to 39 | | users of the application. Like the host we have set this value to 40 | | stay compatible with the Mailgun e-mail application by default. 41 | | 42 | */ 43 | 44 | 'port' => env('MAIL_PORT', 587), 45 | 46 | /* 47 | |-------------------------------------------------------------------------- 48 | | Global "From" Address 49 | |-------------------------------------------------------------------------- 50 | | 51 | | You may wish for all e-mails sent by your application to be sent from 52 | | the same address. Here, you may specify a name and address that is 53 | | used globally for all e-mails that are sent by your application. 54 | | 55 | */ 56 | 57 | 'from' => ['address' => 'no-reply@example.com', 'name' => 'System'], 58 | 59 | /* 60 | |-------------------------------------------------------------------------- 61 | | E-Mail Encryption Protocol 62 | |-------------------------------------------------------------------------- 63 | | 64 | | Here you may specify the encryption protocol that should be used when 65 | | the application send e-mail messages. A sensible default using the 66 | | transport layer security protocol should provide great security. 67 | | 68 | */ 69 | 70 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | SMTP Server Username 75 | |-------------------------------------------------------------------------- 76 | | 77 | | If your SMTP server requires a username for authentication, you should 78 | | set it here. This will get used to authenticate with your server on 79 | | connection. You may also set the "password" value below this one. 80 | | 81 | */ 82 | 83 | 'username' => env('MAIL_USERNAME'), 84 | 85 | /* 86 | |-------------------------------------------------------------------------- 87 | | SMTP Server Password 88 | |-------------------------------------------------------------------------- 89 | | 90 | | Here you may set the password required by your SMTP server to send out 91 | | messages from your application. This will be given to the server on 92 | | connection so that the application will be able to send messages. 93 | | 94 | */ 95 | 96 | 'password' => env('MAIL_PASSWORD'), 97 | 98 | /* 99 | |-------------------------------------------------------------------------- 100 | | Sendmail System Path 101 | |-------------------------------------------------------------------------- 102 | | 103 | | When using the "sendmail" driver to send e-mails, we will need to know 104 | | the path to where Sendmail lives on this server. A default path has 105 | | been provided here, which will work well on most of your systems. 106 | | 107 | */ 108 | 109 | 'sendmail' => '/usr/sbin/sendmail -bs', 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Mail "Pretend" 114 | |-------------------------------------------------------------------------- 115 | | 116 | | When this option is enabled, e-mail will not actually be sent over the 117 | | web and will instead be written to your application's logs files so 118 | | you may inspect the message. This is great for local development. 119 | | 120 | */ 121 | 122 | 'pretend' => false, 123 | 124 | ]; 125 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Queue Connections 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may configure the connection information for each server that 27 | | is used by your application. A default configuration has been added 28 | | for each back-end shipped with Laravel. You are free to add more. 29 | | 30 | */ 31 | 32 | 'connections' => [ 33 | 34 | 'sync' => [ 35 | 'driver' => 'sync', 36 | ], 37 | 38 | 'database' => [ 39 | 'driver' => 'database', 40 | 'table' => 'jobs', 41 | 'queue' => 'default', 42 | 'expire' => 60, 43 | ], 44 | 45 | 'beanstalkd' => [ 46 | 'driver' => 'beanstalkd', 47 | 'host' => 'localhost', 48 | 'queue' => 'default', 49 | 'ttr' => 60, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => 'your-public-key', 55 | 'secret' => 'your-secret-key', 56 | 'queue' => 'your-queue-url', 57 | 'region' => 'us-east-1', 58 | ], 59 | 60 | 'iron' => [ 61 | 'driver' => 'iron', 62 | 'host' => 'mq-aws-us-east-1.iron.io', 63 | 'token' => 'your-token', 64 | 'project' => 'your-project-id', 65 | 'queue' => 'your-queue-name', 66 | 'encrypt' => true, 67 | ], 68 | 69 | 'redis' => [ 70 | 'driver' => 'redis', 71 | 'connection' => 'default', 72 | 'queue' => 'default', 73 | 'expire' => 60, 74 | ], 75 | 76 | ], 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Failed Queue Jobs 81 | |-------------------------------------------------------------------------- 82 | | 83 | | These options configure the behavior of failed queue job logging so you 84 | | can control which database and table are used to store the jobs that 85 | | have failed. You may change them to any database / table you wish. 86 | | 87 | */ 88 | 89 | 'failed' => [ 90 | 'database' => 'mysql', 'table' => 'failed_jobs', 91 | ], 92 | 93 | ]; 94 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => '', 19 | 'secret' => '', 20 | ], 21 | 22 | 'mandrill' => [ 23 | 'secret' => '', 24 | ], 25 | 26 | 'ses' => [ 27 | 'key' => '', 28 | 'secret' => '', 29 | 'region' => 'us-east-1', 30 | ], 31 | 32 | 'stripe' => [ 33 | 'model' => App\User::class, 34 | 'key' => '', 35 | 'secret' => '', 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle before it expires. If you want them 28 | | to immediately expire on the browser closing, set that option. 29 | | 30 | */ 31 | 32 | 'lifetime' => 120, 33 | 34 | 'expire_on_close' => false, 35 | 36 | /* 37 | |-------------------------------------------------------------------------- 38 | | Session Encryption 39 | |-------------------------------------------------------------------------- 40 | | 41 | | This option allows you to easily specify that all of your session data 42 | | should be encrypted before it is stored. All encryption will be run 43 | | automatically by Laravel and you can use the Session like normal. 44 | | 45 | */ 46 | 47 | 'encrypt' => false, 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Session File Location 52 | |-------------------------------------------------------------------------- 53 | | 54 | | When using the native session driver, we need a location where session 55 | | files may be stored. A default has been set for you but a different 56 | | location may be specified. This is only needed for file sessions. 57 | | 58 | */ 59 | 60 | 'files' => storage_path('framework/sessions'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Session Database Connection 65 | |-------------------------------------------------------------------------- 66 | | 67 | | When using the "database" or "redis" session drivers, you may specify a 68 | | connection that should be used to manage these sessions. This should 69 | | correspond to a connection in your database configuration options. 70 | | 71 | */ 72 | 73 | 'connection' => null, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Session Database Table 78 | |-------------------------------------------------------------------------- 79 | | 80 | | When using the "database" session driver, you may specify the table we 81 | | should use to manage the sessions. Of course, a sensible default is 82 | | provided for you; however, you are free to change this as needed. 83 | | 84 | */ 85 | 86 | 'table' => 'sessions', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Session Sweeping Lottery 91 | |-------------------------------------------------------------------------- 92 | | 93 | | Some session drivers must manually sweep their storage location to get 94 | | rid of old sessions from storage. Here are the chances that it will 95 | | happen on a given request. By default, the odds are 2 out of 100. 96 | | 97 | */ 98 | 99 | 'lottery' => [2, 100], 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Session Cookie Name 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Here you may change the name of the cookie used to identify a session 107 | | instance by ID. The name specified here will get used every time a 108 | | new session cookie is created by the framework for every driver. 109 | | 110 | */ 111 | 112 | 'cookie' => 'laravel_session', 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Session Cookie Path 117 | |-------------------------------------------------------------------------- 118 | | 119 | | The session cookie path determines the path for which the cookie will 120 | | be regarded as available. Typically, this will be the root path of 121 | | your application but you are free to change this when necessary. 122 | | 123 | */ 124 | 125 | 'path' => '/', 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | Session Cookie Domain 130 | |-------------------------------------------------------------------------- 131 | | 132 | | Here you may change the domain of the cookie used to identify a session 133 | | in your application. This will determine which domains the cookie is 134 | | available to in your application. A sensible default has been set. 135 | | 136 | */ 137 | 138 | 'domain' => null, 139 | 140 | /* 141 | |-------------------------------------------------------------------------- 142 | | HTTPS Only Cookies 143 | |-------------------------------------------------------------------------- 144 | | 145 | | By setting this option to true, session cookies will only be sent back 146 | | to the server if the browser has a HTTPS connection. This will keep 147 | | the cookie from being sent to you if it can not be done securely. 148 | | 149 | */ 150 | 151 | 'secure' => false, 152 | 153 | ]; 154 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | realpath(base_path('resources/views')), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/ModelFactory.php: -------------------------------------------------------------------------------- 1 | define(App\User::class, function (Faker\Generator $faker) { 15 | return [ 16 | 'name' => $faker->name, 17 | 'email' => $faker->email, 18 | 'password' => bcrypt(str_random(10)), 19 | 'remember_token' => str_random(10), 20 | ]; 21 | }); 22 | 23 | $factory->define(PhpSoft\Users\Models\RoutePermission::class, function (Faker\Generator $faker) { 24 | return [ 25 | 'route' => $faker->name, 26 | 'permissions' => '', 27 | 'roles' => '', 28 | ]; 29 | }); 30 | 31 | $factory->define(PhpSoft\Users\Models\Permission::class, function (Faker\Generator $faker) { 32 | return [ 33 | 'name' => $faker->name, 34 | 'display_name' => '', 35 | 'description' => '', 36 | ]; 37 | }); 38 | 39 | $factory->define(PhpSoft\Users\Models\Role::class, function (Faker\Generator $faker) { 40 | return [ 41 | 'name' => $faker->name, 42 | 'display_name' => '', 43 | 'description' => '', 44 | ]; 45 | }); 46 | -------------------------------------------------------------------------------- /database/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/database/migrations/.gitkeep -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->string('name'); 18 | $table->string('email')->unique(); 19 | $table->string('password', 60); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::drop('users'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 17 | $table->string('token')->index(); 18 | $table->timestamp('created_at'); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::drop('password_resets'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /database/seeds/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/database/seeds/.gitkeep -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(UserTableSeeder::class); 18 | 19 | Model::reguard(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var elixir = require('laravel-elixir'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Elixir Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Elixir provides a clean, fluent API for defining some basic Gulp tasks 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for our application, as well as publishing vendor resources. 11 | | 12 | */ 13 | 14 | elixir(function(mix) { 15 | mix.sass('app.scss'); 16 | }); 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "devDependencies": { 4 | "gulp": "^3.8.8" 5 | }, 6 | "dependencies": { 7 | "laravel-elixir": "^2.0.0", 8 | "bootstrap-sass": "^3.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/Users/Commands/MigrationCommand.php: -------------------------------------------------------------------------------- 1 | createMigration(); 34 | $this->info("Run 'php artisan migrate' to finish migration."); 35 | } 36 | 37 | /** 38 | * Create the migration. 39 | * 40 | * @param string $name 41 | * 42 | * @return bool 43 | */ 44 | protected function createMigration() 45 | { 46 | $files = scandir(__DIR__ . '/migrations'); 47 | foreach ($files as $file) { 48 | if ($file == '.' || $file == '..' || file_exists(base_path('/database/migrations') . '/' . $file)) { 49 | continue; 50 | } 51 | if (copy(__DIR__ . '/migrations/' . $file, base_path('/database/migrations') . '/' . $file)) { 52 | $this->line("Created Migration: $file"); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/Users/Commands/migrations/2015_07_25_145818_entrust_setup_tables.php: -------------------------------------------------------------------------------- 1 | increments('id'); 23 | $table->string('name')->unique(); 24 | $table->string('display_name')->nullable(); 25 | $table->string('description')->nullable(); 26 | $table->timestamps(); 27 | }); 28 | 29 | // Create table for associating roles to users (Many-to-Many) 30 | Schema::create('role_user', function (Blueprint $table) { 31 | $table->integer('user_id')->unsigned(); 32 | $table->integer('role_id')->unsigned(); 33 | 34 | $table->foreign('user_id')->references('id')->on('users') 35 | ->onUpdate('cascade')->onDelete('cascade'); 36 | $table->foreign('role_id')->references('id')->on('roles') 37 | ->onUpdate('cascade')->onDelete('cascade'); 38 | 39 | $table->primary(['user_id', 'role_id']); 40 | }); 41 | 42 | // Create table for storing permissions 43 | Schema::create('permissions', function (Blueprint $table) { 44 | $table->increments('id'); 45 | $table->string('name')->unique(); 46 | $table->string('display_name')->nullable(); 47 | $table->string('description')->nullable(); 48 | $table->timestamps(); 49 | }); 50 | 51 | // Create table for associating permissions to roles (Many-to-Many) 52 | Schema::create('permission_role', function (Blueprint $table) { 53 | $table->integer('permission_id')->unsigned(); 54 | $table->integer('role_id')->unsigned(); 55 | 56 | $table->foreign('permission_id')->references('id')->on('permissions') 57 | ->onUpdate('cascade')->onDelete('cascade'); 58 | $table->foreign('role_id')->references('id')->on('roles') 59 | ->onUpdate('cascade')->onDelete('cascade'); 60 | 61 | $table->primary(['permission_id', 'role_id']); 62 | }); 63 | } 64 | 65 | /** 66 | * Reverse the migrations. 67 | * 68 | * @return void 69 | */ 70 | public function down() 71 | { 72 | Schema::drop('permission_role'); 73 | Schema::drop('permissions'); 74 | Schema::drop('role_user'); 75 | Schema::drop('roles'); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /packages/Users/Commands/migrations/2015_08_20_084811_users_add_profiles_field.php: -------------------------------------------------------------------------------- 1 | string('username', 30)->nullable(); 22 | $table->string('location', 100)->nullable(); 23 | $table->string('country', 100)->nullable(); 24 | $table->string('biography', 255)->nullable(); 25 | $table->string('occupation', 255)->nullable(); 26 | $table->string('website', 255)->nullable(); 27 | $table->string('image', 255)->nullable(); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | // Schema::table('users', function ($table) { 39 | // $table->dropColumn(['username', 'location','country','biography','occupation','website','image']); 40 | // }); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/Users/Commands/migrations/2015_08_30_031807_users_create_table_route_permission.php: -------------------------------------------------------------------------------- 1 | increments('id'); 22 | $table->string('route')->unique(); 23 | $table->string('permissions')->nullable(); 24 | $table->string('roles')->nullable(); 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::drop('route_permission'); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /packages/Users/Commands/migrations/2015_09_01_075306_users_add_status_field.php: -------------------------------------------------------------------------------- 1 | integer('status')->default(0); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/Users/Commands/migrations/2015_09_04_021739_users_add_birthday_gender_field.php: -------------------------------------------------------------------------------- 1 | date('birthday')->nullable(); 22 | $table->tinyInteger('gender')->nullable(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/Users/Commands/migrations/2015_12_11_072547_users_add_soft_delete_field.php: -------------------------------------------------------------------------------- 1 | softDeletes(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | // 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/Users/Contracts/Validator.php: -------------------------------------------------------------------------------- 1 | json(arrayView('phpsoft.users::errors/authenticate', [ 30 | 'error' => 'Invalid Credentials.' 31 | ]), 401); 32 | } 33 | } catch (JWTException $e) { 34 | // something went wrong whilst attempting to encode the token 35 | return response()->json(arrayView('phpsoft.users::errors/authenticate', [ 36 | 'error' => 'Could not create token.' 37 | ]), 500); 38 | } 39 | 40 | // all good so return the token 41 | return response()->json(arrayView('phpsoft.users::tokens/show', compact('token'))); 42 | } 43 | 44 | /** 45 | * Logout action 46 | * 47 | * @return Response 48 | */ 49 | public function logout() 50 | { 51 | if (!$this->checkAuth()) { 52 | return response()->json(null, 401); 53 | } 54 | 55 | Auth::logout(); 56 | JWTAuth::invalidate(JWTAuth::getToken()); 57 | 58 | return response()->json(null, 204); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/Users/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | can($permission) || Auth::user()->hasRole('admin'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/Users/Controllers/PasswordController.php: -------------------------------------------------------------------------------- 1 | Auth::user()->id, 'password' => $value]); 28 | 29 | if (!$checkOldPassword) { 30 | return false; 31 | } 32 | 33 | return true; 34 | 35 | }, 'The old password is incorrect.'); 36 | } 37 | 38 | /** 39 | * Forgot password 40 | * 41 | * @param Request $request 42 | * @return json 43 | */ 44 | public function forgot(Request $request) 45 | { 46 | $validator = Validator::make($request->only('email'), [ 47 | 'email' => 'required|email', 48 | ]); 49 | 50 | if ($validator->fails()) { 51 | return response()->json($validator->errors(), 400); 52 | } 53 | 54 | $response = Password::sendResetLink($request->only('email'), function (Message $message) { 55 | 56 | $message->subject($this->getEmailSubject()); 57 | }); 58 | 59 | if ($response == Password::INVALID_USER) { 60 | return response()->json('User is invalid.', 400); 61 | } 62 | 63 | return response()->json(null, 200); 64 | } 65 | 66 | /** 67 | * Reset password 68 | * 69 | * @param Request $request 70 | * @return json 71 | */ 72 | public function reset(Request $request) 73 | { 74 | $validator = Validator::make($request->all(), [ 75 | 'token' => 'required', 76 | 'email' => 'required|email', 77 | 'password' => 'required|confirmed|min:6', 78 | ]); 79 | 80 | if ($validator->fails()) { 81 | return response()->json($validator->errors(), 400); 82 | } 83 | 84 | $credentials = $request->only('email', 'password', 'password_confirmation', 'token'); 85 | 86 | $response = Password::reset($credentials, function ($user, $password) { 87 | 88 | $this->resetPassword($user, $password); // @codeCoverageIgnore 89 | }); 90 | 91 | switch ($response) { 92 | case Password::PASSWORD_RESET: 93 | return response()->json(null, 200); 94 | 95 | default: 96 | return response()->json(null, 400); 97 | } 98 | } 99 | 100 | /** 101 | * Change password 102 | * 103 | * @param Request $request 104 | * @return Response 105 | */ 106 | public function change(Request $request) 107 | { 108 | // register validate 109 | $this->registerValidators(); 110 | 111 | if (!$this->checkAuth()) { 112 | return response()->json(null, 401); 113 | } 114 | 115 | $validator = Validator::make($request->all(), [ 116 | 'old_password' => 'required|min:6|oldPassword', 117 | 'password' => 'required|confirmed|min:6', 118 | ]); 119 | 120 | if ($validator->fails()) { 121 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 122 | 'errors' => $validator->errors() 123 | ]), 400); 124 | } 125 | 126 | $user = Auth::user(); 127 | 128 | $change = $user->update(['password' => $request->password]); 129 | 130 | if (!$change) { 131 | return response()->json(null, 500); // @codeCoverageIgnore 132 | } 133 | 134 | return response()->json(null, 204); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /packages/Users/Controllers/PermissionController.php: -------------------------------------------------------------------------------- 1 | all(), [ 20 | 'name' => 'required|string|max:255|unique:permissions', 21 | 'display_name' => 'string|max:255', 22 | 'description' => 'max:1000' 23 | ]); 24 | 25 | if ($validator->fails()) { 26 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 27 | 'errors' => $validator->errors() 28 | ]), 400); 29 | } 30 | 31 | $permission = Permission::create($request->all()); 32 | 33 | return response()->json(arrayView('phpsoft.users::permission/read', [ 34 | 'permission' => $permission 35 | ]), 201); 36 | } 37 | 38 | /** 39 | * Update permission action 40 | * @param Request $request 41 | * @return Response 42 | */ 43 | public function update(Request $request, $id = null) 44 | { 45 | // validate data 46 | $validator = Validator::make($request->all(), [ 47 | 'name' => 'sometimes|required|string|max:255|unique:permissions,name,'.$id, 48 | 'display_name' => 'string|max:255', 49 | 'description' => 'max:1000' 50 | ]); 51 | 52 | if ($validator->fails()) { 53 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 54 | 'errors' => $validator->errors() 55 | ]), 400); 56 | } 57 | 58 | // check permission 59 | $permission = Permission::find($id); 60 | 61 | if (!$permission) { 62 | return response()->json(null, 404); 63 | } 64 | 65 | // update permission 66 | $updatePermission = $permission->update($request->all()); 67 | 68 | if (!$updatePermission) { 69 | return response()->json(null, 500); // @codeCoverageIgnore 70 | } 71 | 72 | return response()->json(arrayView('phpsoft.users::permission/read', [ 73 | 'permission' => $permission 74 | ]), 200); 75 | } 76 | 77 | /** 78 | * Delete permission 79 | * @param int $id 80 | * @return Response 81 | */ 82 | public function destroy($id) 83 | { 84 | // get permission by id 85 | $permission = Permission::find($id); 86 | 87 | if (!$permission) { 88 | return response()->json(null, 404); 89 | } 90 | 91 | // delete permission 92 | $deletePermission = $permission->delete(); 93 | 94 | if (!$deletePermission) { 95 | return response()->json(null, 500); // @codeCoverageIgnore 96 | } 97 | 98 | return response()->json(null, 204); 99 | } 100 | 101 | /** 102 | * View permission 103 | * @param int $id 104 | * @return Response 105 | */ 106 | public function show($id) 107 | { 108 | // get permission by id 109 | $permission = Permission::find($id); 110 | 111 | if (!$permission) { 112 | return response()->json(null, 404); 113 | } 114 | 115 | return response()->json(arrayView('phpsoft.users::permission/read', [ 116 | 'permission' => $permission 117 | ]), 200); 118 | } 119 | 120 | /** 121 | * index 122 | * @return json 123 | */ 124 | public function index(Request $request) 125 | { 126 | $permissions = Permission::browse([ 127 | 'order' => [ Input::get('sort', 'id') => Input::get('direction', 'desc') ], 128 | 'limit' => ($limit = (int)Input::get('limit', 25)), 129 | 'offset' => (Input::get('page', 1) - 1) * $limit, 130 | 'filters' => $request->all() 131 | ]); 132 | 133 | return response()->json(arrayView('phpsoft.users::permission/browse', [ 134 | 'permissions' => $permissions, 135 | ]), 200); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /packages/Users/Controllers/RoleController.php: -------------------------------------------------------------------------------- 1 | all(), [ 20 | 'name' => 'required|string|max:255|unique:roles', 21 | 'display_name' => 'string|max:255', 22 | 'description' => 'max:1000' 23 | ]); 24 | 25 | if ($validator->fails()) { 26 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 27 | 'errors' => $validator->errors() 28 | ]), 400); 29 | } 30 | 31 | $role = Role::create($request->all()); 32 | 33 | return response()->json(arrayView('phpsoft.users::role/read', [ 34 | 'role' => $role 35 | ]), 201); 36 | } 37 | 38 | /** 39 | * Update role action 40 | * @param Request $request 41 | * @return Response 42 | */ 43 | public function update(Request $request, $id = null) 44 | { 45 | // validate data 46 | $validator = Validator::make($request->all(), [ 47 | 'name' => 'sometimes|required|string|max:255|unique:roles,name,'.$id, 48 | 'display_name' => 'string|max:255', 49 | 'description' => 'max:1000' 50 | ]); 51 | 52 | if ($validator->fails()) { 53 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 54 | 'errors' => $validator->errors() 55 | ]), 400); 56 | } 57 | 58 | // check role 59 | $role = Role::find($id); 60 | 61 | if (!$role) { 62 | return response()->json(null, 404); 63 | } 64 | 65 | // update role 66 | $updateRole = $role->update($request->all()); 67 | 68 | if (!$updateRole) { 69 | return response()->json(null, 500); // @codeCoverageIgnore 70 | } 71 | 72 | return response()->json(arrayView('phpsoft.users::role/read', [ 73 | 'role' => $role 74 | ]), 200); 75 | } 76 | 77 | /** 78 | * Delete role 79 | * @param int $id 80 | * @return Response 81 | */ 82 | public function destroy($id) 83 | { 84 | // get role by id 85 | $role = Role::find($id); 86 | 87 | if (!$role) { 88 | return response()->json(null, 404); 89 | } 90 | 91 | // delete role 92 | $deleteRole = $role->delete(); 93 | 94 | if (!$deleteRole) { 95 | return response()->json(null, 500); // @codeCoverageIgnore 96 | } 97 | 98 | return response()->json(null, 204); 99 | } 100 | 101 | /** 102 | * View role 103 | * @param int $id 104 | * @return Response 105 | */ 106 | public function show($id) 107 | { 108 | // get role by id 109 | $role = Role::find($id); 110 | 111 | if (!$role) { 112 | return response()->json(null, 404); 113 | } 114 | 115 | return response()->json(arrayView('phpsoft.users::role/read', [ 116 | 'role' => $role 117 | ]), 200); 118 | } 119 | 120 | /** 121 | * index 122 | * @return json 123 | */ 124 | public function index(Request $request) 125 | { 126 | $roles = Role::browse([ 127 | 'order' => [ Input::get('sort', 'id') => Input::get('direction', 'desc') ], 128 | 'limit' => ($limit = (int)Input::get('limit', 25)), 129 | 'offset' => (Input::get('page', 1) - 1) * $limit, 130 | 'filters' => $request->all() 131 | ]); 132 | 133 | return response()->json(arrayView('phpsoft.users::role/browse', [ 134 | 'roles' => $roles, 135 | ]), 200); 136 | } 137 | 138 | /** 139 | * index 140 | * @param int $id 141 | * @return json 142 | */ 143 | public function indexByUser($id) 144 | { 145 | $user = \App\User::find($id); 146 | 147 | if (!$user) { 148 | return response()->json(null, 404); 149 | } 150 | 151 | $roles = Role::browseByUser([ 152 | 'order' => [ Input::get('sort', 'name') => Input::get('direction', 'asc') ], 153 | 'limit' => ($limit = (int)Input::get('limit', 25)), 154 | 'offset' => (Input::get('page', 1) - 1) * $limit, 155 | 'user' => $user 156 | ]); 157 | 158 | return response()->json(arrayView('phpsoft.users::role/browse', [ 159 | 'roles' => $roles, 160 | ]), 200); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /packages/Users/Controllers/RoutePermissionController.php: -------------------------------------------------------------------------------- 1 | count()) { 33 | $flag = false; 34 | break; 35 | } 36 | } 37 | } else { 38 | $flag = false; 39 | } 40 | 41 | return $flag; 42 | 43 | }, 'Roles or permissions are invalid.'); 44 | } 45 | 46 | /** 47 | * Create route permission action 48 | * 49 | * @param Request $request 50 | * @return Response 51 | */ 52 | public function store(Request $request) 53 | { 54 | // validate 55 | $this->registerValidators(); 56 | 57 | $validator = Validator::make($request->all(), [ 58 | 'route' => 'required|max:255|string|unique:route_permission,route', 59 | 'permissions' => 'required|max:255|array|rolePermission', 60 | 'roles' => 'required|max:255|array|rolePermission' 61 | ]); 62 | 63 | if ($validator->fails()) { 64 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 65 | 'errors' => $validator->errors() 66 | ]), 400); 67 | } 68 | 69 | // check current user is admin 70 | if (!(Auth::user() && Auth::user()->hasRole('admin'))) { 71 | return response()->json(null, 403); 72 | } 73 | 74 | // add permissions and roles for the route 75 | $routePermission = RoutePermission::setRoutePermissionsRoles( 76 | $request['route'], 77 | $request['permissions'], 78 | $request['roles'] 79 | ); 80 | 81 | return response()->json(arrayView('phpsoft.users::routePermission/read', [ 82 | 'routePermission' => $routePermission 83 | ]), 201); 84 | } 85 | 86 | /** 87 | * Update permissions and roles for a route 88 | * 89 | * @param Request $request 90 | * @return Response 91 | */ 92 | public function update($id, Request $request) 93 | { 94 | $routePermission = RoutePermission::find($id); 95 | 96 | if ($routePermission == null) { 97 | return response()->json(null, 404); 98 | } 99 | 100 | // validate 101 | $this->registerValidators(); 102 | 103 | $validator = Validator::make($request->all(), [ 104 | 'route' => 'sometimes|required|string|max:255|unique:route_permission,route,'.$id, 105 | 'permissions' => 'sometimes|required|array|max:255|rolePermission', 106 | 'roles' => 'sometimes|required|array|max:255|rolePermission' 107 | ]); 108 | 109 | if ($validator->fails()) { 110 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 111 | 'errors' => $validator->errors() 112 | ]), 400); 113 | } 114 | 115 | $request['permissions'] = isset($request['permissions']) ? 116 | json_encode($request['permissions']) : $routePermission->permissions; 117 | $request['roles'] = isset($request['roles']) ? 118 | json_encode($request['roles']) : $routePermission->roles; 119 | 120 | // check current user is admin 121 | if (!(Auth::user() && Auth::user()->hasRole('admin'))) { 122 | return response()->json(null, 403); 123 | } 124 | 125 | // update permissions and roles for the route 126 | $routePermission = $routePermission->update($request->all()); 127 | 128 | return response()->json(arrayView('phpsoft.users::routePermission/read', [ 129 | 'routePermission' => $routePermission 130 | ]), 200); 131 | } 132 | 133 | /** 134 | * Delete route permission 135 | * @param int $id 136 | * @return Response 137 | */ 138 | public function destroy($id) 139 | { 140 | // get route permission by id 141 | $routePermission = RoutePermission::find($id); 142 | 143 | if (!$routePermission) { 144 | return response()->json(null, 404); 145 | } 146 | 147 | // check current user is admin 148 | if (!(Auth::user() && Auth::user()->hasRole('admin'))) { 149 | return response()->json(null, 403); 150 | } 151 | 152 | // delete route permission 153 | $deleteRoutePermission = $routePermission->delete(); 154 | 155 | if (!$deleteRoutePermission) { 156 | return response()->json(null, 500); // @codeCoverageIgnore 157 | } 158 | 159 | return response()->json(null, 204); 160 | } 161 | 162 | /** 163 | * View route permission 164 | * @param int $id 165 | * @return Response 166 | */ 167 | public function show($id) 168 | { 169 | // get permissions and roles of a route by id 170 | $routePermission = RoutePermission::find($id); 171 | 172 | if (!$routePermission) { 173 | return response()->json(null, 404); 174 | } 175 | 176 | return response()->json(arrayView('phpsoft.users::routePermission/read', [ 177 | 'routePermission' => $routePermission 178 | ]), 200); 179 | } 180 | 181 | /** 182 | * index 183 | * @return json 184 | */ 185 | public function index(Request $request) 186 | { 187 | $routePermissions = RoutePermission::browse([ 188 | 'order' => [ Input::get('sort', 'id') => Input::get('direction', 'desc') ], 189 | 'limit' => ($limit = (int)Input::get('limit', 25)), 190 | 'offset' => (Input::get('page', 1) - 1) * $limit, 191 | 'filters' => $request->all() 192 | ]); 193 | 194 | return response()->json(arrayView('phpsoft.users::routePermission/browse', [ 195 | 'routePermissions' => $routePermissions, 196 | ]), 200); 197 | } 198 | 199 | /** 200 | * List all routes in app 201 | * 202 | * @param 203 | * @return Response 204 | */ 205 | public function getAllRoutes() 206 | { 207 | $routes = Route::getRoutes(); 208 | $results = []; 209 | 210 | if ($routes != null) { 211 | foreach ($routes as $route) { 212 | $route = array( 213 | 'method' => $route->getMethods(), 214 | 'uri' => $route->getPath() 215 | ); 216 | $results[] = (object)$route; 217 | } 218 | } 219 | 220 | return response()->json(arrayView('phpsoft.users::route/browse', [ 221 | 'routes' => $results, 222 | ]), 200); 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /packages/Users/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | response = $response; 41 | $this->events = $events; 42 | $this->auth = $auth; 43 | } 44 | 45 | /** 46 | * Handle an incoming request. 47 | * 48 | * @param \Illuminate\Http\Request $request 49 | * @param \Closure $next 50 | * @return mixed 51 | */ 52 | public function handle($request, Closure $next) 53 | { 54 | if (!$token = $this->auth->setRequest($request)->getToken()) { 55 | return $this->respond('tymon.jwt.absent', 'Token is not provided.', 400); 56 | } 57 | 58 | try { 59 | $user = $this->auth->authenticate($token); 60 | } catch (TokenExpiredException $e) { 61 | return $this->respond('tymon.jwt.expired', 'Token has expired.', $e->getStatusCode(), [$e]); 62 | } catch (JWTException $e) { 63 | return $this->respond('tymon.jwt.invalid', 'Token is invalid.', $e->getStatusCode(), [$e]); 64 | } 65 | 66 | if (!$user) { 67 | return $this->respond('tymon.jwt.user_not_found', 'User not found.', 404); 68 | } 69 | 70 | $this->events->fire('tymon.jwt.valid', $user); 71 | 72 | return $next($request); 73 | } 74 | 75 | /** 76 | * Fire event and return the response 77 | * 78 | * @param string $event 79 | * @param string $error 80 | * @param integer $status 81 | * @param array $payload 82 | * @return mixed 83 | */ 84 | protected function respond($event, $error, $status, $payload = []) 85 | { 86 | $response = $this->events->fire($event, $payload, true); 87 | 88 | return $response ?: $this->response->json(arrayView('phpsoft.users::errors/authenticate', [ 89 | 'error' => $error 90 | ]), $status); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /packages/Users/Middleware/Permission.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 26 | } 27 | 28 | /** 29 | * Handle an incoming request. 30 | * 31 | * @param \Illuminate\Http\Request $request 32 | * @param \Closure $next 33 | * @return mixed 34 | */ 35 | public function handle($request, Closure $next, $permission = 'manage', $role = 'admin') 36 | { 37 | if (($status = $this->checkPermission($permission, $role)) !== true) { 38 | return response()->json(null, $status); 39 | } 40 | 41 | return $next($request); 42 | } 43 | 44 | /** 45 | * Check permission 46 | * 47 | * @return boolean 48 | */ 49 | protected function checkPermission($permission = 'manage', $role = 'admin') 50 | { 51 | if ($this->auth->guest()) { 52 | return 401; 53 | } 54 | 55 | if ($this->auth->user()->can($permission) || $this->auth->user()->hasRole($role)) { 56 | return true; 57 | } 58 | 59 | return 403; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/Users/Middleware/RoutePermission.php: -------------------------------------------------------------------------------- 1 | auth = $auth; 38 | $this->router = $router; 39 | } 40 | 41 | /** 42 | * Handle an incoming request. 43 | * 44 | * @param \Illuminate\Http\Request $request 45 | * @param \Closure $next 46 | * @return mixed 47 | */ 48 | public function handle($request, Closure $next) 49 | { 50 | $route = $this->router->current()->methods()[0] . ' /' . $this->router->current()->uri(); 51 | 52 | $isPermissionAllRoutes = RoutePermissionModel::getRoutePermissionsRoles('*'); 53 | if ($isPermissionAllRoutes) { 54 | if (($user = $this->user($request)) === 401) { 55 | return response()->json(null, 401); 56 | } 57 | 58 | $hasRole = $user->hasRole($isPermissionAllRoutes->roles, false); 59 | $hasPerms = $user->can($isPermissionAllRoutes->permissions, false); 60 | 61 | $hasRolePerm = $hasRole || $hasPerms || (is_array($isPermissionAllRoutes->roles) && in_array('@', $isPermissionAllRoutes->roles)); 62 | 63 | if (!$hasRolePerm) { 64 | return response()->json(null, 403); 65 | } 66 | } 67 | 68 | $routePermission = RoutePermissionModel::getRoutePermissionsRoles($route); 69 | if ($routePermission) { 70 | if (($user = $this->user($request)) === 401) { 71 | return response()->json(null, 401); 72 | } 73 | 74 | $hasRole = $user->hasRole($routePermission->roles, false); 75 | $hasPerms = $user->can($routePermission->permissions, false); 76 | 77 | $hasRolePerm = $hasRole || $hasPerms || (is_array($routePermission->roles) && in_array('@', $routePermission->roles)); 78 | 79 | if (!$hasRolePerm) { 80 | return response()->json(null, 403); 81 | } 82 | } 83 | 84 | return $next($request); 85 | } 86 | 87 | /** 88 | * Get the currently authenticated user or null. 89 | * 90 | * @return Illuminate\Auth\UserInterface|null 91 | */ 92 | protected function user($request) 93 | { 94 | if (!$token = $this->auth->setRequest($request)->getToken()) { 95 | return 401; 96 | } 97 | 98 | try { 99 | $user = $this->auth->authenticate($token); 100 | } catch (JWTException $e) { 101 | return 401; 102 | } 103 | 104 | if (!$user) { 105 | return 401; 106 | } 107 | 108 | return $user; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /packages/Users/Middleware/Validate.php: -------------------------------------------------------------------------------- 1 | all(), $classValidate::rules()); 14 | 15 | if ($validator->fails()) { 16 | return response()->json(arrayView('phpsoft.users::errors/validation', [ 17 | 'errors' => $validator->errors() 18 | ]), 400); 19 | } 20 | 21 | return $next($request); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/Users/Models/Permission.php: -------------------------------------------------------------------------------- 1 | fresh(); 25 | } 26 | 27 | /** 28 | * Update the model in the database. 29 | * 30 | * @param array $attributes 31 | * @return bool|int 32 | */ 33 | public function update(array $attributes = []) 34 | { 35 | if (!parent::update($attributes)) { 36 | throw new Exception('Cannot update permission.'); // @codeCoverageIgnore 37 | } 38 | 39 | return $this->fresh(); 40 | } 41 | 42 | /** 43 | * Browse items 44 | * 45 | * @param array $options 46 | * @return array 47 | */ 48 | public static function browse($options = []) 49 | { 50 | $find = new Permission(); 51 | $fillable = $find->fillable; 52 | 53 | $total = $find->count(); 54 | 55 | if (!empty($options['order'])) { 56 | foreach ($options['order'] as $field => $direction) { 57 | if (in_array($field, $fillable)) { 58 | $find = $find->orderBy($field, $direction); 59 | } 60 | $find = $find->orderBy('id', 'DESC'); 61 | } 62 | } 63 | 64 | if (!empty($options['offset'])) { 65 | $find = $find->skip($options['offset']); 66 | } 67 | 68 | if (!empty($options['limit'])) { 69 | $find = $find->take($options['limit']); 70 | } 71 | 72 | return [ 73 | 'total' => $total, 74 | 'offset' => empty($options['offset']) ? 0 : $options['offset'], 75 | 'limit' => empty($options['limit']) ? 0 : $options['limit'], 76 | 'data' => $find->get(), 77 | ]; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /packages/Users/Models/Role.php: -------------------------------------------------------------------------------- 1 | fresh(); 25 | } 26 | 27 | /** 28 | * Update the model in the database. 29 | * 30 | * @param array $attributes 31 | * @return bool|int 32 | */ 33 | public function update(array $attributes = []) 34 | { 35 | if (!parent::update($attributes)) { 36 | throw new Exception('Cannot update role.'); // @codeCoverageIgnore 37 | } 38 | 39 | return $this->fresh(); 40 | } 41 | 42 | /** 43 | * Browse items 44 | * 45 | * @param array $options 46 | * @return array 47 | */ 48 | public static function browse($options = []) 49 | { 50 | $find = new Role(); 51 | $fillable = $find->fillable; 52 | 53 | $total = $find->count(); 54 | 55 | if (!empty($options['order'])) { 56 | foreach ($options['order'] as $field => $direction) { 57 | if (in_array($field, $fillable)) { 58 | $find = $find->orderBy($field, $direction); 59 | } 60 | $find = $find->orderBy('id', 'DESC'); 61 | } 62 | } 63 | 64 | if (!empty($options['offset'])) { 65 | $find = $find->skip($options['offset']); 66 | } 67 | 68 | if (!empty($options['limit'])) { 69 | $find = $find->take($options['limit']); 70 | } 71 | 72 | return [ 73 | 'total' => $total, 74 | 'offset' => empty($options['offset']) ? 0 : $options['offset'], 75 | 'limit' => empty($options['limit']) ? 0 : $options['limit'], 76 | 'data' => $find->get(), 77 | ]; 78 | } 79 | 80 | /** 81 | * get all role of user 82 | * @return role 83 | */ 84 | public static function browseByUser($options = []) 85 | { 86 | $find = $options['user']->roles(); 87 | $total = $find->count(); 88 | 89 | if (!empty($options['order'])) { 90 | foreach ($options['order'] as $field => $direction) { 91 | 92 | $find = $find->orderBy($field, $direction); 93 | } 94 | } 95 | 96 | if (!empty($options['offset'])) { 97 | $find = $find->skip($options['offset']); 98 | } 99 | 100 | if (!empty($options['limit'])) { 101 | $find = $find->take($options['limit']); 102 | } 103 | 104 | return [ 105 | 'total' => $total, 106 | 'offset' => empty($options['offset']) ? 0 : $options['offset'], 107 | 'limit' => empty($options['limit']) ? 0 : $options['limit'], 108 | 'data' => $find->get(), 109 | ]; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /packages/Users/Models/RoutePermission.php: -------------------------------------------------------------------------------- 1 | $route]); 55 | 56 | if (count($permissions)) { 57 | $routePermission->permissions = json_encode($permissions); 58 | } 59 | if (count($roles)) { 60 | $routePermission->roles = json_encode($roles); 61 | } 62 | 63 | $routePermission->save(); 64 | 65 | return $routePermission; 66 | } 67 | 68 | /** 69 | * Get permissions and roles of an route 70 | * 71 | * @param string 72 | * @return RoutePermission 73 | */ 74 | public static function getRoutePermissionsRoles($route) 75 | { 76 | $routePermission = parent::where('route', $route)->first(); 77 | if (empty($routePermission)) { 78 | return null; 79 | } 80 | $routePermission->permissions = json_decode($routePermission->permissions); 81 | $routePermission->roles = json_decode($routePermission->roles); 82 | return $routePermission; 83 | } 84 | 85 | /** 86 | * Update permissions and roles of a route. 87 | * 88 | * @param array $attributes 89 | * @return bool|int 90 | */ 91 | public function update(array $attributes = []) 92 | { 93 | if (!parent::update($attributes)) { 94 | throw new Exception('Cannot update category.'); // @codeCoverageIgnore 95 | } 96 | 97 | return $this->fresh(); 98 | } 99 | 100 | /** 101 | * List permissions and roles of all route 102 | * 103 | * @param array $options 104 | * @return array 105 | */ 106 | public static function browse($options = []) 107 | { 108 | $find = new RoutePermission(); 109 | $fillable = $find->fillable; 110 | 111 | if (!empty($options['filters'])) { 112 | $inFilters = array_intersect($fillable, array_keys($options['filters'])); 113 | 114 | if (!empty($inFilters)) { 115 | foreach ($inFilters as $key) { 116 | $find = ($options['filters'][$key] == null) ? $find : $find->where($key, 'LIKE', $options['filters'][$key]); 117 | } 118 | } 119 | } 120 | 121 | $total = $find->count(); 122 | 123 | if (!empty($options['order'])) { 124 | foreach ($options['order'] as $field => $direction) { 125 | if (in_array($field, $fillable)) { 126 | $find = $find->orderBy($field, $direction); 127 | } 128 | } 129 | } 130 | 131 | $find = $find->orderBy('id', 'DESC'); 132 | 133 | if (!empty($options['offset'])) { 134 | $find = $find->skip($options['offset']); 135 | } 136 | 137 | if (!empty($options['limit'])) { 138 | $find = $find->take($options['limit']); 139 | } 140 | 141 | return [ 142 | 'total' => $total, 143 | 'offset' => empty($options['offset']) ? 0 : $options['offset'], 144 | 'limit' => empty($options['limit']) ? 0 : $options['limit'], 145 | 'data' => $find->get(), 146 | ]; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /packages/Users/Models/User.php: -------------------------------------------------------------------------------- 1 | save(); 65 | 66 | return $user; 67 | } 68 | 69 | /** 70 | * Update the model in the database. 71 | * 72 | * @param array $attributes 73 | * @return bool|int 74 | */ 75 | public function update(array $attributes = []) 76 | { 77 | if (isset($attributes['password'])) { 78 | $attributes['password'] = bcrypt($attributes['password']); 79 | } 80 | 81 | if (!parent::update($attributes)) { 82 | throw new Exception('Cannot update user.'); // @codeCoverageIgnore 83 | } 84 | if (!parent::update($attributes)) { 85 | throw new Exception('Cannot update user.'); // @codeCoverageIgnore 86 | } 87 | 88 | return $this->fresh(); 89 | } 90 | 91 | 92 | /** 93 | * 94 | * @param array $options 95 | * @return array 96 | */ 97 | public static function browse($options = []) 98 | { 99 | $find = new AppUser(); 100 | $fillable = $find->fillable; 101 | 102 | if (!empty($options['trash'])) { 103 | $find = $find->onlyTrashed(); 104 | } 105 | 106 | if (!empty($options['filters'])) { 107 | $inFilters = array_intersect($fillable, array_keys($options['filters'])); 108 | 109 | foreach ($inFilters as $key) { 110 | $find = ($options['filters'][$key] == null) ? $find : $find->where($key, 'LIKE', $options['filters'][$key]); 111 | } 112 | } 113 | 114 | $total = $find->count(); 115 | 116 | if (!empty($options['order'])) { 117 | foreach ($options['order'] as $field => $direction) { 118 | if (in_array($field, $fillable)) { 119 | $find = $find->orderBy($field, $direction); 120 | } 121 | } 122 | 123 | $find = $find->orderBy('id', 'DESC'); 124 | } 125 | 126 | if (!empty($options['offset'])) { 127 | $find = $find->skip($options['offset']); 128 | } 129 | 130 | if (!empty($options['limit'])) { 131 | $find = $find->take($options['limit']); 132 | } 133 | 134 | if (!empty($options['cursor'])) { 135 | $find = $find->where('id', '<', $options['cursor']); 136 | } 137 | 138 | return [ 139 | 'total' => $total, 140 | 'offset' => empty($options['offset']) ? 0 : $options['offset'], 141 | 'limit' => empty($options['limit']) ? 0 : $options['limit'], 142 | 'data' => $find->get(), 143 | ]; 144 | } 145 | 146 | /** 147 | * set status is block 148 | * 149 | * @param int $status 150 | * @return int 151 | */ 152 | public function block() 153 | { 154 | $this->status = $this->status | User::STATUS_BLOCK; 155 | return $this->save(); 156 | } 157 | 158 | /** 159 | * set status is non block 160 | * 161 | * @param int $status 162 | * @return int 163 | */ 164 | public function unblock() 165 | { 166 | $this->status = $this->status & ~User::STATUS_BLOCK; 167 | return $this->save(); 168 | } 169 | 170 | /** 171 | * check status is block 172 | * 173 | * @param int $status 174 | * @return boolean 175 | */ 176 | public function isBlock() 177 | { 178 | return (User::STATUS_BLOCK)==($this->status & User::STATUS_BLOCK); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /packages/Users/Models/UserTrait.php: -------------------------------------------------------------------------------- 1 | loadViewsFrom(__DIR__ . '/../resources/views', 'phpsoft.users'); 17 | 18 | // Publish views 19 | $this->publishes([ 20 | __DIR__ . '/../resources/views' => base_path('resources/views/vendor/phpsoft.users'), 21 | ]); 22 | 23 | // Publish config files 24 | $this->publishes([ 25 | __DIR__ . '/../config/jwt.php' => config_path('jwt.php'), 26 | __DIR__ . '/../config/entrust.php' => config_path('entrust.php'), 27 | ]); 28 | 29 | // Register commands 30 | $this->commands('phpsoft.users.command.migration'); 31 | 32 | // Publish migration files 33 | $this->publishes([ 34 | __DIR__.'/../Commands/migrations' => base_path('database/migrations'), 35 | ], 'migrations'); 36 | } 37 | 38 | /** 39 | * Register bindings in the container. 40 | * 41 | * @return void 42 | */ 43 | public function register() 44 | { 45 | $this->registerCommands(); 46 | } 47 | 48 | /** 49 | * Register the artisan commands. 50 | * 51 | * @return void 52 | */ 53 | private function registerCommands() 54 | { 55 | $this->app->bindShared('phpsoft.users.command.migration', function () { 56 | return new MigrationCommand(); 57 | }); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/Users/config/entrust.php: -------------------------------------------------------------------------------- 1 | PhpSoft\Users\Models\Role::class, 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Entrust Roles Table 27 | |-------------------------------------------------------------------------- 28 | | 29 | | This is the roles table used by Entrust to save roles to the database. 30 | | 31 | */ 32 | 'roles_table' => 'roles', 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Entrust Permission Model 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the Permission model used by Entrust to create correct relations. 40 | | Update the permission if it is in a different namespace. 41 | | 42 | */ 43 | 'permission' => PhpSoft\Users\Models\Permission::class, 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | Entrust Permissions Table 48 | |-------------------------------------------------------------------------- 49 | | 50 | | This is the permissions table used by Entrust to save permissions to the 51 | | database. 52 | | 53 | */ 54 | 'permissions_table' => 'permissions', 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Entrust permission_role Table 59 | |-------------------------------------------------------------------------- 60 | | 61 | | This is the permission_role table used by Entrust to save relationship 62 | | between permissions and roles to the database. 63 | | 64 | */ 65 | 'permission_role_table' => 'permission_role', 66 | 67 | /* 68 | |-------------------------------------------------------------------------- 69 | | Entrust role_user Table 70 | |-------------------------------------------------------------------------- 71 | | 72 | | This is the role_user table used by Entrust to save assigned roles to the 73 | | database. 74 | | 75 | */ 76 | 'role_user_table' => 'role_user', 77 | 78 | ]; 79 | -------------------------------------------------------------------------------- /packages/Users/config/jwt.php: -------------------------------------------------------------------------------- 1 | env('JWT_SECRET', 'changeme'), 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | JWT time to live 20 | |-------------------------------------------------------------------------- 21 | | 22 | | Specify the length of time (in minutes) that the token will be valid for. 23 | | Defaults to 1 hour 24 | | 25 | */ 26 | 27 | 'ttl' => 60, 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | Refresh time to live 32 | |-------------------------------------------------------------------------- 33 | | 34 | | Specify the length of time (in minutes) that the token can be refreshed 35 | | within. I.E. The user can refresh their token within a 2 week window of 36 | | the original token being created until they must re-authenticate. 37 | | Defaults to 2 weeks 38 | | 39 | */ 40 | 41 | 'refresh_ttl' => 20160, 42 | 43 | /* 44 | |-------------------------------------------------------------------------- 45 | | JWT hashing algorithm 46 | |-------------------------------------------------------------------------- 47 | | 48 | | Specify the hashing algorithm that will be used to sign the token. 49 | | 50 | | See here: https://github.com/namshi/jose/tree/2.2.0/src/Namshi/JOSE/Signer 51 | | for possible values 52 | | 53 | */ 54 | 55 | 'algo' => 'HS256', 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | User Model namespace 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Specify the full namespace to your User model. 63 | | e.g. 'Acme\Entities\User' 64 | | 65 | */ 66 | 67 | 'user' => 'App\User', 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | User identifier 72 | |-------------------------------------------------------------------------- 73 | | 74 | | Specify a unique property of the user that will be added as the 'sub' 75 | | claim of the token payload. 76 | | 77 | */ 78 | 79 | 'identifier' => 'id', 80 | 81 | /* 82 | |-------------------------------------------------------------------------- 83 | | Required Claims 84 | |-------------------------------------------------------------------------- 85 | | 86 | | Specify the required claims that must exist in any token. 87 | | A TokenInvalidException will be thrown if any of these claims are not 88 | | present in the payload. 89 | | 90 | */ 91 | 92 | 'required_claims' => ['iss', 'iat', 'exp', 'nbf', 'sub', 'jti'], 93 | 94 | /* 95 | |-------------------------------------------------------------------------- 96 | | Blacklist Enabled 97 | |-------------------------------------------------------------------------- 98 | | 99 | | In order to invalidate tokens, you must have the the blacklist enabled. 100 | | If you do not want or need this functionality, then set this to false. 101 | | 102 | */ 103 | 104 | 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Providers 109 | |-------------------------------------------------------------------------- 110 | | 111 | | Specify the various providers used throughout the package. 112 | | 113 | */ 114 | 115 | 'providers' => [ 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | User Provider 120 | |-------------------------------------------------------------------------- 121 | | 122 | | Specify the provider that is used to find the user based 123 | | on the subject claim 124 | | 125 | */ 126 | 127 | 'user' => 'Tymon\JWTAuth\Providers\User\EloquentUserAdapter', 128 | 129 | /* 130 | |-------------------------------------------------------------------------- 131 | | JWT Provider 132 | |-------------------------------------------------------------------------- 133 | | 134 | | Specify the provider that is used to create and decode the tokens. 135 | | 136 | */ 137 | 138 | 'jwt' => 'Tymon\JWTAuth\Providers\JWT\NamshiAdapter', 139 | 140 | /* 141 | |-------------------------------------------------------------------------- 142 | | Authentication Provider 143 | |-------------------------------------------------------------------------- 144 | | 145 | | Specify the provider that is used to authenticate users. 146 | | 147 | */ 148 | 149 | 'auth' => function ($app) { 150 | return new Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter($app['auth']); 151 | }, 152 | 153 | /* 154 | |-------------------------------------------------------------------------- 155 | | Storage Provider 156 | |-------------------------------------------------------------------------- 157 | | 158 | | Specify the provider that is used to store tokens in the blacklist 159 | | 160 | */ 161 | 162 | 'storage' => function ($app) { 163 | return new Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter($app['cache']); 164 | } 165 | 166 | ] 167 | 168 | ]; 169 | -------------------------------------------------------------------------------- /packages/Users/database/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/packages/Users/database/.gitkeep -------------------------------------------------------------------------------- /packages/Users/database/seeds/UserModuleSeeder.php: -------------------------------------------------------------------------------- 1 | create([ 19 | 'name' => 'Administrator', 20 | 'email' => 'admin@example.com', 21 | 'password' => bcrypt('123456'), 22 | 'username' => 'admin', 23 | 'location' => 'Da Nang', 24 | 'country' => 'Viet Nam', 25 | 'biography' => 'Dev', 26 | 'occupation'=> 'Dev', 27 | 'website' => 'greenglobal.vn', 28 | 'image' => 'avatar.jpg', 29 | ]); 30 | 31 | // create default roles 32 | $admin = new Role; 33 | $admin->name = 'admin'; 34 | $admin->display_name = 'Administrator'; 35 | $admin->description = 'User is allowed to manage all system.'; 36 | $admin->save(); 37 | 38 | // attach roles 39 | $root->attachRole($admin); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /packages/Users/resources/views/errors/authenticate.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('status', 'error'); 5 | $this->set('type', 'authenticate'); 6 | $this->set('message', $error); 7 | -------------------------------------------------------------------------------- /packages/Users/resources/views/errors/validation.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('status', 'error'); 5 | $this->set('type', 'validation'); 6 | $this->set('errors', $errors); 7 | $this->set('message', is_array($errors)? $errors[0] : $errors->first()); 8 | -------------------------------------------------------------------------------- /packages/Users/resources/views/helpers/links.helper.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'href' => $hrefSelf, 16 | 'type' => 'application/json; version=1.0', 17 | ] 18 | ]; 19 | 20 | if (count($items)) { 21 | $last = $items[count($items) - 1]; 22 | 23 | $queries = Input::all(); 24 | $queries = array_merge($queries, [ 25 | 'cursor' => $last->id, 26 | ]); 27 | $hrefNext = url(Request::url()) . '?' . http_build_query($queries); 28 | 29 | $links['next'] = [ 30 | 'href' => $hrefNext, 31 | 'type' => 'application/json; version=1.0', 32 | ]; 33 | } 34 | 35 | return $links; 36 | }; 37 | -------------------------------------------------------------------------------- /packages/Users/resources/views/partials/permission.array.php: -------------------------------------------------------------------------------- 1 | extract($permission, [ 4 | 'id', 5 | 'name', 6 | 'display_name', 7 | 'description', 8 | ]); 9 | -------------------------------------------------------------------------------- /packages/Users/resources/views/partials/role.array.php: -------------------------------------------------------------------------------- 1 | extract($role, [ 4 | 'id', 5 | 'name', 6 | 'display_name', 7 | 'description', 8 | ]); 9 | -------------------------------------------------------------------------------- /packages/Users/resources/views/partials/routePermission.array.php: -------------------------------------------------------------------------------- 1 | extract($routePermission, [ 4 | 'id', 5 | 'route', 6 | ]); 7 | 8 | $this->set('roles', function($section) use ($routePermission) { 9 | $section->set(json_decode($routePermission->roles)); 10 | }); 11 | 12 | $this->set('permissions', function($section) use ($routePermission) { 13 | $section->set(json_decode($routePermission->permissions)); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/Users/resources/views/partials/user.array.php: -------------------------------------------------------------------------------- 1 | extract($user, [ 4 | 'id', 5 | 'name', 6 | 'username', 7 | 'location', 8 | 'country', 9 | 'biography', 10 | 'occupation', 11 | 'website', 12 | 'image', 13 | 'birthday', 14 | 'gender', 15 | ]); 16 | $this->set('isBlock', $user->isBlock()); 17 | -------------------------------------------------------------------------------- /packages/Users/resources/views/permission/browse.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 3 | $this->set('links', $this->helper('phpsoft.users::helpers.links', $permissions['data'])); 4 | $this->set('meta', function ($section) use ($permissions) { 5 | 6 | $section->set('offset', $permissions['offset']); 7 | $section->set('limit', $permissions['limit']); 8 | $section->set('total', $permissions['total']); 9 | }); 10 | 11 | $this->set('entities', $this->each($permissions['data'], function ($section, $permission) { 12 | 13 | $section->set($section->partial('phpsoft.users::partials/permission', [ 'permission' => $permission ])); 14 | })); 15 | 16 | $this->set('linked', '{}'); 17 | -------------------------------------------------------------------------------- /packages/Users/resources/views/permission/read.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('links', '{}'); 5 | $this->set('meta', '{}'); 6 | 7 | $this->set('entities', $this->each([ $permission ], function ($section, $permission) { 8 | 9 | $section->set($section->partial('phpsoft.users::partials/permission', [ 'permission' => $permission ])); 10 | })); 11 | 12 | $this->set('linked', '{}'); 13 | -------------------------------------------------------------------------------- /packages/Users/resources/views/role/browse.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 3 | $this->set('links', $this->helper('phpsoft.users::helpers.links', $roles['data'])); 4 | $this->set('meta', function ($section) use ($roles) { 5 | 6 | $section->set('offset', $roles['offset']); 7 | $section->set('limit', $roles['limit']); 8 | $section->set('total', $roles['total']); 9 | }); 10 | 11 | $this->set('entities', $this->each($roles['data'], function ($section, $role) { 12 | 13 | $section->set($section->partial('phpsoft.users::partials/role', [ 'role' => $role ])); 14 | })); 15 | 16 | $this->set('linked', '{}'); 17 | -------------------------------------------------------------------------------- /packages/Users/resources/views/role/read.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('links', '{}'); 5 | $this->set('meta', '{}'); 6 | 7 | $this->set('entities', $this->each([ $role ], function ($section, $role) { 8 | 9 | $section->set($section->partial('phpsoft.users::partials/role', [ 'role' => $role ])); 10 | })); 11 | 12 | $this->set('linked', '{}'); 13 | -------------------------------------------------------------------------------- /packages/Users/resources/views/route/browse.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('links', '{}'); 5 | $this->set('meta', '{}'); 6 | 7 | $this->set('entities', $this->each($routes, function ($section, $route) { 8 | 9 | $section->set('method', $route->method); 10 | $section->set('uri', $route->uri); 11 | })); 12 | 13 | $this->set('linked', '{}'); 14 | -------------------------------------------------------------------------------- /packages/Users/resources/views/routePermission/browse.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 3 | $this->set('links', $this->helper('phpsoft.users::helpers.links', $routePermissions['data'])); 4 | $this->set('meta', function ($section) use ($routePermissions) { 5 | 6 | $section->set('offset', $routePermissions['offset']); 7 | $section->set('limit', $routePermissions['limit']); 8 | $section->set('total', $routePermissions['total']); 9 | }); 10 | 11 | $this->set('entities', $this->each($routePermissions['data'], function ($section, $routePermission) { 12 | 13 | $section->set($section->partial('phpsoft.users::partials/routePermission', [ 14 | 'routePermission' => $routePermission 15 | ])); 16 | })); 17 | 18 | $this->set('linked', '{}'); 19 | -------------------------------------------------------------------------------- /packages/Users/resources/views/routePermission/read.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('links', '{}'); 5 | $this->set('meta', '{}'); 6 | 7 | $this->set('entities', $this->each([ $routePermission ], function ($section, $routePermission) { 8 | 9 | $section->set($section->partial('phpsoft.users::partials/routePermission', [ 10 | 'routePermission' => $routePermission 11 | ])); 12 | })); 13 | 14 | $this->set('linked', '{}'); 15 | -------------------------------------------------------------------------------- /packages/Users/resources/views/tokens/show.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('links', '{}'); 5 | $this->set('meta', '{}'); 6 | 7 | $this->set('entities', $this->each([ $token ], function ($section, $token) { 8 | 9 | $section->set('token', $token); 10 | })); 11 | 12 | $this->set('linked', '{}'); 13 | -------------------------------------------------------------------------------- /packages/Users/resources/views/user/browse.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 3 | $this->set('links', $this->helper('phpsoft.users::helpers.links', $users['data'])); 4 | $this->set('meta', function ($section) use ($users) { 5 | 6 | $section->set('offset', $users['offset']); 7 | $section->set('limit', $users['limit']); 8 | $section->set('total', $users['total']); 9 | }); 10 | 11 | $this->set('entities', $this->each($users['data'], function ($section, $user) { 12 | 13 | $section->set($section->partial('phpsoft.users::partials/user', [ 'user' => $user ])); 14 | })); 15 | 16 | $this->set('linked', '{}'); 17 | -------------------------------------------------------------------------------- /packages/Users/resources/views/user/read.array.php: -------------------------------------------------------------------------------- 1 | set('version', '1.0'); 4 | $this->set('links', '{}'); 5 | $this->set('meta', '{}'); 6 | 7 | $this->set('entities', $this->each([ $user ], function ($section, $user) { 8 | 9 | $section->set($section->partial('phpsoft.users::partials/user', [ 'user' => $user ])); 10 | })); 11 | 12 | $this->set('linked', '{}'); 13 | -------------------------------------------------------------------------------- /phpspec.yml: -------------------------------------------------------------------------------- 1 | suites: 2 | main: 3 | namespace: App 4 | psr4_prefix: App 5 | src_path: app -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | packages/ 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | RewriteCond %{HTTP:Authorization} ^(.*) 9 | RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] 10 | 11 | # Redirect Trailing Slashes If Not A Folder... 12 | RewriteCond %{REQUEST_FILENAME} !-d 13 | RewriteRule ^(.*)/$ /$1 [L,R=301] 14 | 15 | # Handle Front Controller... 16 | RewriteCond %{REQUEST_FILENAME} !-d 17 | RewriteCond %{REQUEST_FILENAME} !-f 18 | RewriteRule ^ index.php [L] 19 | 20 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | /* 11 | |-------------------------------------------------------------------------- 12 | | Register The Auto Loader 13 | |-------------------------------------------------------------------------- 14 | | 15 | | Composer provides a convenient, automatically generated class loader for 16 | | our application. We just need to utilize it! We'll simply require it 17 | | into the script here so that we don't have to worry about manual 18 | | loading any of our classes later on. It feels nice to relax. 19 | | 20 | */ 21 | 22 | require __DIR__.'/../bootstrap/autoload.php'; 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Turn On The Lights 27 | |-------------------------------------------------------------------------- 28 | | 29 | | We need to illuminate PHP development, so let us turn on the lights. 30 | | This bootstraps the framework and gets it ready for use, then it 31 | | will load up this application so that we can run it and send 32 | | the responses back to the browser and delight our users. 33 | | 34 | */ 35 | 36 | $app = require_once __DIR__.'/../bootstrap/app.php'; 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Run The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once we have the application, we can handle the incoming request 44 | | through the kernel, and send the associated response back to 45 | | the client's browser allowing them to enjoy the creative 46 | | and wonderful application we have prepared for them. 47 | | 48 | */ 49 | 50 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 51 | 52 | $response = $kernel->handle( 53 | $request = Illuminate\Http\Request::capture() 54 | ); 55 | 56 | $response->send(); 57 | 58 | $kernel->terminate($request, $response); 59 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | // @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; 2 | 3 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'alpha' => 'The :attribute may only contain letters.', 20 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 21 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 22 | 'array' => 'The :attribute must be an array.', 23 | 'before' => 'The :attribute must be a date before :date.', 24 | 'between' => [ 25 | 'numeric' => 'The :attribute must be between :min and :max.', 26 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 27 | 'string' => 'The :attribute must be between :min and :max characters.', 28 | 'array' => 'The :attribute must have between :min and :max items.', 29 | ], 30 | 'boolean' => 'The :attribute field must be true or false.', 31 | 'confirmed' => 'The :attribute confirmation does not match.', 32 | 'date' => 'The :attribute is not a valid date.', 33 | 'date_format' => 'The :attribute does not match the format :format.', 34 | 'different' => 'The :attribute and :other must be different.', 35 | 'digits' => 'The :attribute must be :digits digits.', 36 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 37 | 'email' => 'The :attribute must be a valid email address.', 38 | 'filled' => 'The :attribute field is required.', 39 | 'exists' => 'The selected :attribute is invalid.', 40 | 'image' => 'The :attribute must be an image.', 41 | 'in' => 'The selected :attribute is invalid.', 42 | 'integer' => 'The :attribute must be an integer.', 43 | 'ip' => 'The :attribute must be a valid IP address.', 44 | 'max' => [ 45 | 'numeric' => 'The :attribute may not be greater than :max.', 46 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 47 | 'string' => 'The :attribute may not be greater than :max characters.', 48 | 'array' => 'The :attribute may not have more than :max items.', 49 | ], 50 | 'mimes' => 'The :attribute must be a file of type: :values.', 51 | 'min' => [ 52 | 'numeric' => 'The :attribute must be at least :min.', 53 | 'file' => 'The :attribute must be at least :min kilobytes.', 54 | 'string' => 'The :attribute must be at least :min characters.', 55 | 'array' => 'The :attribute must have at least :min items.', 56 | ], 57 | 'not_in' => 'The selected :attribute is invalid.', 58 | 'numeric' => 'The :attribute must be a number.', 59 | 'regex' => 'The :attribute format is invalid.', 60 | 'required' => 'The :attribute field is required.', 61 | 'required_if' => 'The :attribute field is required when :other is :value.', 62 | 'required_with' => 'The :attribute field is required when :values is present.', 63 | 'required_with_all' => 'The :attribute field is required when :values is present.', 64 | 'required_without' => 'The :attribute field is required when :values is not present.', 65 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 66 | 'same' => 'The :attribute and :other must match.', 67 | 'size' => [ 68 | 'numeric' => 'The :attribute must be :size.', 69 | 'file' => 'The :attribute must be :size kilobytes.', 70 | 'string' => 'The :attribute must be :size characters.', 71 | 'array' => 'The :attribute must contain :size items.', 72 | ], 73 | 'string' => 'The :attribute must be a string.', 74 | 'timezone' => 'The :attribute must be a valid zone.', 75 | 'unique' => 'The :attribute has already been taken.', 76 | 'url' => 'The :attribute format is invalid.', 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Custom Validation Language Lines 81 | |-------------------------------------------------------------------------- 82 | | 83 | | Here you may specify custom validation messages for attributes using the 84 | | convention "attribute.rule" to name the lines. This makes it quick to 85 | | specify a specific custom language line for a given attribute rule. 86 | | 87 | */ 88 | 89 | 'custom' => [ 90 | 'attribute-name' => [ 91 | 'rule-name' => 'custom-message', 92 | ], 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Custom Validation Attributes 98 | |-------------------------------------------------------------------------- 99 | | 100 | | The following language lines are used to swap attribute place-holders 101 | | with something more reader friendly such as E-Mail Address instead 102 | | of "email". This simply helps us make messages a little cleaner. 103 | | 104 | */ 105 | 106 | 'attributes' => [], 107 | 108 | ]; 109 | -------------------------------------------------------------------------------- /resources/views/emails/password.blade.php: -------------------------------------------------------------------------------- 1 | 3 |

You are receiving this e-mail because you requested resetting your password to domain.com

4 | Please click this URL to reset your password: http://domain.com/passwords/reset?token={{$token}} 5 | 6 | -------------------------------------------------------------------------------- /resources/views/errors/503.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Be right back. 5 | 6 | 7 | 8 | 39 | 40 | 41 |
42 |
43 |
Be right back.
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /resources/views/vendor/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/resources/views/vendor/.gitkeep -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Laravel 5 | 6 | 7 | 8 | 37 | 38 | 39 |
40 |
41 |
Laravel 5
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /storage/database.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/storage/database.sqlite -------------------------------------------------------------------------------- /storage/database.sqlite.blank: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php-soft/laravel-users/cd8d696dbf7337002188576d8a143cbc19d86b40/storage/database.sqlite.blank -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | compiled.php 4 | services.json 5 | events.scanned.php 6 | routes.scanned.php 7 | down 8 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); 22 | 23 | Route::post('/posts', [ 24 | 'middleware' => 'permission:create-post', 25 | function () { 26 | return response()->json(null, 200); 27 | } 28 | ]); 29 | 30 | Route::group(['middleware'=>'routePermission'], function() { 31 | 32 | Route::post('/blog/{id}', function ($id) { 33 | return response()->json(null, 200); 34 | }); 35 | }); 36 | 37 | Route::post('/user', ['middleware'=>'validate:App\Http\Validators\UserValidate', 38 | function () { 39 | return response()->json(null, 200); 40 | } 41 | ]); 42 | 43 | return $app; 44 | } 45 | 46 | public function setUp() 47 | { 48 | parent::setUp(); 49 | @unlink(base_path('storage/database.sqlite')); 50 | @copy(base_path('storage/database.sqlite.blank'), base_path('storage/database.sqlite')); 51 | Artisan::call('vendor:publish', ['--tag'=>['migrations']]); 52 | Artisan::call('migrate'); 53 | Artisan::call('db:seed', [ '--class' => 'UserModuleSeeder' ]); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/Users/Controllers/AuthControllerTest.php: -------------------------------------------------------------------------------- 1 | call('POST', '/auth/login'); 12 | $this->assertEquals(401, $res->getStatusCode()); 13 | $results = json_decode($res->getContent()); 14 | $this->assertEquals('error', $results->status); 15 | $this->assertEquals('authenticate', $results->type); 16 | $this->assertEquals('Invalid Credentials.', $results->message); 17 | 18 | // user not found 19 | $res = $this->call('POST', '/auth/login', [ 20 | 'email' => 'nouser@example.com', 21 | 'password' => '123456', 22 | ]); 23 | $this->assertEquals(401, $res->getStatusCode()); 24 | $results = json_decode($res->getContent()); 25 | $this->assertEquals('error', $results->status); 26 | $this->assertEquals('authenticate', $results->type); 27 | $this->assertEquals('Invalid Credentials.', $results->message); 28 | 29 | // wrong password 30 | $res = $this->call('POST', '/auth/login', [ 31 | 'email' => 'admin@example.com', 32 | 'password' => 'abcdef', 33 | ]); 34 | $this->assertEquals(401, $res->getStatusCode()); 35 | $results = json_decode($res->getContent()); 36 | $this->assertEquals('error', $results->status); 37 | $this->assertEquals('authenticate', $results->type); 38 | $this->assertEquals('Invalid Credentials.', $results->message); 39 | 40 | // can't create token 41 | JWTAuth::shouldReceive('attempt')->once()->andThrow(new Tymon\JWTAuth\Exceptions\JWTException('Could not create token.', 500)); 42 | $res = $this->call('POST', '/auth/login'); 43 | $results = json_decode($res->getContent()); 44 | $this->assertEquals(500, $res->getStatusCode()); 45 | $this->assertEquals('Could not create token.', $results->message); 46 | } 47 | 48 | public function testLoginSuccess() 49 | { 50 | $res = $this->call('POST', '/auth/login', [ 51 | 'email' => 'admin@example.com', 52 | 'password' => '123456', 53 | ]); 54 | $this->assertEquals(200, $res->getStatusCode()); 55 | $results = json_decode($res->getContent()); 56 | $this->assertNotNull($results->entities[0]->token); 57 | 58 | $this->assertEquals('admin@example.com', Auth::user()->email); 59 | } 60 | 61 | public function testCheckAuthLogout() 62 | { 63 | $this->withoutMiddleware(); 64 | $res = $this->call('POST', '/auth/logout'); 65 | $this->assertEquals(401, $res->getStatusCode()); 66 | } 67 | 68 | public function testLogout() 69 | { 70 | $credentials = [ 'email' => 'admin@example.com', 'password' => '123456' ]; 71 | $token = JWTAuth::attempt($credentials); 72 | 73 | $this->assertEquals('admin@example.com', Auth::user()->email); 74 | 75 | $res = $this->call('POST', '/auth/logout', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 76 | $this->assertEquals(204, $res->getStatusCode()); 77 | $this->assertNull(Auth::user()); 78 | 79 | // check re-logout 80 | $res = $this->call('POST', '/auth/logout', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 81 | $this->assertEquals(401, $res->getStatusCode()); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /tests/Users/Controllers/ControllerTest.php: -------------------------------------------------------------------------------- 1 | create(); 13 | $login = Auth::login($user); 14 | 15 | // Create role 16 | $creator = new Role(); 17 | $creator->name = 'creator'; 18 | $creator->save(); 19 | 20 | // Create permission 21 | $createPost = new Permission(); 22 | $createPost->name = 'create-post'; 23 | $createPost->display_name = 'Create Posts'; 24 | $createPost->description = 'create new blog posts'; 25 | $createPost->save(); 26 | 27 | // Attach creator role for user 28 | $user->attachRole($creator); 29 | 30 | // Attach createPost for creator role 31 | $creator->attachPermission($createPost); 32 | 33 | $controller = new Controller(); 34 | 35 | // Check user hasn't permission 36 | $hasPermission = $controller->checkPermission('edit-profile'); 37 | $this->assertEquals(false, $hasPermission); 38 | 39 | // Check user has permission 40 | $hasPermission = $controller->checkPermission('create-post'); 41 | $this->assertEquals(true, $hasPermission); 42 | } 43 | 44 | public function testPermissionUserIsAdmin() 45 | { 46 | // Check user is admin 47 | $user = factory(App\User::class)->create(); 48 | $login = Auth::login($user); 49 | 50 | $admin = Role::find(1); 51 | 52 | // Attach admin role for user 53 | $user->attachRole($admin); 54 | 55 | $controller = new Controller(); 56 | 57 | $isAdmin = $controller->checkPermission('manage-user'); 58 | $this->assertEquals(true, $isAdmin); 59 | } 60 | } -------------------------------------------------------------------------------- /tests/Users/Controllers/PasswordControllerTest.php: -------------------------------------------------------------------------------- 1 | call('POST','/passwords/forgot', [ 9 | 'email'=> 'admin@example' 10 | ]); 11 | $this->assertEquals(400, $checkSendMail->getStatusCode()); 12 | $result = json_decode($checkSendMail->getContent()); 13 | $this->assertEquals('The email must be a valid email address.', $result->email[0]); 14 | 15 | // check user is invalid 16 | $checkSendMail = $this->call('POST','/passwords/forgot', [ 17 | 'email'=> 'nouser@example.com' 18 | ]); 19 | $this->assertEquals(400, $checkSendMail->getStatusCode()); 20 | $result = json_decode($checkSendMail->getContent()); 21 | $this->assertEquals('User is invalid.', $result); 22 | 23 | // check send mail success 24 | $checkSendMail = $this->call('POST','/passwords/forgot', [ 25 | 'email'=> 'admin@example.com' 26 | ]); 27 | $this->assertEquals(200, $checkSendMail->getStatusCode()); 28 | } 29 | 30 | public function testResetPasswordFailure() 31 | { 32 | // check validate input 33 | 34 | // check input is empty 35 | $checkResetPassword = $this->call('POST','/passwords/reset'); 36 | $this->assertEquals(400, $checkResetPassword->getStatusCode()); 37 | $result = json_decode($checkResetPassword->getContent()); 38 | $this->assertEquals('The email field is required.', $result->email[0]); 39 | $this->assertEquals('The token field is required.', $result->token[0]); 40 | $this->assertEquals('The password field is required.', $result->password[0]); 41 | 42 | // check email format 43 | $checkResetPassword = $this->call('POST','/passwords/reset', [ 44 | 'token' => 'token', 45 | 'email' => 'admin@example', 46 | 'password' => '12345678', 47 | 'password_confirmation' => '12345678', 48 | ]); 49 | $this->assertEquals(400, $checkResetPassword->getStatusCode()); 50 | $result = json_decode($checkResetPassword->getContent()); 51 | $this->assertEquals('The email must be a valid email address.', $result->email[0]); 52 | 53 | // check password confirmation 54 | $checkResetPassword = $this->call('POST','/passwords/reset', [ 55 | 'token' => 'token', 56 | 'email' => 'admin@example.com', 57 | 'password' => '12345678', 58 | 'password_confirmation' => '123456', 59 | ]); 60 | $this->assertEquals(400, $checkResetPassword->getStatusCode()); 61 | $this->assertEquals(400, $checkResetPassword->getStatusCode()); 62 | $result = json_decode($checkResetPassword->getContent()); 63 | $this->assertEquals('The password confirmation does not match.', $result->password[0]); 64 | 65 | // check input incorrect 66 | $checkResetPassword = $this->call('POST','/passwords/reset', [ 67 | 'token' => 'token', 68 | 'email' => 'admin@example.com', 69 | 'password' => '12345678', 70 | 'password_confirmation' => '12345678', 71 | ]); 72 | $this->assertEquals(400, $checkResetPassword->getStatusCode()); 73 | } 74 | 75 | public function testResetPasswordSuccess() 76 | { 77 | // check reset password success 78 | Password::shouldReceive('reset')->once()->andReturn('passwords.reset'); 79 | 80 | $checkResetPassword = $this->call('POST','/passwords/reset', [ 81 | 'token' => 'token', 82 | 'email' => 'admin@example.com', 83 | 'password' => '12345678', 84 | 'password_confirmation' => '12345678', 85 | ]); 86 | $this->assertEquals(200, $checkResetPassword->getStatusCode()); 87 | } 88 | 89 | public function testCheckAuthChangePassword() 90 | { 91 | $this->withoutMiddleware(); 92 | $res = $this->call('PUT', '/me/password'); 93 | $this->assertEquals(401, $res->getStatusCode()); 94 | } 95 | 96 | public function testChangePassword() 97 | { 98 | // Check authenticate 99 | $res = $this->call('PUT', '/me/password'); 100 | $results = json_decode($res->getContent()); 101 | $this->assertEquals('error', $results->status); 102 | $this->assertEquals('authenticate', $results->type); 103 | $this->assertEquals('Token is not provided.', $results->message); 104 | 105 | $credentials = [ 'email' => 'admin@example.com', 'password' => '123456' ]; 106 | $token = JWTAuth::attempt($credentials); 107 | 108 | // Input is empty 109 | $res = $this->call('PUT', '/me/password', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 110 | $this->assertEquals(400, $res->getStatusCode()); 111 | $results = json_decode($res->getContent()); 112 | $this->assertEquals('error', $results->status); 113 | $this->assertEquals('validation', $results->type); 114 | $this->assertObjectHasAttribute('old_password', $results->errors); 115 | $this->assertEquals('The old password field is required.', $results->errors->old_password[0]); 116 | $this->assertObjectHasAttribute('password', $results->errors); 117 | $this->assertEquals('The password field is required.', $results->errors->password[0]); 118 | 119 | // Check validate input 120 | $res = $this->call('PUT', '/me/password', [ 121 | 'old_password' => '1234', 122 | 'password' => '1234', 123 | 'password_confirmation' => '123' 124 | ], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 125 | $this->assertEquals(400, $res->getStatusCode()); 126 | $results = json_decode($res->getContent()); 127 | $this->assertEquals('error', $results->status); 128 | $this->assertEquals('validation', $results->type); 129 | $this->assertObjectHasAttribute('old_password', $results->errors); 130 | $this->assertEquals('The old password must be at least 6 characters.', $results->errors->old_password[0]); 131 | $this->assertObjectHasAttribute('password', $results->errors); 132 | $this->assertEquals('The password confirmation does not match.', $results->errors->password[0]); 133 | $this->assertEquals('The password must be at least 6 characters.', $results->errors->password[1]); 134 | 135 | // Old password is wrong 136 | $res = $this->call('PUT', '/me/password', [ 137 | 'old_password' => '123456789', 138 | 'password' => '12345678', 139 | 'password_confirmation' => '12345678' 140 | ], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 141 | $this->assertEquals(400, $res->getStatusCode()); 142 | $results = json_decode($res->getContent()); 143 | $this->assertEquals('error', $results->status); 144 | $this->assertEquals("The old password is incorrect.", $results->message); 145 | $this->assertEquals('validation', $results->type); 146 | 147 | // Change password success 148 | $res = $this->call('PUT', '/me/password', [ 149 | 'old_password' => '123456', 150 | 'password' => '12345678', 151 | 'password_confirmation' => '12345678' 152 | ], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 153 | $this->assertEquals(204, $res->getStatusCode()); 154 | $checkPassword = Auth::attempt(['id' => 1, 'password' => '12345678']); 155 | $this->assertTrue($checkPassword); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /tests/Users/Middleware/AuthenticateTest.php: -------------------------------------------------------------------------------- 1 | once()->andReturn($request); 13 | $request->shouldReceive('getToken')->once()->andReturn(true); 14 | JWTAuth::shouldReceive('authenticate')->once()->andThrow(new Tymon\JWTAuth\Exceptions\TokenExpiredException('tymon.jwt.expired', 404)); 15 | 16 | $res = $this->call('POST', '/auth/logout'); 17 | $this->assertEquals(404, $res->getStatusCode()); 18 | $result = json_decode($res->getContent()); 19 | $this->assertEquals('Token has expired.', $result->message); 20 | $this->assertEquals('error', $result->status); 21 | $this->assertEquals('authenticate', $result->type); 22 | } 23 | 24 | public function testUserNotFound() 25 | { 26 | // Check user not found 27 | $request = Mockery::mock(); 28 | JWTAuth::shouldReceive('setRequest')->once()->andReturn($request); 29 | $request->shouldReceive('getToken')->once()->andReturn(true); 30 | JWTAuth::shouldReceive('authenticate')->once()->andReturn(false); 31 | 32 | $res = $this->call('POST', '/auth/logout'); 33 | $result = json_decode($res->getContent()); 34 | $this->assertEquals(404, $res->getStatusCode()); 35 | $this->assertEquals('User not found.', $result->message); 36 | $this->assertEquals('error', $result->status); 37 | $this->assertEquals('authenticate', $result->type); 38 | } 39 | } -------------------------------------------------------------------------------- /tests/Users/Middleware/PermissionTest.php: -------------------------------------------------------------------------------- 1 | call('POST', '/posts'); 11 | $this->assertEquals(401, $res->getStatusCode()); 12 | } 13 | 14 | public function testUserHaveNotPermission() 15 | { 16 | $user = factory(App\User::class)->make(); 17 | Auth::login($user); 18 | 19 | $res = $this->call('POST', '/posts'); 20 | $this->assertEquals(403, $res->getStatusCode()); 21 | } 22 | 23 | public function testUserHavePermission() 24 | { 25 | // create role creator 26 | $creator = new Role(); 27 | $creator->name = 'creator'; 28 | $creator->save(); 29 | 30 | // create permission 31 | $createPost = new Permission(); 32 | $createPost->name = 'create-post'; 33 | $createPost->save(); 34 | 35 | $creator->attachPermission($createPost); 36 | 37 | $user = factory(App\User::class)->create(); 38 | $user->attachRole($creator); 39 | Auth::login($user); 40 | 41 | $res = $this->call('POST', '/posts'); 42 | $this->assertEquals(200, $res->getStatusCode()); 43 | } 44 | 45 | public function testUserHaveNotPermissionButIsAdmin() 46 | { 47 | $user = App\User::where('email', 'admin@example.com')->first(); 48 | Auth::login($user); 49 | 50 | $res = $this->call('POST', '/posts'); 51 | $this->assertEquals(200, $res->getStatusCode()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/Users/Middleware/RoutePermissionTest.php: -------------------------------------------------------------------------------- 1 | call('POST', '/blog/1'); 13 | $this->assertEquals(200, $res->getStatusCode()); 14 | } 15 | 16 | public function testRouteRequirePermissionGuestAccess() 17 | { 18 | RoutePermission::setRoutePermissions('POST /blog/{id}', ['create-blog']); 19 | 20 | $res = $this->call('POST', '/blog/1'); 21 | $this->assertEquals(401, $res->getStatusCode()); 22 | 23 | $request = Mockery::mock(); 24 | $request->shouldReceive('getToken')->once()->andReturn('mocktoken'); 25 | JWTAuth::shouldReceive('setRequest')->once()->andReturn($request); 26 | JWTAuth::shouldReceive('authenticate')->once()->andThrow(new Tymon\JWTAuth\Exceptions\JWTException('Not authenticate.', 401)); 27 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer fake_token"]); 28 | $this->assertEquals(401, $res->getStatusCode()); 29 | 30 | $request = Mockery::mock(); 31 | $request->shouldReceive('getToken')->once()->andReturn('mocktoken'); 32 | JWTAuth::shouldReceive('setRequest')->once()->andReturn($request); 33 | JWTAuth::shouldReceive('authenticate')->once()->andReturn(null); 34 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer fake_token"]); 35 | $this->assertEquals(401, $res->getStatusCode()); 36 | } 37 | 38 | public function testRouteRequirePermissionUserHaveNotPermission() 39 | { 40 | RoutePermission::setRoutePermissions('POST /blog/{id}', ['create-blog']); 41 | 42 | $user = factory(App\User::class)->create(['password'=>bcrypt('123456')]); 43 | $credentials = [ 'email' => $user->email, 'password' => '123456' ]; 44 | $token = JWTAuth::attempt($credentials); 45 | 46 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 47 | $this->assertEquals(403, $res->getStatusCode()); 48 | } 49 | 50 | public function testRouteRequirePermissionUserHavePermission() 51 | { 52 | RoutePermission::setRoutePermissions('POST /blog/{id}', ['create-blog']); 53 | 54 | // create role creator 55 | $creator = new Role(); 56 | $creator->name = 'creator'; 57 | $creator->save(); 58 | 59 | // create permission 60 | $createPost = new Permission(); 61 | $createPost->name = 'create-blog'; 62 | $createPost->save(); 63 | 64 | $creator->attachPermission($createPost); 65 | 66 | $user = factory(App\User::class)->create(['password'=>bcrypt('123456')]); 67 | $user->attachRole($creator); 68 | $credentials = [ 'email' => $user->email, 'password' => '123456' ]; 69 | $token = JWTAuth::attempt($credentials); 70 | 71 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 72 | $this->assertEquals(200, $res->getStatusCode()); 73 | } 74 | 75 | public function testUserHaveNotPermissionButIsAdmin() 76 | { 77 | RoutePermission::setRoutePermissions('POST /blog/{id}', ['create-blog']); 78 | RoutePermission::setRouteRoles('POST /blog/{id}', ['creator', 'admin']); 79 | 80 | $credentials = [ 'email' => 'admin@example.com', 'password' => '123456' ]; 81 | $token = JWTAuth::attempt($credentials); 82 | 83 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 84 | $this->assertEquals(200, $res->getStatusCode()); 85 | } 86 | 87 | public function testUserPermission() 88 | { 89 | RoutePermission::setRouteRoles('POST /blog/{id}', ['@']); 90 | 91 | // not login 92 | $res = $this->call('POST', '/blog/1'); 93 | $this->assertEquals(401, $res->getStatusCode()); 94 | 95 | // has login 96 | $user = factory(App\User::class)->create(['password'=>bcrypt('123456')]); 97 | $credentials = [ 'email' => $user->email, 'password' => '123456' ]; 98 | $token = JWTAuth::attempt($credentials); 99 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 100 | $this->assertEquals(200, $res->getStatusCode()); 101 | } 102 | 103 | public function testSetRoutePermissionAllRouter() 104 | { 105 | RoutePermission::setRouteRoles('*', ['@']); 106 | 107 | // not login 108 | $res = $this->call('POST', '/blog/1'); 109 | $this->assertEquals(401, $res->getStatusCode()); 110 | 111 | // has login 112 | $user = factory(App\User::class)->create(['password'=>bcrypt('123456')]); 113 | $credentials = [ 'email' => $user->email, 'password' => '123456' ]; 114 | $token = JWTAuth::attempt($credentials); 115 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 116 | $this->assertEquals(200, $res->getStatusCode()); 117 | } 118 | 119 | public function testSetRoutePermissionAllRouterAndCurrentRoute() 120 | { 121 | RoutePermission::setRouteRoles('*', ['@']); 122 | RoutePermission::setRouteRoles('POST /blog/{id}', ['admin']); 123 | 124 | // not login 125 | $res = $this->call('POST', '/blog/1'); 126 | $this->assertEquals(401, $res->getStatusCode()); 127 | 128 | // has login, not admin 129 | $user = factory(App\User::class)->create(['password'=>bcrypt('123456')]); 130 | $credentials = [ 'email' => $user->email, 'password' => '123456' ]; 131 | $token = JWTAuth::attempt($credentials); 132 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 133 | $this->assertEquals(403, $res->getStatusCode()); 134 | } 135 | 136 | public function testSetRoutePermissionAllRouterAndCurrentRouteAdminAccess() 137 | { 138 | RoutePermission::setRouteRoles('*', ['@']); 139 | RoutePermission::setRouteRoles('POST /blog/{id}', ['admin']); 140 | 141 | // has login, is admin 142 | $credentials = [ 'email' => 'admin@example.com', 'password' => '123456' ]; 143 | $token = JWTAuth::attempt($credentials); 144 | $res = $this->call('POST', '/blog/1', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); 145 | $this->assertEquals(200, $res->getStatusCode()); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tests/Users/Middleware/ValidateTest.php: -------------------------------------------------------------------------------- 1 | call('POST', '/user'); 8 | $this->assertEquals(400, $res->getStatusCode()); 9 | $results = json_decode($res->getContent()); 10 | $this->assertEquals('error', $results->status); 11 | $this->assertEquals('validation', $results->type); 12 | $this->assertObjectHasAttribute('name', $results->errors); 13 | $this->assertEquals('The name field is required.', $results->errors->name[0]); 14 | $this->assertObjectHasAttribute('email', $results->errors); 15 | $this->assertEquals('The email field is required.', $results->errors->email[0]); 16 | $this->assertObjectHasAttribute('password', $results->errors); 17 | $this->assertEquals('The password field is required.', $results->errors->password[0]); 18 | } 19 | 20 | public function testValidateNameFailure() 21 | { 22 | $res = $this->call('POST', '/user', [ 23 | 'name' => 'Invalid name', 24 | 'email' => 'user@example.com', 25 | 'password' => 'password', 26 | 'password_confirmation' => 'password' 27 | ]); 28 | $this->assertEquals(400, $res->getStatusCode()); 29 | $results = json_decode($res->getContent()); 30 | $this->assertEquals('The name is in valid.', $results->errors->name[0]); 31 | } 32 | 33 | public function testValidateSuccess() 34 | { 35 | $res = $this->call('POST', '/user', [ 36 | 'name' => 'validate_name', 37 | 'email' => 'user@example.com', 38 | 'password' => 'password', 39 | 'password_confirmation' => 'password' 40 | ]); 41 | $this->assertEquals(200, $res->getStatusCode()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/build/bin/phpcs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | ./vendor/bin/phpcs --report=checkstyle --report-file=tests/build/logs/checkstyle.xml --standard=tests/build/config/phpcs.xml --ignore=*.html.php,*.config.php,*.twig.php packages 3 | php ./tests/build/scripts/checkstyle.php 4 | -------------------------------------------------------------------------------- /tests/build/bin/phpmd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | ./vendor/bin/phpmd packages xml tests/build/config/phpmd.xml --reportfile tests/build/logs/pmd.xml 3 | php ./tests/build/scripts/pmd.php 4 | -------------------------------------------------------------------------------- /tests/build/bin/phpqunit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | ./vendor/bin/phpunit --configuration ./tests/build/config/phpunit.quick.xml "$@" 3 | -------------------------------------------------------------------------------- /tests/build/bin/phpunit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | ./vendor/bin/phpunit --configuration phpunit.xml "$@" 3 | -------------------------------------------------------------------------------- /tests/build/config/phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | The coding standard for standard PHP application 4 | */img/* 5 | */images/* 6 | */less/* 7 | */css/* 8 | */js/* 9 | *.html 10 | *.twig 11 | *.yml 12 | *.xml 13 | *.txt 14 | *.less 15 | *.css 16 | *.js 17 | *.jpg 18 | *.jpeg 19 | *.png 20 | *.gif 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/build/config/phpmd.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | PHP rule set that checks code 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/build/config/phpunit.quick.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ../../../tests/ 15 | 16 | 17 | 18 | 19 | ../../../packages/ 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/build/coverage/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /tests/build/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /tests/build/scripts/ColorCLI.php: -------------------------------------------------------------------------------- 1 | $fgCode) { 9 | * echo ColorCLI::$fg($str); 10 | * 11 | * foreach (ColorCLI::$backgroundColors as $bg => $bgCode) { 12 | * echo ColorCLI::$fg($str, $bg); 13 | * } 14 | * 15 | * echo PHP_EOL; 16 | * } 17 | * 18 | * @see http://www.if-not-true-then-false.com/2010/php-class-for-coloring-php-command-line-cli-scripts-output-php-output-colorizing-using-bash-shell-colors/ 19 | */ 20 | class ColorCLI 21 | { 22 | public static $foregroundColors = array( 23 | 'bold' => '1', 'dim' => '2', 24 | 'black' => '0;30', 'dark_gray' => '1;30', 25 | 'blue' => '0;34', 'lightBlue' => '1;34', 26 | 'green' => '0;32', 'lightGreen' => '1;32', 27 | 'cyan' => '0;36', 'lightCyan' => '1;36', 28 | 'red' => '0;31', 'lightRed' => '1;31', 29 | 'purple' => '0;35', 'lightPurple' => '1;35', 30 | 'brown' => '0;33', 'yellow' => '1;33', 31 | 'lightGray' => '0;37', 'white' => '1;37', 32 | 'normal' => '0;39', 33 | ); 34 | 35 | public static $backgroundColors = array( 36 | 'black' => '40', 'red' => '41', 37 | 'green' => '42', 'yellow' => '43', 38 | 'blue' => '44', 'magenta' => '45', 39 | 'cyan' => '46', 'lightGray' => '47', 40 | ); 41 | 42 | public static $options = array( 43 | 'underline' => '4', 'blink' => '5', 44 | 'reverse' => '7', 'hidden' => '8', 45 | ); 46 | 47 | public static function __callStatic($foregroundColor, array $args) 48 | { 49 | if (!isset($args[0])) { 50 | throw new \InvalidArgumentException('Coloring string must be specified.'); 51 | } 52 | 53 | $string = $args[0]; 54 | $coloredString = ""; 55 | 56 | // Check if given foreground color found 57 | if (isset(static::$foregroundColors[$foregroundColor])) { 58 | $coloredString .= static::color(static::$foregroundColors[$foregroundColor]); 59 | } else { 60 | die($foregroundColor . ' not a valid color'); 61 | } 62 | 63 | array_shift($args); 64 | 65 | foreach ($args as $option) { 66 | // Check if given background color found 67 | if (isset(static::$backgroundColors[$option])) { 68 | $coloredString .= static::color(static::$backgroundColors[$option]); 69 | } elseif (isset(self::$options[$option])) { 70 | $coloredString .= static::color(static::$options[$option]); 71 | } 72 | } 73 | 74 | // Add string and end coloring 75 | $coloredString .= $string . "\033[0m"; 76 | 77 | return $coloredString; 78 | } 79 | 80 | public static function bell($count = 1) 81 | { 82 | echo str_repeat("\007", $count); 83 | } 84 | 85 | protected static function color($color) 86 | { 87 | return "\033[" . $color . "m"; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/build/scripts/checkstyle.php: -------------------------------------------------------------------------------- 1 | file as $file) { 8 | echo sprintf("file: %s", $file['name']) . PHP_EOL; 9 | foreach ($file->error as $violation) { 10 | echo " " . printMessage($violation) . PHP_EOL; 11 | echo sprintf( 12 | " severity: %s rule: %s at line %s column %s", 13 | $violation['severity'], 14 | $violation['source'], 15 | $violation['line'], 16 | $violation['column'] 17 | ), 18 | PHP_EOL; 19 | } 20 | } 21 | 22 | return 0; 23 | } 24 | 25 | function printMessage($violation) 26 | { 27 | $str = $violation['message']; 28 | 29 | if (!class_exists('ColorCLI')) { 30 | return $str; 31 | } 32 | 33 | $severity = $violation['severity']; 34 | 35 | if ($severity == 'error') { 36 | return ColorCLI::red($str); 37 | } elseif ($severity == 'warning') { 38 | return ColorCLI::yellow($str); 39 | } 40 | 41 | return ColorCLI::cyan($str); 42 | } 43 | 44 | function checkFile($xmlFileName) 45 | { 46 | $root = realpath(__DIR__ . "/.."); 47 | $path = realpath("$root/logs/$xmlFileName"); 48 | 49 | if ($path === false || !file_exists($path)) { 50 | return "Not found $xmlFileName"; 51 | } 52 | 53 | return run($path); 54 | } 55 | 56 | $colorCli = realpath(__DIR__ . '/ColorCLI.php'); 57 | 58 | if (file_exists($colorCli)) { 59 | include_once $colorCli; 60 | } 61 | 62 | define('NORMAL_PRIORITY', 3); 63 | 64 | 65 | $result = array( 66 | checkFile("checkstyle.xml"), 67 | // checkFile("checkstyle-apigen.xml"), 68 | ); 69 | 70 | foreach ($result as $value) { 71 | if (is_string($value)) { 72 | echo $value, PHP_EOL; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/build/scripts/junit.php: -------------------------------------------------------------------------------- 1 | testsuite; 7 | 8 | echo sprintf("total: %s msec", formatMsec($project['time'])) . PHP_EOL; 9 | 10 | foreach ($project->testsuite as $testsuite) { 11 | echo sprintf(" suite: %s msec : %s", formatMsec($testsuite['time']), $testsuite['name']) . PHP_EOL; 12 | 13 | foreach ($testsuite->testcase as $testcase) { 14 | echo sprintf(" case: %s msec : %s", printMsec($testcase['time']), $testcase['name']) . PHP_EOL; 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | function msec($str) 22 | { 23 | return floatval((string)$str) * 1000; 24 | } 25 | 26 | function formatMsec($time) 27 | { 28 | return sprintf('%9.3f', msec($time)); 29 | } 30 | 31 | function printMsec($time, $warn = 5, $error = 10) 32 | { 33 | $str = formatMsec($time); 34 | 35 | if (!class_exists('ColorCLI')) { 36 | return $str; 37 | } 38 | 39 | $msec = msec($time); 40 | 41 | if ($msec < $warn) { 42 | return ColorCLI::lightGreen($str); 43 | } elseif ($msec < $error) { 44 | return ColorCLI::yellow($str); 45 | } 46 | 47 | return ColorCLI::red($str); 48 | } 49 | 50 | $colorCli = realpath(__DIR__ . '/ColorCLI.php'); 51 | 52 | if (file_exists($colorCli)) { 53 | include_once $colorCli; 54 | } 55 | 56 | $xmlFileName = "junit.xml"; 57 | $root = realpath(__DIR__ . "/.."); 58 | $path = realpath("$root/logs/$xmlFileName"); 59 | 60 | if ($path === false || !file_exists($path)) { 61 | die("Not found $xmlFileName"); 62 | } 63 | 64 | return run($path); 65 | -------------------------------------------------------------------------------- /tests/build/scripts/pmd.php: -------------------------------------------------------------------------------- 1 | file as $file) { 8 | echo sprintf("file: %s", $file['name']) . PHP_EOL; 9 | foreach ($file->violation as $violation) { 10 | echo " " . printMessage($violation) . PHP_EOL; 11 | echo sprintf( 12 | " priority: %s rule: %s:%s at line %s - %s", 13 | $violation['priority'], 14 | $violation['ruleset'], 15 | $violation['rule'], 16 | $violation['beginline'], 17 | $violation['endline'] 18 | ), 19 | PHP_EOL; 20 | } 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | function isHighPriority($priority) 27 | { 28 | // red 29 | return $priority < NORMAL_PRIORITY; 30 | } 31 | 32 | function isNormatPriority($priority) 33 | { 34 | // yellow 35 | return $priority == NORMAL_PRIORITY; 36 | } 37 | 38 | function isLowPriority($priority) 39 | { 40 | return $priority > NORMAL_PRIORITY; 41 | } 42 | 43 | function printMessage($violation) 44 | { 45 | $str = formatMessage($violation); 46 | 47 | if (!class_exists('ColorCLI')) { 48 | return $str; 49 | } 50 | 51 | $priority = $violation['priority']; 52 | 53 | if (isHighPriority($priority)) { 54 | return ColorCLI::red($str); 55 | } elseif (isNormatPriority($priority)) { 56 | return ColorCLI::yellow($str); 57 | } 58 | 59 | return ColorCLI::cyan($str); 60 | } 61 | 62 | function formatMessage($violation) 63 | { 64 | return trim($violation); 65 | } 66 | 67 | $colorCli = realpath(__DIR__ . '/ColorCLI.php'); 68 | 69 | if (file_exists($colorCli)) { 70 | include_once $colorCli; 71 | } 72 | 73 | $xmlFileName = "pmd.xml"; 74 | $root = realpath(__DIR__ . "/.."); 75 | $path = realpath("$root/logs/$xmlFileName"); 76 | 77 | if ($path === false || !file_exists($path)) { 78 | die("Not found $xmlFileName"); 79 | } 80 | 81 | define('NORMAL_PRIORITY', 3); 82 | 83 | return run($path); 84 | --------------------------------------------------------------------------------