38 lines
948 B
PHP
38 lines
948 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Auth;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class LoginRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
$user = User::query()->where('telephone_id', '=', $this->telephone_id)->first();
|
|
if ($user && $user->is_online === 1) {
|
|
return false;
|
|
}
|
|
$user->update(['telephone_id' => null]);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'username' => 'required|exists:users,username',
|
|
'password' => 'required|string',
|
|
'telephone_id' => 'required|string'
|
|
];
|
|
}
|
|
}
|