Skip to content

Commit

Permalink
Merge commit 'dc5062177900727279051c7be37ede3566416c0a' as 'Modules/U…
Browse files Browse the repository at this point in the history
…ser'
  • Loading branch information
nWidart committed Sep 9, 2016
2 parents 17f7789 + dc50621 commit 7a96299
Show file tree
Hide file tree
Showing 89 changed files with 4,876 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Modules/User/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/
/vendor
.php_cs.cache
composer.lock
Modules/
build
48 changes: 48 additions & 0 deletions Modules/User/.php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('Modules')
->exclude('vendor')
->in(__DIR__)
;

return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array(
// Concatenation should be used with at least one whitespace around.
'concat_with_spaces',
// Unused use statements must be removed.
'ordered_use',
// Removes extra empty lines.
'extra_empty_lines',
// Removes line breaks between use statements.
'remove_lines_between_uses',
// An empty line feed should precede a return statement.
'return',
// Unused use statements must be removed.
'unused_use',
// Remove trailing whitespace at the end of blank lines.
'whitespacy_lines',
// There MUST be one blank line after the namespace declaration.
'line_after_namespace',
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace',
// Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
'single_line_after_imports',
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
'blankline_after_open_tag',
// Remove duplicated semicolons.
'duplicate_semicolon',
// PHP multi-line arrays should have a trailing comma.
'multiline_array_trailing_comma',
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening',
// There should not be blank lines between docblock and the documented element.
'no_empty_lines_after_phpdocs',
// Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim',
// Removes line breaks between use statements.
'remove_lines_between_uses',
))
->finder($finder);
35 changes: 35 additions & 0 deletions Modules/User/.scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
filter:
excluded_paths: [tests/*]
checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
tools:
external_code_coverage:
timeout: 600
runs: 3
php_analyzer: true
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [vendor, tests]
php_cpd:
enabled: true
excluded_dirs: [vendor, tests]
3 changes: 3 additions & 0 deletions Modules/User/.sensiolabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rules:
php.interface_has_no_interface_suffix:
enabled: false
25 changes: 25 additions & 0 deletions Modules/User/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: php

php:
- 7
- 5.6
- hhvm

env:
- LARAVEL_VERSION="~5.2" TESTBENCH_VERSION="~3.2"

before_script:
- travis_retry composer install --no-interaction --prefer-source

script: phpunit

sudo: false

notifications:
email:
- [email protected]
- [email protected]

matrix:
allow_failures:
- php: hhvm
24 changes: 24 additions & 0 deletions Modules/User/Composers/PermissionsViewComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Modules\User\Composers;

use Modules\User\Permissions\PermissionManager;

class PermissionsViewComposer
{
/**
* @var PermissionManager
*/
private $permissions;

public function __construct(PermissionManager $permissions)
{
$this->permissions = $permissions;
}

public function compose($view)
{
// Get all permissions
$view->permissions = $this->permissions->all();
}
}
24 changes: 24 additions & 0 deletions Modules/User/Composers/UsernameViewComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Modules\User\Composers;

use Illuminate\Contracts\View\View;
use Modules\User\Contracts\Authentication;

class UsernameViewComposer
{
/**
* @var Authentication
*/
private $auth;

public function __construct(Authentication $auth)
{
$this->auth = $auth;
}

public function compose(View $view)
{
$view->with('user', $this->auth->user());
}
}
78 changes: 78 additions & 0 deletions Modules/User/Config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Define which user driver to use.
|--------------------------------------------------------------------------
| Current default and only option : Sentinel
*/
'driver' => 'Sentinel',
/*
|--------------------------------------------------------------------------
| Define which route to redirect to after a successful login
|--------------------------------------------------------------------------
*/
'redirect_route_after_login' => 'homepage',
/*
|--------------------------------------------------------------------------
| Define which route the user should be redirected to after accessing
| a resource that requires to be logged in
|--------------------------------------------------------------------------
*/
'redirect_route_not_logged_in' => 'auth/login',
/*
|--------------------------------------------------------------------------
| Login column(s)
|--------------------------------------------------------------------------
| Define which column(s) you'd like to use to login with, currently
| only supported by the Sentinel user driver
*/
'login-columns' => ['email'],
/*
|--------------------------------------------------------------------------
| Allow anonymous user registration
|--------------------------------------------------------------------------
*/
'allow_user_registration' => true,
/*
|--------------------------------------------------------------------------
| The default role for new user registrations
| Default: User
|--------------------------------------------------------------------------
*/
'default_role' => 'User',
/*
|--------------------------------------------------------------------------
| Fillable user fields
|--------------------------------------------------------------------------
| Set the fillable user fields, those fields will be mass assigned
*/
'fillable' => [
'email',
'password',
'permissions',
'first_name',
'last_name',
],
/*
|--------------------------------------------------------------------------
| Dynamic relations
|--------------------------------------------------------------------------
| Add relations that will be dynamically added to the User entity
*/
'relations' => [
// 'extension' => function ($self) {
// return $self->belongsTo(UserExtension::class, 'user_id', 'id')->first();
// }
],
/*
|--------------------------------------------------------------------------
| Custom Sidebar Class
|--------------------------------------------------------------------------
| If you want to customise the admin sidebar ordering or grouping
| You can define your own sidebar class for this module.
| No custom sidebar: null
*/
'custom-sidebar' => null,
];
21 changes: 21 additions & 0 deletions Modules/User/Config/permissions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

return [
'user.users' => [
'index' => 'user::users.list user',
'create' => 'user::users.create user',
'edit' => 'user::users.edit user',
'destroy' => 'user::users.destroy user',
],
'user.roles' => [
'index' => 'user::roles.list resource',
'create' => 'user::roles.create resource',
'edit' => 'user::roles.edit resource',
'destroy' => 'user::roles.destroy resource',
],
'account.api-keys' => [
'index' => 'user::users.list api key',
'create' => 'user::users.create api key',
'destroy' => 'user::users.destroy api key',
],
];
91 changes: 91 additions & 0 deletions Modules/User/Contracts/Authentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Modules\User\Contracts;

interface Authentication
{
/**
* Authenticate a user
* @param array $credentials
* @param bool $remember Remember the user
* @return mixed
*/
public function login(array $credentials, $remember = false);

/**
* Register a new user.
* @param array $user
* @return bool
*/
public function register(array $user);

/**
* Activate the given used id
* @param int $userId
* @param string $code
* @return mixed
*/
public function activate($userId, $code);

/**
* Assign a role to the given user.
* @param \Modules\User\Repositories\UserRepository $user
* @param \Modules\User\Repositories\RoleRepository $role
* @return mixed
*/
public function assignRole($user, $role);

/**
* Log the user out of the application.
* @return mixed
*/
public function logout();

/**
* Create an activation code for the given user
* @param $user
* @return mixed
*/
public function createActivation($user);

/**
* Create a reminders code for the given user
* @param $user
* @return mixed
*/
public function createReminderCode($user);

/**
* Completes the reset password process
* @param $user
* @param string $code
* @param string $password
* @return bool
*/
public function completeResetPassword($user, $code, $password);

/**
* Determines if the current user has access to given permission
* @param $permission
* @return bool
*/
public function hasAccess($permission);

/**
* Check if the user is logged in
* @return bool
*/
public function check();

/**
* Get the currently logged in user
* @return \Modules\User\Entities\UserInterface
*/
public function user();

/**
* Get the ID for the currently authenticated user
* @return int
*/
public function id();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateUserTokensTable extends Migration
{
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::create('user_tokens', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('access_token');
$table->timestamps();

$table->unique('access_token');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}

/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::drop('user_tokens');
}
}
Loading

0 comments on commit 7a96299

Please sign in to comment.