Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
concurs.tbf.ro
/
app
/
Http
/
Controllers
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
MainController.php
| Size :
7.72
KB
Copy
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Applicant; use App\Point; class MainController extends Controller { public function home(){ //0 it's for not referral users $referral = 0; $from = 'start'; $applicant = false; return view('welcome', compact('referral', 'from', 'applicant')); } public function home_referral($token){ $applicant_referral = Applicant::where('token', $token)->first(); $from = 'start'; $applicant = false; if($applicant_referral){ $referral = $applicant_referral->id; }else{ $referral = 0; } return view('welcome', compact('referral', 'from', 'applicant')); } public function check_email(Request $request){ $applicant = Applicant::where('email', $request->email)->first(); if($applicant){ return response()->json(['error' => true]); }else{ return response()->json(['error' => false]); } } public function store(Request $request){ $request->validate([ 'name' => 'required', 'email' => 'required|email|unique:applicants', ]); $random_code = substr(md5(uniqid(rand(), true)), 12, 12); $exist_random_code = Applicant::where('token',$random_code)->first(); while ($exist_random_code) { $random_code = substr(md5(uniqid(rand(), true)), 12, 12); $exist_random_code = Applicant::where('token',$random_code)->first(); } $confirmation_code = substr(md5(uniqid(rand(), true)), 4, 4); $applicant = Applicant::create([ 'response' => $request->answer, 'name' => ucfirst($request->name), 'email' => $request->email, 'phone' => $request->phone, 'terms_and_conditions' => 1, 'referral' => $request->referral, 'token' => $random_code, 'confirmation_code' => $confirmation_code ]); // send mail and sms to applicant with confirmation code newUserCreatedMail($applicant); if($request->phone){ newUserCreatedSms($applicant); } return response()->json(['message' => 'A fost salvat cu succes!', 'token' => $applicant->token]); } public function confirm_code(Request $request){ $applicant = Applicant::where('token', $request->token)->first(); if($applicant->confirmation_code == $request->confirmation_code){ if(!$applicant->confirmed){ $applicant->update(['confirmed' => 1]); $pointRegistration = Point::create([ 'applicant_id' => $applicant->id, 'type' => 'registration', 'description' => 'Inregistrare in concurs', 'value' => 1 ]); generateTickets($pointRegistration); if($applicant->referral != 0){ $point = Point::create([ 'applicant_id' => $applicant->referral, 'type' => 'referral', 'description' => $applicant->name.' ('.$applicant->email.')', 'friend_id' => $applicant->id, 'value' => 100 ]); // create tickets generateTickets($point); // send mail to applicant referral with new points received newPointsMail($point, $applicant); } // send mail to applicant to confirm sing up signUpConfirmationMail($applicant); } $points = $applicant->points->sum('value'); $applicant = Applicant::where('token', $applicant->token)->first(); $customApplicant = [ 'name' => $applicant->name, 'facebook' => $applicant->facebook, 'linkedin' => $applicant->linkedin, 'token' => $applicant->token, 'points' => $applicant->points->where('type', 'referral'), 'tickets' => $applicant->tickets->pluck('id')->toArray() ]; return response()->json(['message' => 'Contul a fost confirmat!', 'applicant' => $customApplicant, 'error' => false, 'points' => $points]); }else{ return response()->json(['error' => true]); } } public function add_points(Request $request){ $applicant = Applicant::where('token', $request->token)->first(); if($request->type){ if((!$applicant->facebook && $request->type == 'facebook') || (!$applicant->linkedin && $request->type != 'facebook')){ $point = Point::create([ 'applicant_id' => $applicant->id, 'type' => 'social_follow', 'description' => $request->type == 'facebook' ? 'Follow Facebook' : 'Follow Linkedin', 'value' => $request->type == 'facebook' ? 20 : 30, ]); generateTickets($point); } if($request->type == 'facebook'){ $applicant->facebook = 1; $applicant->save(); }else{ $applicant->linkedin = 1; $applicant->save(); } } $points = $applicant->points->sum('value'); $customApplicant = [ 'name' => $applicant->name, 'facebook' => $applicant->facebook, 'linkedin' => $applicant->linkedin, 'token' => $applicant->token, 'points' => $applicant->points->where('type', 'referral'), 'tickets' => $applicant->tickets->pluck('id')->toArray() ]; return response()->json(['message' => 'Sansele au fost adaugate!', 'applicant' => $customApplicant, 'error' => false, 'points' => $points]); } public function view_points($token){ $applicant = Applicant::where('token', $token)->first(); if($applicant){ return view('points', compact('applicant')); }else{ return redirect()->route('home'); } } public function confirmation_link($token){ return redirect()->route('home'); // $applicant = Applicant::where('token', $token)->first(); // if($applicant){ // $from = 'confirmation_mail'; // $referral = $applicant->referral; // if(!$applicant->confirmed){ // $applicant->update(['confirmed' => 1]); // $pointRegistration = Point::create([ // 'applicant_id' => $applicant->id, // 'type' => 'registration', // 'description' => 'Inregistrare in concurs', // 'value' => 1 // ]); // generateTickets($pointRegistration); // if($applicant->referral != 0){ // $point = Point::create([ // 'applicant_id' => $applicant->referral, // 'type' => 'referral', // 'description' => $applicant->name.' ('.$applicant->email.')', // 'friend_id' => $applicant->id, // 'value' => 100 // ]); // generateTickets($point); // // send mail to applicant referral with new points received // newPointsMail($point, $applicant); // } // // send mail to applicant to confirm sing up // signUpConfirmationMail($applicant); // return view('welcome', compact('referral', 'from', 'applicant')); // }else{ // return redirect()->route('view_points',$applicant->token); // } // }else{ // return redirect()->route('home'); // } } }
Back