Commit 4e543828 authored by alinetenorio's avatar alinetenorio
Browse files

validação do link de grupo de pesquisa

parent 5ae315e0
......@@ -93,7 +93,7 @@ class TrabalhoController extends Controller
'area' => ['required', 'string'],
'subArea' => ['required', 'string'],
'pontuacaoPlanilha' => ['required', 'string'],
'linkGrupo' => ['required', 'string'],
'linkGrupo' => ['required', 'string', 'link_grupo'],
'linkLattesEstudante' => ['required', 'string', 'link_lattes'],
'nomeParticipante.*' => ['required', 'string'],
'emailParticipante.*' => ['required', 'string'],
......@@ -142,7 +142,7 @@ class TrabalhoController extends Controller
'area' => ['required', 'string'],
'subArea' => ['required', 'string'],
'pontuacaoPlanilha' => ['required', 'string'],
'linkGrupo' => ['required', 'string'],
'linkGrupo' => ['required', 'string', 'link_grupo'],
'linkLattesEstudante' => ['required', 'string', 'link_lattes'],
'nomeParticipante.*' => ['required', 'string'],
'emailParticipante.*' => ['required', 'string'],
......
......@@ -26,5 +26,6 @@ class AppServiceProvider extends ServiceProvider
{
Validator::extend('cpf', '\App\Utils\CpfValidation@validate');
Validator::extend('link_lattes', '\App\Utils\LattesValidation@validate', 'Link inválido');
Validator::extend('link_grupo', '\App\Utils\GrupoPesquisaValidation@validate', 'Link inválido');
}
}
<?php namespace App\Utils;
class GrupoPesquisaValidation
{
public function validate($attribute, $value, $parameters, $validator)
{
return $this->isValidUrl($value);
}
function isValidUrl($url)
{
// first do some quick sanity checks:
if (!$url || !is_string($url)) {
return false;
}
$url = filter_var($url, FILTER_SANITIZE_URL);
// Validate url
if (!filter_var($url, FILTER_VALIDATE_URL)) {
return false;
}
// if(parse_url($url)['host'] != 'dgp.cnpq.br'){
// return false;
// }
if($this->getHttpResponseCode_using_getheaders($url) != 200){
return false;
}
return true;
}
function getHttpResponseCode_using_getheaders($url, $followredirects = true)
{
if (!$url || !is_string($url)) {
return false;
}
$headers = @get_headers($url);
if ($headers && is_array($headers)) {
if ($followredirects) {
$headers = array_reverse($headers);
}
foreach ($headers as $hline) {
if (preg_match('/^HTTP\/\S+\s+([1-9][0-9][0-9])\s+.*/', $hline, $matches)) {
$code = $matches[1];
return $code;
}
}
return false;
}
return false;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment