Modulo de forms independiente de universal3 (cuidado)
Showing
... | ... | @@ -10,7 +10,7 @@ use Yajra\Datatables\Datatables; |
use App\Notifications\WelcomeInterested; | ||
use App\Notifications\NewInterestd; | ||
use App\Notifications\EmailInvalid; | ||
use App\Interested; | ||
use Onestartup\CrmForms\Model\Interested; | ||
use App\User; | ||
use Jenssegers\Agent\Agent; | ||
use Onestartup\CrmForms\Model\InterestedDetail; | ||
... | ... | @@ -22,90 +22,37 @@ class CrmFormsController extends Controller |
{ | ||
public function store(RequestInterested $request) | ||
{ | ||
error_log("$request"); | ||
$agent = new Agent(); | ||
$agent->setUserAgent($request->header('User-Agent')); | ||
$browser = $agent->browser(); | ||
$browser_version = $agent->version($browser); | ||
$devise = $agent->device(); | ||
$platform = $agent->platform(); | ||
$platform_version = $agent->version($platform); | ||
$session_time = $request->session_time; | ||
if ($agent->isMobile()){ | ||
$devise_type = "Mobil"; | ||
}elseif($agent->isTablet()){ | ||
$devise_type = "Tablet"; | ||
}elseif($agent->isDesktop()){ | ||
$devise_type = "Desktop"; | ||
}else{ | ||
$devise_type = "Otro"; | ||
} | ||
$agent->isMobile(); | ||
$agent->isTablet(); | ||
$user = User::find(1); | ||
if($request->desc2 == "" && $request->email2 == "[email protected]" && strpos($request->email, "@mail.ru") === false){ | ||
if (config('crmforms.validate_email')) { //Se activa la opcion de validar emails por API | ||
$url = "https://apps.emaillistverify.com/api/verifyEmail?secret=".env('KEY_VERIFY')."&email=".$request->email; | ||
$client = new \GuzzleHttp\Client(); | ||
$res = $client->request('GET', $url); | ||
$respuesta = $res->getBody(); | ||
if ( $respuesta == 'ok') { //Si el correo es valido | ||
$interested = Interested::create($request->all()); | ||
$interested->notify(new WelcomeInterested()); | ||
$user->notify(new NewInterestd($interested)); | ||
$interested_details = InterestedDetail::firstOrNew(['interested_id' => $interested->id]); | ||
$interested_details->browser = $browser; | ||
$interested_details->browser_version = $browser_version; | ||
$interested_details->devise = $devise; | ||
$interested_details->platform = $platform; | ||
$interested_details->platform_version = $platform_version; | ||
$interested_details->session_time = $session_time; | ||
$interested_details->devise_type = $devise_type; | ||
$interested_details->save(); | ||
} else { // Si el correo no es valido | ||
$user->notify(new EmailInvalid($request->all())); | ||
return redirect() | ||
->back() | ||
->withInput() | ||
->with('fail', 'fail'); | ||
} | ||
} else { // No se valida el correo por api, va directo a la bd | ||
$interested = Interested::create($request->all()); | ||
$interested->notify(new WelcomeInterested()); | ||
$user->notify(new NewInterestd($interested)); | ||
$interested_details = InterestedDetail::firstOrNew(['interested_id' => $interested->id]); | ||
$interested_details->browser = $browser; | ||
$interested_details->browser_version = $browser_version; | ||
$interested_details->devise = $devise; | ||
$interested_details->plataform = $platform; | ||
$interested_details->plataform_version = $platform_version; | ||
$interested_details->session_time = $session_time; | ||
$interested_details->devise_type = $devise_type; | ||
$interested_details->save(); | ||
} | ||
if(!($request->desc2 == "" && $request->email2 == "[email protected]" && strpos($request->email, "@mail.ru") === false)){ | ||
return redirect()->back()->withInput(); | ||
} | ||
return redirect() | ||
->route('crmforms.redirect', $request->landing) | ||
->with('registrado', 'registrado') | ||
->with('message_success', 'Hemos recibido tu solicitud, en breve nos comunicaremos contigo'); | ||
if (config('crmforms.validate_email')) { //Se activa la opcion de validar emails por API | ||
$url = "https://apps.emaillistverify.com/api/verifyEmail?secret=".env('KEY_VERIFY')."&email=".$request->email; | ||
$client = new \GuzzleHttp\Client(); | ||
$res = $client->request('GET', $url); | ||
$respuesta = $res->getBody(); | ||
if ( $respuesta == 'ok') { //Si el correo es valido | ||
$this->createInterested($request, $user); | ||
} else { // Si el correo no es valido | ||
$user->notify(new EmailInvalid($request->all())); | ||
return redirect() | ||
->back() | ||
->withInput() | ||
->with('fail', 'fail'); | ||
} | ||
} else { // No se valida el correo por api, va directo a la bd | ||
$this->createInterested($request, $user); | ||
} | ||
}else{ | ||
return redirect()->back(); | ||
} | ||
return redirect() | ||
->route('crmforms.redirect', $request->landing) | ||
->with('registrado', 'registrado') | ||
->with('message_success', 'Hemos recibido tu solicitud, en breve nos comunicaremos contigo'); | ||
} | ||
public function redirect($landing) | ||
... | ... | @@ -128,4 +75,56 @@ class CrmFormsController extends Controller |
} | ||
} | ||
private function createInterested($request, $user){ | ||
$agent = new Agent(); | ||
$agent->setUserAgent($request->header('User-Agent')); | ||
$browser = $agent->browser(); | ||
$browser_version = $agent->version($browser); | ||
$devise = $agent->device(); | ||
$platform = $agent->platform(); | ||
$platform_version = $agent->version($platform); | ||
$session_time = $request->session_time; | ||
if ($agent->isMobile()){ | ||
$devise_type = "Mobil"; | ||
}elseif($agent->isTablet()){ | ||
$devise_type = "Tablet"; | ||
}elseif($agent->isDesktop()){ | ||
$devise_type = "Desktop"; | ||
}else{ | ||
$devise_type = "Otro"; | ||
} | ||
$agent->isMobile(); | ||
$agent->isTablet(); | ||
$interested = Interested::create($request->all()); | ||
$interested->notify(new WelcomeInterested()); | ||
$user->notify(new NewInterestd($interested)); | ||
$interested_details = InterestedDetail::firstOrNew(['interested_id' => $interested->id]); | ||
$interested_details->browser = $browser; | ||
$interested_details->browser_version = $browser_version; | ||
$interested_details->devise = $devise; | ||
$interested_details->platform = $platform; | ||
$interested_details->platform_version = $platform_version; | ||
$interested_details->session_time = $session_time; | ||
$interested_details->devise_type = $devise_type; | ||
$interested_details->save(); | ||
} | ||
public static function functionName($slug) { | ||
$slug_landing = preg_replace('/[,]|[:]|[.]|[,]|[ ]/','-',$slug); | ||
$slug_landing = str_replace(["â","á","à","ä"],'a',$slug_landing); | ||
$slug_landing = str_replace(["ê","é","è","ë"],'e',$slug_landing); | ||
$slug_landing = str_replace(['í','ì','î','ï'],'i',$slug_landing); | ||
$slug_landing = str_replace(['ó','ò','ô','ö'],'o',$slug_landing); | ||
$slug_landing = str_replace(['ú','ù','û','ü'],'u',$slug_landing); | ||
$slug_landing = str_replace(['ñ'],'n',$slug_landing); | ||
$slug_landing = strtolower($slug_landing); | ||
return $slug_landing; | ||
} | ||
} |
src/model/Interested.php
0 → 100644
Please
register
or
sign in
to comment