First complete upload CasaDoc
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth;
|
||||
|
||||
class ApiLoginRequest extends LoginRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return array_merge(parent::rules(), [
|
||||
'device_name' => 'required',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the needed authorization credentials from the request.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
$credentials = parent::getCredentials();
|
||||
|
||||
unset($credentials['password']);
|
||||
|
||||
return $credentials;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth;
|
||||
|
||||
class ApiVerifyEmailRequest extends LoginRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'id' => 'required',
|
||||
'hash' => 'required',
|
||||
'expires' => 'required',
|
||||
'signature' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||
|
||||
class LoginRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'username' => 'required',
|
||||
'password' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the needed authorization credentials from the request.
|
||||
*
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
// The form field for providing username or password
|
||||
// have name of "username", however, in order to support
|
||||
// logging users in with both (username and email)
|
||||
// we have to check if user has entered one or another
|
||||
$username = $this->get('username');
|
||||
|
||||
if ($this->isEmail($username)) {
|
||||
return [
|
||||
'email' => $username,
|
||||
'password' => $this->get('password')
|
||||
];
|
||||
}
|
||||
|
||||
return $this->only('username', 'password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if provided parameter is valid email.
|
||||
*
|
||||
* @param $param
|
||||
* @return bool
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
private function isEmail($param)
|
||||
{
|
||||
$factory = $this->container->make(ValidationFactory::class);
|
||||
|
||||
return ! $factory->make(
|
||||
['username' => $param],
|
||||
['username' => 'email']
|
||||
)->fails();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class PasswordRemindRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email|exists:users,email',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class PasswordResetRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'token' => 'required',
|
||||
'email' => 'required|email',
|
||||
'password' => 'required|confirmed|min:8'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password reset fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function credentials()
|
||||
{
|
||||
return $this->only('email', 'password', 'password_confirmation', 'token');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\Support\Enum\UserStatus;
|
||||
|
||||
class RegisterRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'username' => 'required|unique:users,username',
|
||||
'password' => 'required|confirmed|min:8',
|
||||
];
|
||||
|
||||
if (setting('registration.captcha.enabled')) {
|
||||
$rules['g-recaptcha-response'] = 'required|captcha';
|
||||
}
|
||||
|
||||
if (setting('tos')) {
|
||||
$rules['tos'] = 'accepted';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'tos.accepted' => __('You have to accept Terms of Service.')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the valid request data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validFormData()
|
||||
{
|
||||
// Determine user status. User's status will be set to UNCONFIRMED
|
||||
// if he has to confirm his email or to ACTIVE if email confirmation is not required
|
||||
$status = setting('reg_email_confirmation')
|
||||
? UserStatus::UNCONFIRMED
|
||||
: UserStatus::ACTIVE;
|
||||
|
||||
return array_merge($this->only('email', 'username', 'password'), [
|
||||
'status' => $status,
|
||||
'email_verified_at' => setting('reg_email_confirmation') ? null : now()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth\Social;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class ApiAuthenticateRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'network' => [
|
||||
'required',
|
||||
Rule::in(config('auth.social.providers'))
|
||||
],
|
||||
'social_token' => 'required',
|
||||
'device_name' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Auth\Social;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class SaveEmailRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email|unique:users,email',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Permission;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BasePermissionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Validation messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'name.unique' => __('Permission with this name already exists.')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Permission;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Vanguard\Rules\ValidPermissionName;
|
||||
|
||||
class CreatePermissionRequest extends BasePermissionRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
new ValidPermissionName,
|
||||
Rule::unique('permissions', 'name')
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Permission;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class RemovePermissionRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return $this->route('permission')->removable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Permission;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Vanguard\Rules\ValidPermissionName;
|
||||
|
||||
class UpdatePermissionRequest extends BasePermissionRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
new ValidPermissionName,
|
||||
Rule::unique('permissions', 'name')->ignore($this->route('permission')->id)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
abstract class Request extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Role;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class CreateRoleRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|regex:/^[a-zA-Z0-9\-_\.]+$/|unique:roles,name'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Role;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class RemoveRoleRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return $this->route('role')->removable;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Role;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\Permission;
|
||||
|
||||
class UpdateRolePermissionsRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$permissions = Permission::pluck('id')->toArray();
|
||||
|
||||
return [
|
||||
'permissions' => 'required|array',
|
||||
'permissions.*' => Rule::in($permissions)
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'permissions.*' => 'Provided permission does not exist.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\Role;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class UpdateRoleRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$role = $this->route('role');
|
||||
|
||||
return [
|
||||
'name' => 'required|regex:/^[a-zA-Z0-9\-_\.]+$/|unique:roles,name,' . $role->id
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\TwoFactor;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\Repositories\User\UserRepository;
|
||||
use Vanguard\User;
|
||||
|
||||
class DisableTwoFactorRequest extends TwoFactorRequest
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\TwoFactor;
|
||||
|
||||
class EnableTwoFactorRequest extends TwoFactorRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'country_code' => 'required|numeric|integer',
|
||||
'phone_number' => 'required|numeric',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\TwoFactor;
|
||||
|
||||
class ReSendTwoFactorTokenRequest extends TwoFactorRequest
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\TwoFactor;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\Repositories\User\UserRepository;
|
||||
|
||||
abstract class TwoFactorRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Authorize the request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if ($userId = $this->get('user')) {
|
||||
// Only users with "users.manage" permission can enable 2FA for other users.
|
||||
return $this->user()->hasPermission('users.manage') || $this->user()->id == $userId;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user for which we should enable the 2FA.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function theUser()
|
||||
{
|
||||
if ($userId = $this->get('user')) {
|
||||
return app(UserRepository::class)->find($userId);
|
||||
}
|
||||
|
||||
return $this->user();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\TwoFactor;
|
||||
|
||||
class VerifyTwoFactorTokenRequest extends TwoFactorRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'token' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\User;
|
||||
|
||||
class CreateUserRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'username' => 'nullable|unique:users,username',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
'birthday' => 'nullable|date',
|
||||
'role_id' => 'required|exists:roles,id',
|
||||
'verified' => 'boolean'
|
||||
];
|
||||
|
||||
if ($this->get('country_id')) {
|
||||
$rules += ['country_id' => 'exists:countries,id'];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\User;
|
||||
|
||||
class UpdateDetailsRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'birthday' => 'nullable|date',
|
||||
'role_id' => 'required|exists:roles,id'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\User;
|
||||
|
||||
class UpdateLoginDetailsRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$user = $this->getUserForUpdate();
|
||||
|
||||
return [
|
||||
'email' => 'required|email|unique:users,email,' . $user->id,
|
||||
'username' => 'nullable|unique:users,username,' . $user->id,
|
||||
'password' => 'nullable|min:8|confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Routing\Route|object|string
|
||||
*/
|
||||
protected function getUserForUpdate()
|
||||
{
|
||||
return $this->route('user');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\User;
|
||||
|
||||
class UpdateProfileDetailsRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'birthday' => 'nullable|date',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
class UpdateProfileLoginDetailsRequest extends UpdateLoginDetailsRequest
|
||||
{
|
||||
/**
|
||||
* Get authenticated user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getUserForUpdate()
|
||||
{
|
||||
return \Auth::user();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Vanguard\Http\Requests\Request;
|
||||
use Vanguard\Support\Enum\UserStatus;
|
||||
use Vanguard\User;
|
||||
|
||||
class UpdateUserRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
return [
|
||||
'email' => 'email|unique:users,email,' . $user->id,
|
||||
'username' => 'nullable|unique:users,username,' . $user->id,
|
||||
'password' => 'min:6|confirmed',
|
||||
'birthday' => 'nullable|date',
|
||||
'role_id' => 'exists:roles,id',
|
||||
'country_id' => 'exists:countries,id',
|
||||
'status' => Rule::in(array_keys(UserStatus::lists()))
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Vanguard\Http\Requests\User;
|
||||
|
||||
use Vanguard\Http\Requests\Request;
|
||||
|
||||
class UploadAvatarRawRequest extends Request
|
||||
{
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'file' => 'required|image'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user