added routing for mod section and put admin/mod uri selection into a function to one view can be used for both
This commit is contained in:
parent
3569d1909b
commit
40992d676a
19 changed files with 80 additions and 45 deletions
app
resources/views
admin
mod
tests
users
routes
|
@ -3,7 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Requests;
|
||||
|
||||
class ModeratorController extends Controller
|
||||
|
@ -20,7 +20,7 @@ class ModeratorController extends Controller
|
|||
|
||||
public function showUsers()
|
||||
{
|
||||
$users = Auth::user()->group()->getGroupUsers();
|
||||
$users = Auth::user()->group->getGroupUsers();
|
||||
return view('users.showall', compact('users'));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class UserController extends Controller
|
|||
*/
|
||||
public function confirmDeleteUser(User $user)
|
||||
{
|
||||
return view('user.delete', compact('user'));
|
||||
return view('users.delete', compact('user'));
|
||||
}
|
||||
|
||||
public function deleteUser(User $user)
|
||||
|
|
|
@ -27,4 +27,9 @@ class AuthServiceProvider extends ServiceProvider
|
|||
|
||||
//
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return "mod";
|
||||
}
|
||||
}
|
||||
|
|
13
app/User.php
13
app/User.php
|
@ -85,12 +85,12 @@ class User extends Authenticatable
|
|||
$this->name = $request["name"];
|
||||
$this->email = $request["email"];
|
||||
$this->passwordHash($request["password"]);
|
||||
$this->enabled = $request["enabled"];
|
||||
if (Auth::user()->isModerator()) {
|
||||
Group::find(Auth::user()->group_id)->tests()->save($this);
|
||||
return true;
|
||||
}
|
||||
$this->group_id = $request["group_id"];
|
||||
$this->enabled = $request["enabled"];
|
||||
$this->save();
|
||||
return true;
|
||||
}
|
||||
|
@ -239,4 +239,15 @@ class User extends Authenticatable
|
|||
$testdetails->update();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getAdminPath()
|
||||
{
|
||||
if ($this->isModerator()) {
|
||||
return "mod";
|
||||
}
|
||||
|
||||
if ($this->isAdministrator()) {
|
||||
return "admin";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,9 +18,9 @@
|
|||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
@if (request()->path() == "admin/tests")
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/tests/all">Show</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/all">Show</button>
|
||||
@elseif (request()->path() == "admin/users")
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/users/all">Show</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/users/all">Show</button>
|
||||
@endif
|
||||
</form>
|
||||
</td>
|
||||
|
@ -32,9 +32,9 @@
|
|||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
@if (request()->path() == "admin/tests")
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/tests/group/{{ $group->id }}">Show</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/group/{{ $group->id }}">Show</button>
|
||||
@elseif (request()->path() == "admin/users")
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/users/group/{{ $group->id }}">Show</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/users/group/{{ $group->id }}">Show</button>
|
||||
@endif
|
||||
</form>
|
||||
</td>
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<div class="panel-heading">Tests</div>
|
||||
<div class="panel-body">
|
||||
<form method="get">
|
||||
<button formaction="/admin/tests" class="btn btn-default">Show Tests</button>
|
||||
<button formaction="/admin/tests/new" class="btn btn-default">New Test</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/tests" class="btn btn-default">Show Tests</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/tests/new" class="btn btn-default">New Test</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -16,8 +16,8 @@
|
|||
<div class="panel-heading">Users</div>
|
||||
<div class="panel-body">
|
||||
<form method="get">
|
||||
<button formaction="/admin/users" class="btn btn-default">Show Users</button>
|
||||
<button formaction="/admin/users/new" class="btn btn-default">New User</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/users" class="btn btn-default">Show Users</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/users/new" class="btn btn-default">New User</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@extends('layouts.base')
|
||||
|
||||
@section('content')
|
||||
<div class="container-fluid">
|
||||
<div class="col-md-4 col-md-offset-4">
|
||||
|
@ -7,8 +6,8 @@
|
|||
<div class="panel-heading">Tests</div>
|
||||
<div class="panel-body">
|
||||
<form method="get">
|
||||
<button formaction="/admin/tests" class="btn btn-default">Show Tests</button>
|
||||
<button formaction="/admin/tests/new" class="btn btn-default">New Test</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/tests" class="btn btn-default">Show Tests</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/tests/new" class="btn btn-default">New Test</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -16,8 +15,8 @@
|
|||
<div class="panel-heading">Users</div>
|
||||
<div class="panel-body">
|
||||
<form method="get">
|
||||
<button formaction="/admin/users" class="btn btn-default">Show Users</button>
|
||||
<button formaction="/admin/users/new" class="btn btn-default">New User</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/users" class="btn btn-default">Show Users</button>
|
||||
<button formaction="/{{ Auth::user()->getAdminPath() }}/users/new" class="btn btn-default">New User</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Are you Sure!</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/tests/{{ $test->id }}/delete">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
<button type="submit" class="btn btn-default">Yes</button>
|
||||
</form>
|
||||
<form method="GET" action="/admin/tests">
|
||||
<form method="GET" action="/{{ Auth::user()->getAdminPath() }}/tests">
|
||||
<button type="submit" class="btn btn-default">No</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Edit Test: {{ $test->title }}</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/tests/{{ $test->id }}/edit">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/edit">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('PATCH') }}
|
||||
<div class="form-group">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Create New Test</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/tests/new">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/tests/new">
|
||||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Are you Sure!</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/questions/{{ $question->id }}">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
<button type="submit" class="btn btn-default">Yes</button>
|
||||
</form>
|
||||
<form method="GET" action="/admin/tests">
|
||||
<form method="GET" action="/{{ Auth::user()->getAdminPath() }}/tests">
|
||||
<button type="submit" class="btn btn-default">No</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Edit User</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/questions/{{ $question->id }}">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('PATCH') }}
|
||||
<div class="form-group">
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Question {{ $question_number }}</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/tests/{{ $test->id }}/question">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/question">
|
||||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<div class="panel-heading">Test</div>
|
||||
<div class="panel-body">
|
||||
<form method="get">
|
||||
<button class="btn btn-default pull-right" formaction="/admin/tests/{{ $test->id }}/delete">Delete</button>
|
||||
<button class="btn btn-default pull-right" formaction="/admin/tests/{{ $test->id }}/edit">Edit</button>
|
||||
<button class="btn btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">Delete</button>
|
||||
<button class="btn btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/edit">Edit</button>
|
||||
</form>
|
||||
<strong>Title:</strong><br>
|
||||
{{ $test->title }}
|
||||
|
@ -33,7 +33,7 @@
|
|||
<th>Question</th>
|
||||
<th>
|
||||
<form method="get">
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/admin/tests/{{ $test->id }}/question">Add Question</button>
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/question">Add Question</button>
|
||||
</form>
|
||||
</th>
|
||||
</tr>
|
||||
|
@ -43,8 +43,8 @@
|
|||
<td>{{ $question->question }}</td>
|
||||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/questions/{{ $question->id }}/edit">Edit</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/questions/{{ $question->id }}/delete">Delete</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}/edit">Edit</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/questions/{{ $question->id }}/delete">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<th>Test</th>
|
||||
<th>
|
||||
<form method="get">
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/admin/tests/new">Add Test</button>
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/tests/new">Add Test</button>
|
||||
</form>
|
||||
</th>
|
||||
</tr>
|
||||
|
@ -24,8 +24,8 @@
|
|||
@if (Auth::user()->access_level == 2 AND !$test->group_id == 0 OR Auth::user()->access_level == 3)
|
||||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/tests/{{ $test->id }}">Edit</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/tests/{{ $test->id }}/delete">Delete</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}">Edit</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/tests/{{ $test->id }}/delete">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
@endif
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Are you Sure!</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/users/{{ $user->id }}">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
<button type="submit" class="btn btn-default">Yes</button>
|
||||
</form>
|
||||
<form method="GET" action="/admin/users">
|
||||
<form method="GET" action="/{{ Auth::user()->getAdminPath() }}/users">
|
||||
<button type="submit" class="btn btn-default">No</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="col-md-4 col-md-offset-4">
|
||||
<h1>Create New User</h1>
|
||||
</br>
|
||||
<form method="POST" action="/admin/users/new">
|
||||
<form method="POST" action="/{{ Auth::user()->getAdminPath() }}/users/new">
|
||||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
|
@ -19,6 +19,13 @@
|
|||
<label>Password</label>
|
||||
<input type="password" class="form-control" name="password">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Enabled</label>
|
||||
<select class="form-control">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</select>
|
||||
</div>
|
||||
@if (Auth::user()->isAdministrator())
|
||||
<div class="form-group">
|
||||
<label>Group</label>
|
||||
|
@ -28,13 +35,6 @@
|
|||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Enabled</label>
|
||||
<select class="form-control">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
</select>
|
||||
</div>
|
||||
@endif
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</form>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<th>User</th>
|
||||
<th>
|
||||
<form method="get">
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/admin/users/new">Add User</button>
|
||||
<button class="btn btn-sm btn-default pull-right" formaction="/{{ Auth::user()->getAdminPath() }}/users/new">Add User</button>
|
||||
</form>
|
||||
</th>
|
||||
</tr>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<td>{{ $user->name }} ({{ $user->email }})</td>
|
||||
<td>
|
||||
<form method="get" class="pull-right">
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/admin/users/{{ $user->id }}/delete">Delete</button>
|
||||
<button class="btn btn-sm btn-default pull-left" formaction="/{{ Auth::user()->getAdminPath() }}/users/{{ $user->id }}/delete">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -39,7 +39,27 @@ Route::group(['prefix' => 'test'], function () {
|
|||
Route::group(['prefix' => 'mod'], function () {
|
||||
|
||||
Route::get('/', 'ModeratorController@index');
|
||||
Route::get('/tests', 'ModeratorController@showTests');
|
||||
Route::get('/tests/new', 'TestController@newTest');
|
||||
Route::post('/tests/new', 'TestController@addTest');
|
||||
Route::get('/tests/{test}', 'TestController@showTest');
|
||||
Route::get('/tests/{test}/edit', 'TestController@editTest');
|
||||
Route::patch('/tests/{test}/edit', 'TestController@updateTest');
|
||||
Route::get('/tests/{test}/delete', 'TestController@confirmDeleteTest');
|
||||
Route::delete('/tests/{test}/delete', 'TestController@deleteTest');
|
||||
Route::get('/tests/{test}/question', 'TestController@newQuestion');
|
||||
Route::post('/tests/{test}/question', 'TestController@addQuestion');
|
||||
Route::get('/questions/{question}/edit', 'TestController@editQuestion');
|
||||
Route::patch('/questions/{question}', 'TestController@updateQuestion');
|
||||
Route::get('/questions/{question}/delete', 'TestController@confirmDeleteQuestion');
|
||||
Route::delete('/questions/{question}/', 'TestController@deleteQuestion');
|
||||
|
||||
|
||||
Route::get('/users', 'ModeratorController@showUsers');
|
||||
Route::get('/users/new', 'UserController@newUser');
|
||||
Route::post('/users/new', 'UserController@addUser');
|
||||
Route::get('/users/{user}/delete', 'UserController@confirmDeleteUser');
|
||||
Route::delete('/users/{user}', 'UserController@deleteUser');
|
||||
});
|
||||
|
||||
/*---------- Routes for the administrator section ----------*/
|
||||
|
|
Reference in a new issue