Merge branch 'user_management' into authentication
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller as BaseController;
|
||||
use App\Http\Requests;
|
||||
|
||||
abstract class Controller extends BaseController
|
||||
{
|
||||
/**
|
||||
* Controller constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Requests;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class Dashboard extends Controller
|
||||
{
|
||||
//
|
||||
public function getIndex() {
|
||||
return view('admin.dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Requests\CreateNewUserRequest;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserManagement extends Controller
|
||||
{
|
||||
public function getNewUser()
|
||||
{
|
||||
// define list of roles, this list will be used in template for selecting proper role for user
|
||||
$roles = [
|
||||
User::ROLE_ADMIN => 'admin/userManagement.role_' . User::ROLE_ADMIN,
|
||||
User::ROLE_EDITOR => 'admin/userManagement.role_' . User::ROLE_EDITOR,
|
||||
User::ROLE_VISITOR => 'admin/userManagement.role_' . User::ROLE_VISITOR
|
||||
];
|
||||
|
||||
// render view
|
||||
return $this->view('admin.userManagement.new', ['roles' => $roles]);
|
||||
}
|
||||
|
||||
public function getEditExistingUser($id)
|
||||
{
|
||||
// try to find user
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
// render view
|
||||
return $this->view('admin.userManagement.edit', ['user' => $user]);
|
||||
}
|
||||
|
||||
public function getOverview($state = null)
|
||||
{
|
||||
echo $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new user
|
||||
*
|
||||
* This method saves new user into database
|
||||
*
|
||||
* @param CreateNewUserRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function postRegistration(CreateNewUserRequest $request)
|
||||
{
|
||||
// when user did not provide any username, use his email
|
||||
$username = isset($request->username) && !empty($request->username) ? $request->username : $request->email;
|
||||
|
||||
// create new user
|
||||
$user = new User();
|
||||
$user->name = $request->name;
|
||||
$user->email = $request->email;
|
||||
$user->username = $username;
|
||||
$user->role = $request->role;
|
||||
$user->password = Hash::make($request->password);
|
||||
|
||||
// store user into database
|
||||
$user->save();
|
||||
|
||||
// refresh page with information about successfull registration
|
||||
return redirect()
|
||||
->route('users.new')
|
||||
->with('message', trans('admin/userManagement.registrationSuccessfull'));
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,21 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/**
|
||||
* Custom wrapper for generating view.
|
||||
*
|
||||
* This method will be used for switching among templates.
|
||||
*
|
||||
* @todo add template support
|
||||
*
|
||||
* @param null $view
|
||||
* @param array $data
|
||||
* @param array $mergeData
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
protected function view($view = null, $data = [], $mergeData = []) {
|
||||
return view($view, $data, $mergeData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ class Authenticate
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
if (!Auth::check($guard)) {
|
||||
if ($request->ajax()) {
|
||||
return response('Unauthorized.', 401);
|
||||
} else {
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\User;
|
||||
|
||||
class CreateNewUserRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
|
||||
return \Auth::check() && \Auth::$user->role == User::ROLE_ADMIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'role' => 'required',
|
||||
'email' => 'required|email|max:128|unique:users',
|
||||
'password' => 'required|min:6'
|
||||
];
|
||||
}
|
||||
}
|
||||
+8
-23
@@ -1,27 +1,8 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Routes File
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you will register all of the routes in an application.
|
||||
| It's a breeze. Simply tell Laravel the URIs it should respond to
|
||||
| and give it the controller to call when that URI is requested.
|
||||
|
|
||||
*/
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This route group applies the "web" middleware group to every route
|
||||
| it contains. The "web" middleware group is defined in your HTTP
|
||||
| kernel and includes session state, CSRF protection, and more.
|
||||
|
|
||||
*/
|
||||
|
||||
/**
|
||||
* This routing groups is used for routing along public part of website
|
||||
*/
|
||||
Route::group(['middleware' => ['web']], function () {
|
||||
Route::get('login', 'Admin\Login@getLoginForm')
|
||||
->name('loginForm');
|
||||
@@ -32,7 +13,11 @@ Route::group(['middleware' => ['web']], function () {
|
||||
->name('login');
|
||||
});
|
||||
|
||||
// list of admin routes
|
||||
/*******************************************************************************/
|
||||
|
||||
/**
|
||||
* This route group serves to handle request in admin
|
||||
*/
|
||||
Route::group([
|
||||
// 'middleware' => ['auth'],
|
||||
'namespace' => 'Admin',
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace App\MenuPresenters;
|
||||
|
||||
use Pingpong\Menus\Presenters\Presenter;
|
||||
|
||||
class FoundationMenuPresenter extends Presenter
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc }
|
||||
*/
|
||||
public function getOpenTagWrapper()
|
||||
{
|
||||
return PHP_EOL . '<ul class="vertical menu-bar icon-left">' . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc }
|
||||
*/
|
||||
public function getCloseTagWrapper()
|
||||
{
|
||||
return PHP_EOL . '</ul>' . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc }
|
||||
*/
|
||||
public function getMenuWithoutDropdownWrapper($item)
|
||||
{
|
||||
return '<li'.$this->getActiveState($item).'><a href="'. $item->getUrl() .'">'.$item->getIcon().' '.$item->title.'</a></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc }
|
||||
*/
|
||||
public function getActiveState($item)
|
||||
{
|
||||
return \Request::is($item->getRequest()) ? ' class="active"' : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc }
|
||||
*/
|
||||
public function getDividerWrapper()
|
||||
{
|
||||
return '<li class="divider"></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc }
|
||||
*/
|
||||
public function getMenuWithDropDownWrapper($item)
|
||||
{
|
||||
return '<li class="has-dropdown">
|
||||
<a href="#">
|
||||
'.$item->getIcon().' '.$item->title.'
|
||||
</a>
|
||||
<ul class="dropdown">
|
||||
'.$this->getChildMenuItems($item).'
|
||||
</ul>
|
||||
</li>' . PHP_EOL;
|
||||
;
|
||||
}
|
||||
}
|
||||
+25
-1
@@ -14,6 +14,7 @@ use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
class User extends Model implements AuthenticableInterface
|
||||
{
|
||||
use Authenticatable, Authorizable, CanResetPassword;
|
||||
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'email',
|
||||
@@ -31,4 +32,27 @@ class User extends Model implements AuthenticableInterface
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
}
|
||||
|
||||
const STATE_DELETED = 'deleted';
|
||||
const STATE_BLOCKED = 'blocked';
|
||||
const STATE_ACTIVE = 'active';
|
||||
const ROLE_VISITOR = 'visitor';
|
||||
const ROLE_EDITOR = 'editor';
|
||||
const ROLE_ADMIN = 'admin';
|
||||
|
||||
/**
|
||||
* Validation method for input data
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public static function validate(array $data)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
if (!$valid) {
|
||||
throw new ValidationException(Validator::class, 'Invalid request');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AdminProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// create instance of main menu
|
||||
\Menu::create('mainMenu', function ($menu) {
|
||||
/**
|
||||
* @var $menu \Pingpong\Menus\MenuBuilder
|
||||
*/
|
||||
|
||||
// create menu entries
|
||||
|
||||
/*
|
||||
* WARNING: MenuBuilder::route() does not seem to work,
|
||||
* nor route() helper function. We need to use action() helper instaed.
|
||||
*/
|
||||
$menu->url(action('Admin\Dashboard@getIndex'), trans('admin/mainMenu.dashboard'), 1, ['icon' => 'fa fa-dashboard']);
|
||||
$menu->dropdown(trans('admin/mainMenu.userManagement'), function($sub) {
|
||||
$sub->url(action('Admin\UserManagement@getNewUser'), trans('admin/mainMenu.newUser'), 1, ['icon' => 'fa fa-user-plus']);
|
||||
$sub->url(action('Admin\UserManagement@getOverview', ['state' => 'all']), trans('admin/mainMenu.usersOverview'), 2, ['icon' => 'fa fa-users']);
|
||||
|
||||
}, ['icon' => 'fa fa-users']);
|
||||
});
|
||||
|
||||
// create menu with user profile
|
||||
\Menu::create('profileMenu', function ($menu) {
|
||||
// @todo add profile menu
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
$this->app->register('Iber\Generator\ModelGeneratorProvider');
|
||||
}
|
||||
|
||||
// register PingPong module extension
|
||||
$this->app->register('Pingpong\Modules\ModulesServiceProvider');
|
||||
$this->app->register('Pingpong\Menus\MenusServiceProvider');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user