contract template endpoint

This commit is contained in:
glovetleong
2021-06-28 15:31:10 +08:00
parent 0be9350b30
commit ebdf9d57cc
16 changed files with 566 additions and 112 deletions
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace App\Http\Rules\User;
use Auth;
use App\Models\ContractTemplate;
use App\Http\Helpers\Hasher;
use Illuminate\Contracts\Validation\Rule;
class ExistCheck implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
private $type;
public function __construct($type = '')
{
$this->type = $type;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$this->attribute = $attribute;
$value = is_array($value) ? $value : [$value];
if ($this->type == 'contract_template') {
foreach ($value as $key => $row) {
if(!empty($row)) {
$id = Hasher::decode('contract_templates', $row);
$data = ContractTemplate::
where('id', $id)
->count();
if (!$data) {
return false;
}
}
}
}
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return config('error_code.exist_error');
}
}
-42
View File
@@ -60,48 +60,6 @@ class LoginRule implements Rule
return true;
}
}
// if ($this->type == 'social') {
// $social_media_type_id = $value;
// $provider_id = $this->password;
// $data = UserSocialAccount::
// where('social_media_type_id', $social_media_type_id)
// ->where('provider_id', $provider_id)
// ->whereHas('user', function($q) {
// $q->whereIn('status', [1]);
// })
// ->count();
// if (!$data) {
// return false;
// }
// return true;
// }
// if ($this->type == 'totp') {
// $social_media_type_id = $value;
// $provider_id = $this->password;
// $data = UserSocialAccount::
// where('social_media_type_id', $social_media_type_id)
// ->where('provider_id', $provider_id)
// ->count();
// if (!$data) {
// return false;
// }
// $totp = new TOTP(
// $social_media_type_id . $provider_id,
// env('TOTP_SECRET'),
// 100,
// 'sha512',
// 8
// );
// if (!$totp->verify($this->totp)) {
// return false;
// }
// return true;
// }
}
/**
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Http\Rules\User;
use Auth;
use App\Models\ContractTemplate;
use App\Http\Helpers\Hasher;
use Illuminate\Contracts\Validation\Rule;
class UnderCheck implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
private $type;
public function __construct($type = '')
{
$this->type = $type;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$this->attribute = $attribute;
$value = is_array($value) ? $value : [$value];
if ($this->type == 'contract_template') {
foreach ($value as $key => $row) {
if(!empty($row)) {
$id = Hasher::decode('contract_templates', $row);
$data = ContractTemplate::
where('id', $id)
->where('user_id', Auth::guard('user-api')->user()->id)
->count();
if (!$data) {
return false;
}
}
}
}
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return config('error_code.under_error');
}
}