Giter Site home page Giter Site logo

vault's Introduction

##This package is no longer maintained. Please use the full boilerplate instead.

Vault (Laravel 5 Package)

Project Status Build Status Scrutinizer Code Quality Total Downloads License

Vault is a simple yet powerful access control system for the new Laravel 5 Framework. It comes with a backend user interface to manage users, roles, and permissions as well as the relationships between them.

Be advised while this package works fully, it is still in development and the code base changes often. A 1.0 tag will be created when the package is stable for release.

Examples: Vault User Index Vault Create Role Vault Edit User Vault Role Index

Documentation

Prerequisites

  • This package assumes you have an installation of Laravel 5 using the pre-packaged authentication library and functionality. For a brand new project, I recommend using my Laravel 5 Boilerplate Package and requiring this library.
  • User model must have soft deletes enabled.
## Setup

In the require key of composer.json file add the following

"rappasoft/vault": "dev-master"

Run the Composer update command

$ composer update

In your config/app.php add the following to your $providers and $aliases array

'providers' => [

    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
    ...
    Rappasoft\Vault\VaultServiceProvider::class,
    Illuminate\Html\HtmlServiceProvider::class,

],
'aliases' => [

    'App'       => Illuminate\Support\Facades\App::class,
    ...
    'Form'		=> Illuminate\Html\FormFacade::class,
    'HTML'		=> Illuminate\Html\HtmlFacade::class

],

The Vault Facade is loaded by the service provider by default.

Run the `vendor:publish` command
$ php artisan vendor:publish --provider="Rappasoft\Vault\VaultServiceProvider"

This will publish the following files to your application:

  • app/config/vault.php config file
  • Vault Migration File
  • Vault Seed File (Will add the seed call to the end of your DatabaseSeeder.php class)
  • public/js/vault/*
  • public/css/vault/*

You can also publish individual assets by tag if need be:

$ php artisan vendor:publish --provider="Rappasoft\Vault\VaultServiceProvider" --tag="config"
$ php artisan vendor:publish --provider="Rappasoft\Vault\VaultServiceProvider" --tag="migration"
$ php artisan vendor:publish --provider="Rappasoft\Vault\VaultServiceProvider" --tag="seeder"
$ php artisan vendor:publish --provider="Rappasoft\Vault\VaultServiceProvider" --tag="assets"

You can also publish views, see configuration below.

Run the dumpautoload command

$ composer dumpautoload -o

Run the migration command

$ php artisan migrate
Add the `UserHasRole` trait to your User model:
<?php namespace App;

...
use Illuminate\Database\Eloquent\SoftDeletes;
use Rappasoft\Vault\Traits\UserHasRole;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

	use Authenticatable, CanResetPassword, SoftDeletes, UserHasRole;
}
Run the `seed` command
$ php artisan db:seed --class="VaultTableSeeder"
Add the `route middleware` to your app/Http/Kernel.php file:
protected $routeMiddleware = [
    'auth' => App\Http\Middleware\Authenticate::class,
    'auth.basic' => Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => App\Http\Middleware\RedirectIfAuthenticated::class,
    ...
    'vault.routeNeedsRole' => \Rappasoft\Vault\Http\Middleware\RouteNeedsRole::class,
    'vault.routeNeedsPermission' => \Rappasoft\Vault\Http\Middleware\RouteNeedsPermission::class,
    'vault.routeNeedsRoleOrPermission' => \Rappasoft\Vault\Http\Middleware\RouteNeedsRoleOrPermission::class,
];

###That's it! You should now be able to navigate to http://localhost/access/users to see the users index.

## Configuration ###Configuration File
/*
* The company name used in the footer of the vault views.
*/
vault.general.company_name
/*
* Whether or not to load the vault views when the application loads.
* Useful if you want to copy the vault routes into your own routes file to modify.
*/
vault.general.use_vault_routes

/*
* The namespaced route to the vault role
*/
vault.role
/*
* The namespaced route to the vault permission
*/
vault.permission

/*
* Used by Vault to save roles to the database.
*/
vault.roles_table
/*
* Used by Vault to save permissions to the database.
*/
vault.permissions_table
/*
* Used by Vault to save relationship between permissions and roles to the database.
*/
vault.permission_role_table
/*
 * Used by Vault to save relationship between permissions and users to the database.
 * This table is only for permissions that belong directly to a specific user and not a role
 */
vault.permission_user_table
/*
* Used by Vault to save assigned roles to the database.
*/
vault.assigned_roles_table

/*
* Amount of users to show per page for pagination on users.index
*/
vault.users.default_per_page
/*
* The rules to validate the users password by when creating a new user
*/
vault.users.password_validation

/*
* Whether a role must contain a permission or can be used standalone (perhaps as a label)
*/
vault.roles.role_must_contain_permission
/*
 * Whether or not the administrator role must possess every permission
 * Works in unison with permissions.permission_must_contain_role
 */
vault.roles.administrator_forced

/*
 * Whether a permission must contain a role or can be used standalone
 * Works in unison with roles.administrator_forced
 * If a permission doesn't contain a role it can be assigned directly to a user
 */
vault.permissions.permission_must_contain_role

/*
 * Validation overwrites, at time of validation uses these rules
 * Each must return an array even if a single rule
*/
vault.validation.users.create
vault.validation.users.update
### Vault Views

By default the package works without publishing its views. But if you wanted to publish the vault views to your application to take full control, run the vault:views command:

$ php artisan vault:views
### Vault Routes

If you do not want vault to use its default routes file you can duplicate it and set the vault.general.use_vault_routes configuration to false and it will not load by default.

### Utilizing the `status` property

If would would like to enable enabled/disabled users you can simply do a check wherever you are logging in your user:

if ($user->status == 0)
    return Redirect::back()->withMessage("Your account is currently disabled");
## Applying the Route Middleware

Laravel 5 is trying to steer away from the filters.php file and more towards using middleware. Here is an example right from the vault routes file of a group of routes that requires the Administrator role:

Route::group([
	'middleware' => 'vault.routeNeedsRole',
	'role' => ['Administrator'],
	'redirect' => '/',
	'with' => ['error', 'You do not have access to do that.']
], function()
{
    Route::group(['prefix' => 'access'], function ()
    	{
    		/*User Management*/
    		Route::resource('users', '\Rappasoft\Vault\Http\Controllers\UserController', ['except' => ['show']]);
    	});
});

The above code checks to see if the currently authenticated user has the role Administrator, if not redirects to / with a session variable that has a key of message and value of You do not have access to do that.

The following middleware ships with the vault package:

  • vault.routeNeedsRole
  • vault.routeNeedsPermission
  • vault.routeNeedsRoleOrPermission
## Route Parameters
  • middleware => The middleware name, you can change them in your app/Http/Kernel.php file.
  • role => A string of one role or an array of roles by name.
  • permission => A string of one permission or an array of permissions by name.
  • needsAll => A boolean, false by default, that states whether or not all of the specified roles/permissions are required to authenticate.
  • with => Sends a session flash on failure. Array with 2 items, first is session key, second is value.
  • redirect => Redirect to a url if authentication fails.
  • redirectRoute => Redirect to a route if authentication fails.
  • redirectAction => Redirect to an action if authentication fails.

If no redirect is specified a response('Unauthorized', 401); will be thrown.

## Create Your Own Middleware

If you would like to create your own middleware, the following methods are available.

/**
	 * Checks if the user has a Role by its name.
	 * @param string $name
	 * @return bool
*/
Vault::hasRole($role);

/**
	 * Checks to see if the user has an array of roles, and whether or not all must return true to authenticate
	 * @param array $roles
	 * @param boolean $needsAll
	 * @return bool
*/
Vault::hasRoles($roles, $needsAll);

/**
	 * Check if user has a permission by its name.
	 * @param string $permission.
	 * @return bool
*/
Vault::can($permission);

/**
	 * Check an array of permissions and whether or not all are required to continue
	 * @param array $permissions
	 * @param boolean $needsAll
	 * @return bool
*/
Vault::canMultiple($permissions, $needsAll);

Vault:: by default uses the currently authenticated user. You can also do:

$user->hasRole($role);
$user->hasRoles($roles, $needsAll);
$user->can($permission);
$user->canMultiple($permissions, $needsAll);
### VaultRoute trait

If you would like to take advantage of the methods used by Vault's route handler, you can use it:

use Rappasoft\Vault\Traits\VaultRoute

Which will give you methods in your middleware to grab route assets. You can then add methods to your middleware to grab assets that vault doesn't grab by default and take advantage of them.

## Blade Extensions

Vault comes with @blade extensions to help you show and hide data by role or permission without clogging up your code with unwanted if statements:

@role('User')
    This content will only show if the authenticated user has the `User` role.
@endrole

@permission('can_view_this_content')
    This content will only show if the authenticated user is somehow associated with the `can_view_this_content` permission.
@endpermission

Currently each call only supports one role or permission, however they can be nested.

If you want to show or hide a specific section you can do so in your layout files the same way:

@role('User')
    @section('special_content')
@endrole

@permission('can_view_this_content')
    @section('special_content')
@endpermission
## License

Vault is free software distributed under the terms of the MIT license.

## Additional information

Any issues, please report here.

vault's People

Contributors

andywendt avatar dennie170 avatar gregoryduckworth avatar martinlindhe avatar rappasoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vault's Issues

Invalid argument supplied for foreach()

Hello,

I try to use this package and... it is good! very nice!
i found i little problem when i'm in the "site.app:8000/access/users/create".
I fill the fields and press "Save". The sistem create new user correctly, but then, i rest in the same page
and i see this error "Invalid argument supplied for foreach()".

Can you help me?

Other information : the "version" of my installation is "Installing rappasoft/vault (dev-master 7bf215c)" (readed during "composer update" command)

Update to docs

You need to update the docs to include adding:

'Illuminate\Html\HtmlServiceProvider', to the providers
and
'Form' => 'Illuminate\Html\FormFacade', 'HTML' => 'Illuminate\Html\HtmlFacade' to the aliases

Password Requirements

How do i change the password so its not just alpha numeric? i also want to allow special characters

unable to access admin part

access/users url redirecting to dashboard. i used laravel-5-boilerplate and vault package, i didn't found any errors at time of installation but am unable access admin part, all Role and Permissions of Controllers and Middleware files are at Vendor only

User Page restrictions

Hi i installed this packages..
if User login as a staff he can only see uers List .. Staff can't do edit update or delete and can't see other pages how can i do that..

an update for laravel 5.2.14 ?

for the recent udpate ... i've theses error :
Conclusion: don't install illuminate/support v5.1.25

  • Conclusion: don't install laravel/framework v5.2.12

and

don't install illuminate/support v5.1.1|don't install laravel/framework v5.2.*

Some update for the futur ?

users.deleted_at assumed

Hello, following setup instructions i hit this:

exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.deleted_at' in 'where clause'' in /home/vagrant/dev/l5-kvarnia/l5/vendor/laravel/framework/src/Illuminate/Database/Connection.php:288

Should be straigtforward to fix, by adding to my users table migration:

 $table->timestamp('deleted_at');

However, it could possibly be mentioned in the readme, or taken care of by the migrations this package creates?

/m

update "deleted at" on logout

Vault update "deleted_at" field on logout action. This deletes my user and need to "null" the field again to log in.

radic/blade-extensions and laravel 5

Hello Anthony,

I am building an app on top of you laravel 5 boilerplate and vault. I noticed you have a mention of blade extensions which I would very much like to use. Unfortunately I have trouble installing the suggested radic/blade-extensions. Below are my composer update conflicts. How did you get that to work?

Thanks,
Peter

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: remove laravel/framework v5.0.2
- Installation request for radic/blade-extensions 1.2 -> satisfiable by radic/blade-extensions[v1.2.0].
- Conclusion: don't install laravel/framework v5.0.2
- Conclusion: don't install laravel/framework v5.0.1
- radic/blade-extensions v1.2.0 requires illuminate/support 4.* -> satisfiable by illuminate/support[v4.0.0, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9, v4.1.0, v4.1.1, v4.1.10, v4.1.11, v4.1.12, v4.1.13, v4.1.14, v4.1.15, v4.1.16, v4.1.17, v4.1.18, v4.1.19, v4.1.2, v4.1.20, v4.1.21, v4.1.22, v4.1.23, v4.1.24, v4.1.25, v4.1.26, v4.1.27, v4.1.28, v4.1.29, v4.1.3, v4.1.30, v4.1.4, v4.1.5, v4.1.6, v4.1.7, v4.1.8, v4.1.9, v4.2.1, v4.2.12, v4.2.16, v4.2.2, v4.2.3, v4.2.4, v4.2.5, v4.2.6, v4.2.7, v4.2.8, v4.2.9].
- don't install illuminate/support v4.0.0|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.1|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.10|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.2|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.3|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.4|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.5|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.6|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.7|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.8|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.0.9|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.0|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.1|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.10|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.11|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.12|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.13|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.14|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.15|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.16|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.17|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.18|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.19|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.2|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.20|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.21|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.22|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.23|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.24|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.25|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.26|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.27|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.28|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.29|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.3|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.30|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.4|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.5|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.6|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.7|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.8|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.1.9|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.1|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.12|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.16|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.2|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.3|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.4|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.5|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.6|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.7|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.8|don't install laravel/framework v5.0.0
- don't install illuminate/support v4.2.9|don't install laravel/framework v5.0.0
- Installation request for laravel/framework 5.0.* -> satisfiable by laravel/framework[v5.0.0, v5.0.1, v5.0.2].

Add support to custom layout

Hi Anthony.. Can you add support to add custom layout?.. It is too hard??..

We can use or not use the vault views... but, what if we want to use your vault views with some extra features or design...

Sorry for my english... thanks.

pS. this is not an issue, this is an enhancement request.

Wrong msg creating new users

Hi,

When i try to create a new user without errors, the system goes back and put a danger message with "Invalid argument supplied for foreach()" but the user is created in db.

Sorry for my english xD
error

[Question] If not logged in -> log in form

I have this example

Route::group([
    'middleware' => 'vault.routeNeedsRole',
    'role' => ['Administrator','Test1'], 
    'redirect' => 'not-autorized',
    'with' => ['error', 'You do not have access to do that.']
], function()
{
    Route::get('example', 'testController@test');
}

I want this : if user go to "site.com/example" and he is not logged in, show login form. After login, redirect to the resource requested by user
site.com/example ---> loginform ----> site.com/example
second example
site.com/example/54/edit ---->loginform --->site.com/example/54/edit
how we can do this?

Error seeding

Getting the following error.

php artisan db:seed --class="VaultTableSeeder"
[Illuminate\Database\QueryException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.deleted_at' in 'where clause' (SQL: select * from `users` where `users`.`deleted_at` is null limit 1)
[PDOException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.deleted_at' in 'where clause'

Do I need to add deleted_at into the users table?

Thanks

incorrectly getting pivot table name

I'm using a fresh laravel 5 install with vault, followed the setup and navigating to /access/users throws a Query Builder exception:

Next exception 'ErrorException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_testbed.user_vault_permission' doesn't exist (SQL: select count(*) as aggregate from `permissions` inner join `user_vault_permission` on `permissions`.`id` = `user_vault_permission`.`permission_id` where `user_vault_permission`.`user_id` = 1) (View: /home/vagrant/Code/l5/resources/views/vendor/vault/index.blade.php)' in /home/vagrant/Code/l5/vendor/laravel/framework/src/Illuminate/Database/Connection.php:614

EDIT: After quick investigation the vault.permission_user_table Schema from migrations.stub is not getting copied over to the migration file. As well neither is the configuration option in the config file.

Error in RouteNeedsRole.php

I get the following exception when trying to implement Vault!!

ErrorException in RouteNeedsRole.php line 22:
Non-static method App\Models\Vault::hasRoles() should not be called statically, assuming $this from incompatible context

To understand i did not install your package i copied some of the classes because I don't need all of your views and stuff.
Thanks

Bug in seeds.stub?

In the end of the seeds.stub, there is this snippet:

$user_model = Config::get('auth.model');
$user = $user_model::find(2);
$user->permissions()->sync(
    [
        $userOnlyPermission->id,
    ]
);

I think it should instead look like this, judging from how the admin role permissions is setup earlier:

$user_model = Config::get('vault.role');
$user = $user_model::find(2);
$user->permissions()->sync(
    [
        $userOnlyPermission->id,
    ]
);

deleted_at is set on each auth/logout

Hi,
I'm having trouble that the deleted_at and the remember_token is set on the user model each time i logout from the system so that when i try to login the authentication fails due to deleted_at is not null anymore.

Anyone else bumped into this problem?

Overwrite validation

Hi,

We're using your package and it is great.
It saves us a lot of time, but we have one problem with it.

We're using some different field. Instead of having a name field we're have multiple fields for firstname and lastname.

Your validation file (vendor/rappasoft/vault/src/Vault/Services/Validators/Rules/Auth/User/Create.php) requires the name field which we don't have.

I would like to know how we could overwrite this in our software.

Best regards,

Jurgen

Keep up the good work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.