Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ yarn-error.log
/.vscode
/.docker
.DS_Store
config/app.php
app/Http/Requests/RegisterRequest.php
public/build/manifest.json
public/build/assets/app-8a9a9028.js
.gitignore
tests/Feature/CriteriaMountTest.php
public/build/manifest.json

43 changes: 21 additions & 22 deletions app/Http/Requests/RegisterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class RegisterRequest extends FormRequest
{
Expand All @@ -23,42 +21,43 @@ public function rules(): array
'username' => 'required|max:255|min:2',
'password' => 'required|min:5|max:255',
'terms' => 'required',
'g-recaptcha-response' => 'required', // Campo do reCAPTCHA
// 'g-recaptcha-response' => 'required', // Campo do reCAPTCHA desativado
];
}

public function messages(): array
{
return [
'g-recaptcha-response.required' => 'A verificação de reCAPTCHA é necessária.',
// 'g-recaptcha-response.required' => 'A verificação de reCAPTCHA é necessária.', // Mensagem desativada
];
}

public function withValidator($validator)
{
$validator->after(function ($validator) {
if (!$this->validateRecaptcha()) {
$validator->errors()->add('g-recaptcha-response', 'Falha na verificação do reCAPTCHA. Tente novamente.');
}
// Validação do reCAPTCHA desativada
// if (!$this->validateRecaptcha()) {
// $validator->errors()->add('g-recaptcha-response', 'Falha na verificação do reCAPTCHA. Tente novamente.');
// }
});
}

private function validateRecaptcha(): bool
{
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
'secret' => config('services.recaptcha.secret_key'),
'response' => $this->input('g-recaptcha-response'),
'remoteip' => $this->ip(),
]);

$result = $response->json();
// Método de validação do reCAPTCHA desativado
// private function validateRecaptcha(): bool
// {
// $response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
// 'secret' => config('services.recaptcha.secret_key'),
// 'response' => $this->input('g-recaptcha-response'),
// 'remoteip' => $this->ip(),
// ]);

if (!($result['success'] ?? false) || ($result['score'] ?? 0) < 0.3) {
Log::error('reCAPTCHA falhou', ['response' => $result]); // Log de erro detalhado
return false;
}
// $result = $response->json();

return true;
}
// if (!($result['success'] ?? false) || ($result['score'] ?? 0) < 0.3) {
// Log::error('reCAPTCHA falhou', ['response' => $result]); // Log de erro detalhado
// return false;
// }

// return true;
// }
}
56 changes: 40 additions & 16 deletions app/Livewire/Planning/Criteria/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,46 @@ protected function messages()
*/
public function mount()
{
$projectId = request()->segment(2);
$this->currentProject = ProjectModel::findOrFail($projectId);
$this->currentCriteria = null;
$this->criterias = CriteriaModel::where(
'id_project',
$this->currentProject->id_project
)->get();
$this->inclusion_rule['value'] = CriteriaModel::where(
'id_project',
$this->currentProject->id_project
)->where('type', 'Inclusion')->first()->rule ?? 'ALL';
$this->exclusion_rule['value'] = CriteriaModel::where(
'id_project',
$this->currentProject->id_project
)->where('type', 'Exclusion')->first()->rule ?? 'ANY';
$this->type['value'] = null;
try {
$projectId = request()->segment(2);

// Verifica se o projeto existe
$this->currentProject = ProjectModel::findOrFail($projectId);

// Inicializa os critérios
$this->criterias = CriteriaModel::where(
'id_project',
$this->currentProject->id_project
)->get();

// Define as regras de inclusão e exclusão com fallback
$this->inclusion_rule['value'] = CriteriaModel::where(
'id_project',
$this->currentProject->id_project
)->where('type', 'Inclusion')->first()->rule ?? 'ALL';

$this->exclusion_rule['value'] = CriteriaModel::where(
'id_project',
$this->currentProject->id_project
)->where('type', 'Exclusion')->first()->rule ?? 'ANY';

// Define o tipo padrão
$this->type['value'] = 'NONE';
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
// Caso o projeto não seja encontrado
$this->toast(
message: __('O projeto não foi encontrado.'),
type: 'error'
);
return redirect()->route('projects.index'); // Redireciona para a lista de projetos
} catch (\Exception $e) {
// Captura outros erros inesperados
$this->toast(
message: __('Ocorreu um erro ao carregar os dados: ') . $e->getMessage(),
type: 'error'
);
}

}

/**
Expand Down