api code global jain

This commit is contained in:
Abhishek Mali
2025-11-05 10:37:10 +05:30
commit 52fe7e2bec
2834 changed files with 1784903 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use App\Models\User;
class CheckUniqueEmailHashValue implements Rule
{
public $id;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($id = null)
{
$this->id = $id;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$hashed = md5($value);
$user = User::where('email_hash', $hashed);
if (isset($this->id) && !empty($this->id)) {
$user = $user->where('id', '!=', $this->id);
}
$user = $user->first();
if ($user === null) {
return true;
}
return false;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return trans('validation.unique', ['attribute' => 'email']);
}
}

56
app/Rules/DeleteVihar.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace App\Rules;
use App\Models\Vihar;
use Carbon\Carbon;
use Illuminate\Contracts\Validation\Rule;
class DeleteVihar implements Rule
{
public $sant_id;
public $start_date;
public $start_time;
public $vihar_id;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($vihar = null)
{
$this->sant_id = $vihar['sant_id'];
$this->start_date = $vihar['start_date'];
$this->start_time = $vihar['start_time'];
$this->vihar_id = $vihar['id'];
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$numberOfVihar = Vihar::where('id', $this->vihar_id)->where('start_time', '<=', Carbon::now()->format('H:i'))->count();
if ($numberOfVihar > 0) {
return false;
} else {
return true;
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Vihar is already started so you can`t delete it.';
}
}

252
app/Rules/Password.php Normal file
View File

@@ -0,0 +1,252 @@
<?php
namespace App\Rules;
use Illuminate\Container\Container;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Contracts\Validation\UncompromisedVerifier;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;
class Password implements Rule, DataAwareRule
{
/**
* The data under validation.
*
* @var array
*/
protected $data;
/**
* The minimum size of the password.
*
* @var int
*/
protected $min = 8;
/**
* If the password requires at least one uppercase and one lowercase letter.
*
* @var bool
*/
protected $mixedCase = true;
/**
* If the password requires at least one letter.
*
* @var bool
*/
protected $letters = false;
/**
* If the password requires at least one number.
*
* @var bool
*/
protected $numbers = true;
/**
* If the password requires at least one symbol.
*
* @var bool
*/
protected $symbols = true;
/**
* If the password should has not been compromised in data leaks.
*
* @var bool
*/
protected $uncompromised = false;
/**
* The number of times a password can appear in data leaks before being consider compromised.
*
* @var int
*/
protected $compromisedThreshold = 0;
/**
* The failure messages, if any.
*
* @var array
*/
protected $messages = [];
/**
* Create a new rule instance.
*
* @param int $min
* @return void
*/
public function __construct($min)
{
$this->min = max((int) $min, 1);
}
/**
* Set the data under validation.
*
* @param array $data
* @return $this
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
/**
* Sets the minimum size of the password.
*
* @param int $size
* @return $this
*/
public static function min($size)
{
return new static($size);
}
/**
* Ensures the password has not been compromised in data leaks.
*
* @param int $threshold
* @return $this
*/
public function uncompromised($threshold = 0)
{
$this->uncompromised = true;
$this->compromisedThreshold = $threshold;
return $this;
}
/**
* Makes the password require at least one uppercase and one lowercase letter.
*
* @return $this
*/
public function mixedCase()
{
$this->mixedCase = true;
return $this;
}
/**
* Makes the password require at least one letter.
*
* @return $this
*/
public function letters()
{
$this->letters = true;
return $this;
}
/**
* Makes the password require at least one number.
*
* @return $this
*/
public function numbers()
{
$this->numbers = true;
return $this;
}
/**
* Makes the password require at least one symbol.
*
* @return $this
*/
public function symbols()
{
$this->symbols = true;
return $this;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$validator = Validator::make($this->data, [
$attribute => 'string|min:'.$this->min,
]);
if ($validator->fails()) {
return $this->fail($validator->messages()->all());
}
$value = (string) $value;
if ($this->mixedCase && ! preg_match('/(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u', $value)) {
$this->fail('The :attribute must contain at least one uppercase and one lowercase letter.');
}
if ($this->letters && ! preg_match('/\pL/u', $value)) {
$this->fail('The :attribute must contain at least one letter.');
}
if ($this->symbols && ! preg_match('/\p{Z}|\p{S}|\p{P}/u', $value)) {
$this->fail('The :attribute must contain at least one symbol.');
}
if ($this->numbers && ! preg_match('/\pN/u', $value)) {
$this->fail('The :attribute must contain at least one number.');
}
if (! empty($this->messages)) {
return false;
}
if ($this->uncompromised && ! Container::getInstance()->make(UncompromisedVerifier::class)->verify([
'value' => $value,
'threshold' => $this->compromisedThreshold,
])) {
return $this->fail(
'The given :attribute has appeared in a data leak. Please choose a different :attribute.'
);
}
return true;
}
/**
* Get the validation error message.
*
* @return array
*/
public function message()
{
return $this->messages;
}
/**
* Adds the given failures, and return false.
*
* @param array|string $messages
* @return bool
*/
protected function fail($messages)
{
$messages = collect(Arr::wrap($messages))->map(function ($message) {
return __($message);
})->all();
$this->messages = array_merge($this->messages, $messages);
return false;
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use App\Models\Vihar;
use Carbon\Carbon;
class ViharCanNotAfterTwoHours implements Rule
{
public $sant_id;
public $start_date;
public $start_time;
public $vihar_id;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($data, $vihar_id = null)
{
$this->sant_id = $data['sant_id'];
$this->start_date = $data['start_date'];
$this->start_time = $data['start_time'];
$this->vihar_id = $vihar_id;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$santID = $this->sant_id;
$numberOfPosts = Vihar::where('sant_id', $this->sant_id)
// ->orWhere( function ($query) use ($santID) {
// return $query->whereHas('viharThana', function ($subQuery) use ($santID) {
// $subQuery->where('vihar_thanas.sant_id', $santID);
// })->orWhere('vihars.sant_id', $santID);
// })
->where('id', '<>', $this->vihar_id)
->where('start_date', $this->start_date)
->whereDate('created_at', Carbon::today())->count();
if ($numberOfPosts >= 1) {
$previousVihar = Vihar::where('sant_id', $this->sant_id)
->where('id', '<>', $this->vihar_id)
->where('start_date', $this->start_date)
->whereDate('created_at', Carbon::today())->first();
$previousTime = Carbon::createFromFormat('H:i', $previousVihar->start_time);
$nextViharTimeShoudBe = Carbon::createFromFormat('H:i', $previousVihar->start_time)->addHours(2);
$nextViharTimeActual = Carbon::createFromFormat('H:i', $this->start_time);
// Update time
if ($this->vihar_id) {
if ($previousVihar->id < $this->vihar_id) {
$result = $nextViharTimeActual->gt($nextViharTimeShoudBe);
if ($result) {
return true;
} else {
return false;
}
}
} else {
$result = $nextViharTimeActual->gt($nextViharTimeShoudBe);
if ($result) {
return true;
} else {
return false;
}
}
}
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Another Vihaar record can be entered only after 2 hours of current Vihaar.';
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use App\Models\Vihar;
use Carbon\Carbon;
class ViharDoesNotStoreForSameDateTime implements Rule
{
public $sant_id;
public $start_date;
public $start_time;
public $vihar_id;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($data, $vihar_id = null)
{
$this->sant_id = $data['sant_id'];
$this->start_date = $data['start_date'];
$this->start_time = $data['start_time'];
$this->vihar_id = $vihar_id;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$santID = $this->sant_id;
$numberOfPosts = Vihar::where('sant_id', $this->sant_id)
// ->orWhere( function ($query) use ($santID) {
// return $query->whereHas('viharThana', function ($subQuery) use ($santID) {
// $subQuery->where('vihar_thanas.sant_id', $santID);
// })->orWhere('vihars.sant_id', $santID);
// })
->where('id', '<>', $this->vihar_id)
->where('start_date', $this->start_date)
->where('start_time', $this->start_time)->whereDate('created_at', Carbon::today())->count();
if ($numberOfPosts > 0) {
return false;
} else {
return true;
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Vihaar already exists for this date and time.';
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use App\Models\Vihar;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class ViharStorePerDay implements Rule
{
public $sant_id;
public $vihar_id;
public $start_date;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($data, $vihar_id = null)
{
$this->sant_id = $data['sant_id'];
$this->vihar_id = $vihar_id;
$this->start_date = $data['start_date'];
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$santID = $this->sant_id;
$numberOfPosts = Vihar::where('sant_id', $this->sant_id)
// ->orWhere( function ($query) use ($santID) {
// return $query->whereHas('viharThana', function ($subQuery) use ($santID) {
// $subQuery->where('vihar_thanas.sant_id', $santID);
// })->orWhere('vihars.sant_id', $santID);
// })
->where('id', '<>', $this->vihar_id)
->whereDate('start_date', $this->start_date)
// ->whereDate('created_at', Carbon::today())
->count();
if ($numberOfPosts >= 2) {
return false;
} else {
return true;
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'Only 2 Vihaar`s can be added for any sant in a day';
}
}