/** * [showRefLink description] * Route::get('{link?}', ['as' => 'reflink', 'uses' => 'LinkController@showRefLink']); * * @param [text] $link [referral link] * * @return [json] [all info abou the link] */ public function showRefLink($link = null) { // // If it has a Sponsor Cookie if (\Cookie::has('sponsor')) { return Redirect::to('/'); // Load Referral Link View } if (is_null($link)) { return Redirect::to('/'); // Redirect To HomePage } try { // If has $Link then Look in Database if Exist $link = Link::findByLink($link)->load('user.profile'); $link = $link->toArray(); // Note Cookie Wont Be Created if Exceeded More than 4kb \Cookie::queue('sponsor', $link, 2628000); // Return Referral View with Variable Link return Redirect::to('/')->with('link', $link); // If No Record Found Throw Exception! } catch (ModelNotFoundException $e) { // Return Back to Home return Redirect::to('/'); // return view('nosponsor'); } }
/** * [showRefLink description] * Route::get('{link?}', ['as' => 'reflink', 'uses' => 'LinkController@showRefLink']); * * @param [text] $link [referral link] * * @return [json] [all info about the link] */ public function showRefLink($link = null) { // // If it has a Sponsor Cookie if (\Cookie::has('sponsor')) { $cookie = \Cookie::get('sponsor'); $link = $cookie['link']; $link = Link::findByLink($link)->load('user.profile'); $product = Product::find(1); return view('pages.referralLink')->with(compact('link', 'product')); } // Check if the Provided Link is Valid Redirect to Home if Invalid Link! try { $link = Link::findByLink($link); $sp_lid = $link->id; // If Sponsor is Not Active LeapFrog to ActiveSponsor if (!$link->active) { $sp_lid = $link->activeSponsor($sp_lid); } // Load User Profile $link = Link::find($sp_lid)->load('user.profile'); $splink = []; $splink['id'] = $link->id; $splink['user_id'] = $link->user_id; $splink['link'] = $link->link; // Load Product $product = Product::find(1); // Assign $splink to the cookie // Note Cookie Wont Be Created if Exceeded More than 4kb // Cookie set Forever / 5 Years or until Cache Clear // No Needed To Return With Cookie if it is Queue $cookie = \Cookie::queue('sponsor', $splink, 2628000); // Return Referral View with Variable Link return view('pages.referralLink')->with(compact('link', 'product')); // LINK PROVIDED IS INVALID REDIRECT HOME } catch (ModelNotFoundException $e) { return Redirect::to('/'); } }
public function searchUser() { // If Cookie is Present Dont Load Any Data! if (Cookie::has('sponsor')) { $cookie = Cookie::get('sponsor'); $link = $cookie['link']; $message = 'Loading... ' . $link . '\'s Sponsor Link'; // Return as an Error Code LOCK! return response()->json(['cookie' => true, 'message' => $message, 'link' => $link], 423); } // If No Cookie Is Present try { $link = Input::get('q'); $splinkdata = Link::findByLink($link)->load('user.profile'); $cookie = $splinkdata->toArray(); $message = 'Loading... ' . $splinkdata['link'] . '\'s Sponsor Link'; return response()->json(['cookie' => false, 'splinkdata' => $splinkdata, 'message' => $message], 200)->withCookie(\Cookie::forever('sponsor', $cookie)); } catch (ModelNotFoundException $e) { $link = Input::get('q'); $message = 'Can\'t Find ' . $link . ' in Database'; return response()->json(['cookie' => false, 'message' => $message, 'link' => $link], 400); } }
public function activateFirstLink(Request $request) { $activateFirstLinkRequest = new ActivateFirstLinkRequest(); $validator = Validator::make($request->all(), $activateFirstLinkRequest->rules(), $activateFirstLinkRequest->messages()); if ($validator->fails()) { return response()->json(['success' => false, 'errors' => $validator->errors()->toArray()], 400); } if ($this->captchaCheck() == false) { $errors = $validator->errors()->add('captchaerror', 'Captcha Expired Refresh Page!'); return response()->json(['success' => false, 'errors' => $errors], 200); } $pin = $request->pin; $secret = $request->secret; $link = $request->link; $code = Code::where('pin', $pin)->first(); $link = Link::findByLink($link); if ($link->active == true) { $errors = $validator->errors()->add('linkerror', 'Your Link is Already Active'); return response()->json(['success' => false, 'errors' => $errors], 200); } if ($code->used == true) { $errors = $validator->errors()->add('linkerror', 'Your Code is Already Used!'); return response()->json(['success' => false, 'errors' => $errors], 200); } if ($code->attempts > 4) { $code->blocked = true; $code->save(); } if ($code->blocked === true) { $errors = $validator->errors()->add('CodeError', 'Maximum Tries Reach! Code is Blocked!'); return response()->json(['success' => false, 'errors' => $errors], 423); } try { $validcode = Code::findByPin($pin)->secret($secret)->firstOrFail(); } catch (ModelNotFoundException $e) { $code = Code::findByPin($pin); $code->attempts = $code->attempts + 1; $code->save(); $attempts = $code->attempts; $errorMessage = 5 - $attempts . ' More Attempt Until Code is Blocked!'; $errors = $validator->errors()->add('CodeError', $errorMessage); return response()->json(['success' => false, 'errors' => $errors], 400); } // $code here inherent call above // $link is modified already to object not string link // Both $code and $link are Object Already $code->used = true; $link->code()->save($code); $link->active = true; $link->sp_link_id = $link->activeSponsor($link->sp_link_id); $link->save(); return response()->json(['success' => true, 'url' => 'FirstLink'], 201); }