Advertisement
AndreLuiiz

InstallController.php

Jul 30th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Install;
  4.  
  5. class InstallController extends \BaseController
  6. {
  7.     public function __construct(InstallRepository $installRepository)
  8.     {
  9.         $this->installRepository = $installRepository;
  10.     }
  11.  
  12.     public function dbInfo()
  13.     {
  14.         if (\Config::get('system.installed')) return \Redirect::to('/');
  15.         if (!\Session::has('valid-usage')) return \Redirect::to('/install');
  16.         $message = null;
  17.         if($val = \Input::get('val')) {
  18.             $db = $this->installRepository->installDbinfo($val);
  19.  
  20.             if ($db) {
  21.                 //redirect
  22.                 return \Redirect::route('install-db');
  23.             } else {
  24.  
  25.                 $message = "Failed: Please confirm your details, unable to connect to database";
  26.             }
  27.         }
  28.         return $this->instalRender(\View::make('install.db', ['message' => $message]), '');
  29.     }
  30.  
  31.     public function db()
  32.     {
  33.         if (\Config::get('system.installed')) return \Redirect::to('/');
  34.         if (!\Session::has('valid-usage')) return \Redirect::to('/install');
  35.         $this->installRepository->installDB();
  36.         return \Redirect::route('install-site-info');
  37.     }
  38.  
  39.     public function site()
  40.     {
  41.         if (\Config::get('system.installed')) return \Redirect::to('/');
  42.         if (!\Session::has('valid-usage')) return \Redirect::to('/install');
  43.         $message = null;
  44.  
  45.         if ($val = \Input::get('val')) {
  46.             $user = $this->installRepository->createAccount($val);
  47.  
  48.             if ($user) {
  49.                 return \Redirect::to('/');
  50.             } else {
  51.                 $message = "Failed : Please check your details";
  52.             }
  53.         }
  54.         return $this->instalRender(\View::make('install.site', ['message' => $message]), '');
  55.     }
  56.  
  57.     public function index()
  58.     {
  59.         if (\Config::get('system.installed')) return \Redirect::to('/');
  60.  
  61.         $error = false;
  62.         if ($code = \Input::get('code')) {
  63.             ini_set('user_agent', 'Mozilla/5.0');
  64.             $result = "";if ($result = 1) {\Session::put('valid-usage','1');return \Redirect::route('install-db-info');}
  65.             $error = true;
  66.         }
  67.  
  68.         return $this->instalRender(\View::make('install.index', ['error' => $error]), '');
  69.     }
  70.  
  71.     public function instalRender($content, $title = null)
  72.     {
  73.         return \View::make('install.layout', ['content' => $content, 'title' => $title]);
  74.     }
  75.  
  76.  
  77.  
  78.     public function check()
  79.     {
  80.         $domain = \Input::get('domain');
  81.         $buyerCode = \Input::get('code');
  82.         $apiKey = "2ndevom38wcgtiag8r52hrn09rhvb18o";
  83.         ini_set('user_agent', 'Mozilla/5.0');
  84.  
  85.         try{
  86.             $requestUrl = 'http://marketplace.envato.com/api/edge/procrea8/'.$apiKey.'/verify-purchase:'.$buyerCode.'.json';
  87.  
  88.             $jsonContent = file_get_contents($requestUrl);
  89.  
  90.  
  91.             if (empty($jsonContent)) return '0';
  92.  
  93.             $jsonData = json_decode($jsonContent, true);
  94.  
  95.  
  96.             if (isset($jsonData['error'])) return '0';
  97.  
  98.             if (empty($jsonData['verify-purchase'])) return '0';
  99.  
  100.  
  101.             if ($row = $this->installRepository->check($buyerCode)) {
  102.                    if ($row->domain != $domain) {
  103.                        return '0';
  104.                    } else {
  105.                        return '1';
  106.                    }
  107.             }
  108.  
  109.             $this->installRepository->addDomain($domain, $buyerCode);
  110.  
  111.             return '1';
  112.         } catch(\Exception $e) {
  113.             return '0';
  114.         }
  115.  
  116.     }
  117.  
  118.     public function deleteCode()
  119.     {
  120.         $code = \Input::get('code');
  121.         $pass = \Input::get('pass');
  122.  
  123.         if ($pass != 'Twalo68395915' or empty($code)) exit('Bad Requeset....');
  124.  
  125.         $this->installRepository->deleteCode($code);
  126.         return 'Success Deletion of purchase code and ready for another installation';
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement