Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/php-soft/laravel-users.svg)](https://travis-ci.org/php-soft/laravel-users)

> This module is use JWTAuth and ENTRUST libraries
>
>
> 1. https://github.com/tymondesigns/jwt-auth (JSON Web Token)
> 2. https://github.com/Zizaco/entrust (Role-based Permissions)

Expand Down Expand Up @@ -41,6 +41,15 @@ Next, also in the `app.php` config file, under the `aliases` array, you may want
]
```

You need to define namespace to your User model in the `phpsoft.user.php` config file, default with 'App\User'.

```php
'aliases' => [
// ...
'model' => 'App\User',
]
```

You will want to publish the config using the following command:

```sh
Expand Down Expand Up @@ -111,7 +120,7 @@ class User extends PhpSoftUser implements AuthenticatableContract, CanResetPassw

// ...
}
```
```

Remove middlewares in `app/Http/Kernel.php`

Expand Down Expand Up @@ -230,14 +239,14 @@ $user->can(['edit-user', 'create-post']); // true

### 3.3 Forgot password

To send mail forgot password,
To send mail forgot password,
- You need to add address and name of sender in `config\mail.php` as follows:

```php
'from' => ['address' => 'no-reply@example.com', 'name' => 'System'],
```

- You need to create email view:
- You need to create email view:
Create `password.blade.php` file in folder `resources\views\emails` with contents as follows:

```php
Expand Down Expand Up @@ -298,7 +307,7 @@ protected $routeMiddleware = [
Usage

```php
Route::group(['middleware'=>'routePermission'], function() {
Route::group(['middleware'=>'routePermission'], function() {
Route::post('/blog', function () {
//
});
Expand Down Expand Up @@ -358,7 +367,7 @@ class UserValidate implements Validator
{
/**
* Custom validator
*
*
* @return boolean
*/
public static function boot($request)
Expand All @@ -373,7 +382,7 @@ class UserValidate implements Validator

/**
* Declare rules
*
*
* @return array
*/
public static function rules()
Expand All @@ -386,4 +395,4 @@ class UserValidate implements Validator
}
}
```
Here, you will declare fields that you want to validate them in `rules()` function. And You can also custom validator fields that you want by declare them in `boot()` function.
Here, you will declare fields that you want to validate them in `rules()` function. And You can also custom validator fields that you want by declare them in `boot()` function.
44 changes: 33 additions & 11 deletions packages/Users/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

namespace PhpSoft\Users\Controllers;

use Input;
use Auth;
use Config;
use Input;
use JWTAuth;
use Validator;
use App\User as AppUser;
use Illuminate\Http\Request;
use PhpSoft\Users\Models\Role;
use PhpSoft\Users\Models\User;

class UserController extends Controller
{
private $userModel;

public function __construct()
{
$this->userModel = config('phpsoft.users.model');
}

/**
* Display the specified resource.
*
Expand Down Expand Up @@ -85,7 +92,8 @@ public function store(Request $request)
]), 400);
}

$user = AppUser::create($request->all());
$userModel = $this->userModel;
$user = $userModel::create($request->all());

return response()->json(arrayView('phpsoft.users::user/read', [
'user' => $user
Expand Down Expand Up @@ -138,8 +146,10 @@ public function update(Request $request, $id = null)
]), 400);
}

// Update profile
$user = $user->update($request->all());
$userModel = $this->userModel;

// check user
$user = $id ? $userModel::find($id) : Auth::user();

if (!$user) {
return response()->json(null, 500); // @codeCoverageIgnore
Expand All @@ -157,8 +167,10 @@ public function update(Request $request, $id = null)
*/
public function destroy($id)
{
$userModel = $this->userModel;

// get user by id
$user = AppUser::find($id);
$user = $userModel::find($id);

if (!$user) {
return response()->json(null, 404);
Expand All @@ -181,8 +193,10 @@ public function destroy($id)
*/
public function show($id)
{
$userModel = $this->userModel;

// get user by id
$user = AppUser::find($id);
$user = $userModel::find($id);

if (!$user) {
return response()->json(null, 404);
Expand All @@ -199,7 +213,9 @@ public function show($id)
*/
public function index(Request $request)
{
$users = AppUser::browse([
$userModel = $this->userModel;

$users = $userModel::browse([
'order' => [ Input::get('sort', 'id') => Input::get('direction', 'desc') ],
'limit' => ($limit = (int)Input::get('limit', 25)),
'cursor' => Input::get('cursor'),
Expand All @@ -220,7 +236,9 @@ public function index(Request $request)
*/
public function block($id)
{
$user = AppUser::find($id);
$userModel = $this->userModel;

$user = $userModel::find($id);

if (!$user) {
return response()->json(null, 404);
Expand All @@ -245,7 +263,9 @@ public function block($id)
*/
public function unblock($id)
{
$user = AppUser::find($id);
$userModel = $this->userModel;

$user = $userModel::find($id);

if (!$user) {
return response()->json(null, 404);
Expand All @@ -270,7 +290,9 @@ public function unblock($id)
*/
public function assignRole($id, Request $request)
{
$user = AppUser::find($id);
$userModel = $this->userModel;

$user = $userModel::find($id);

if (!$user) {
return response()->json(null, 404);
Expand Down
9 changes: 6 additions & 3 deletions packages/Users/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhpSoft\Users\Models;

use App\User as AppUser;
use Config;
use Illuminate\Database\Eloquent\Model;
use PhpSoft\Users\Models\Role;

Expand Down Expand Up @@ -55,9 +55,10 @@ class User extends Model
*/
public static function create(array $attributes = [])
{
$userModel = config('phpsoft.users.model');
$attributes['password'] = bcrypt($attributes['password']);

$user = new AppUser($attributes);
$user = new $userModel($attributes);
$user->save();

return $user;
Expand Down Expand Up @@ -93,7 +94,9 @@ public function update(array $attributes = [])
*/
public static function browse($options = [])
{
$find = new AppUser();
$userModel = config('phpsoft.users.model');

$find = new $userModel;
$fillable = $find->fillable;

if (!empty($options['filters'])) {
Expand Down
5 changes: 5 additions & 0 deletions packages/Users/Providers/UserServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function boot()
$this->publishes([
__DIR__ . '/../config/jwt.php' => config_path('jwt.php'),
__DIR__ . '/../config/entrust.php' => config_path('entrust.php'),
__DIR__ . '/../config/phpsoft.users.php' => config_path('phpsoft.users.php'),
]);

// Register commands
Expand All @@ -37,6 +38,10 @@ public function boot()
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__ . '/../config/phpsoft.users.php', 'phpsoft.users'
);

$this->registerCommands();
}

Expand Down
17 changes: 17 additions & 0 deletions packages/Users/config/phpsoft.users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| User Model namespace
|--------------------------------------------------------------------------
|
| Specify the full namespace to your User model.
| e.g. 'Acme\Entities\User'
|
*/

'model' => 'App\User',

];
Binary file modified storage/database.sqlite
Binary file not shown.