Added validation to site with barebones error reporting to users
This commit is contained in:
parent
7af12d0f5b
commit
71c79d3b2a
17 changed files with 221 additions and 29 deletions
39
app/Http/Requests/StoreGroup.php
Normal file
39
app/Http/Requests/StoreGroup.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreGroup extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (Auth::user()->isAdministrator()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->isModerator()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
"name" => "required|string|alpha_dash|max:255",
|
||||
"enabled" => "boolean"
|
||||
];
|
||||
}
|
||||
}
|
40
app/Http/Requests/StoreOptions.php
Normal file
40
app/Http/Requests/StoreOptions.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreOptions extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (Auth::user()->isAdministrator()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->isModerator()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
"question_id" => "required|integer|exists:questions,id|min:1",
|
||||
"option" => "required|string|alpha_dash|max:255",
|
||||
"correct_answer" => "boolean"
|
||||
];
|
||||
}
|
||||
}
|
43
app/Http/Requests/StoreQuestion.php
Normal file
43
app/Http/Requests/StoreQuestion.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreQuestion extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (Auth::user()->isAdministrator()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->isModerator()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
"test_id" => "integer|exists:tests,id|min:1",
|
||||
"title" => "required|string|alpha_dash|max:255",
|
||||
"question" => "required|string|alpha_dash",
|
||||
"question_type" => "string|in:radio,checkbox|max:255",
|
||||
"correct_answers" => "integer|min:1",
|
||||
"multiple_anwsers_question" => "boolean"
|
||||
];
|
||||
}
|
||||
}
|
|
@ -32,11 +32,11 @@ class StoreTest extends FormRequest
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
"title" => "required|max:255|string",
|
||||
"question_count" => "required|numeric",
|
||||
"question_count_to_fail" => "numeric",
|
||||
"time_limit" => "numeric",
|
||||
"group_id" => "numeric"
|
||||
"title" => "required|string|alpha_dash|max:255",
|
||||
"question_count" => "required|integer|min:1",
|
||||
"question_count_to_fail" => "integer|min:0",
|
||||
"time_limit" => "integer|min:0",
|
||||
"group_id" => "integer|exists:groups,id|min:1"
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreUser extends FormRequest
|
||||
{
|
||||
|
@ -13,6 +14,13 @@ class StoreUser extends FormRequest
|
|||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (Auth::user()->isAdministrator()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Auth::user()->isModerator()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -24,7 +32,12 @@ class StoreUser extends FormRequest
|
|||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
"name" => "required|string|alpha_dash|max:255",
|
||||
"email" => "required|email|unique:users,email|max:255",
|
||||
"password" => "required|alpha_dash|min:8",
|
||||
"group_id" => "integer|exists:groups,id|min:1",
|
||||
"enabled" => "required|boolean",
|
||||
"access_level" => "integer|min:1",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue