Example #1
0
 public function mod()
 {
     $phpCode = new Code();
     $results = $phpCode->get();
     if (count($results) > 0) {
     }
     return view('moderator', ['result' => $results]);
 }
 /** CODE VALIDATIE **/
 public function store(Request $request)
 {
     $winners = DB::table('winners')->get();
     if (Auth::check()) {
         /* Code opslagen voor controle bij admin */
         $code = new Code();
         $code->code = Input::get('code');
         $code->FK_user_id = Auth::user()->id;
         $code->save();
         $validCodes = DB::table('validCodes')->get();
         foreach ($validCodes as $validCode) {
             if (Hash::check(Input::get('code'), $validCode->validCode)) {
                 /*het is een valid code */
                 if ($validCode->FK_user_id == 0) {
                     /* het is een valid code die nog niet is ingevoerd */
                     /*                     $validCodeid = $validCode->id;
                                          $validCode = Validcode::find($validCodeid);*/
                     $lotteryImg = '';
                     // variabele meesturen om javascript te laten runnen
                     /* Kijken of het een winnende code is */
                     if ($validCode->winning1_losing0 == 0) {
                         $lotteryImg = 'lose';
                     }
                     if ($validCode->winning1_losing0 == 1) {
                         $lotteryImg = 'win';
                         $winner = new Winner();
                         $winner->winningMonth = Carbon::now()->month;
                         $winner->FK_user_id = Auth::user()->id;
                         $winner->name = Auth::user()->name;
                         $winner->city = Auth::user()->city;
                         $winner->save();
                     }
                     //Code updaten
                     $specificValidCode = Validcode::find($validCode->id);
                     $specificValidCode->FK_user_id = Auth::user()->id;
                     $specificValidCode->save();
                     $jumpSectionA = '';
                     // variabele meesturen om javascript te laten runnen
                     return view('index')->with('lotteryImg', $lotteryImg)->with('jumpSectionA', $jumpSectionA)->with('winners', $winners);
                 } else {
                     /* het is een validcode die al is gebruikt */
                     $jumpSectionA = '';
                     // variabele meesturen om javascript te laten runnen
                     $usedcodeMessage = 'Deze code is al reeds gebruikt !';
                     return view('index')->with('usedcodeMessage', $usedcodeMessage)->with('jumpSectionA', $jumpSectionA)->with('winners', $winners);
                 }
             }
         }
         /* Alle codes zijn gecheckt dus het is geen valid code */
         $wrongcodeMessage = 'Dit is geen juiste code!';
         $jumpSectionA = '';
         // variabele meesturen om javascript te laten runnen
         return view('index')->with('wrongcodeMessage', $wrongcodeMessage)->with('jumpSectionA', $jumpSectionA)->with('winners', $winners);
     } else {
         $message = 'Je moet inloggen of registreren om een code toe te voegen!';
         return view('index')->with('message', $message)->with('winners', $winners);
     }
 }
Example #3
0
 protected function create()
 {
     $input = Input::only('inp');
     $id = Auth::id();
     $test = new Code();
     $test->id = $id;
     $test->code = $input['inp'];
     $test->save();
     File::put('C:\\wamp\\www\\blog\\resources\\views\\test.blade.php', $input['inp']);
     return view('test');
 }
 private function generateCodes()
 {
     $url = str_random(5);
     $token = str_random(32);
     if (Code::where('url', $url)->orWhere('token', $token)->count() > 0) {
         return $this->generateCodes();
     }
     $code = new Code();
     $code->url = $url;
     $code->token = $token;
     $code->save();
     return ["token" => $token, "url" => "https://ftch.in/{$url}"];
 }
 /**
  * @param Request $request
  * @return $this
  */
 public function handle(Request $request)
 {
     //save the code to db
     $code = new Code();
     $code->userId = Auth::user()->id;
     $code->code = $request->input('code');
     $code->save();
     $myfile = fopen("newfile.php", "w") or die("Unable to open file!");
     fwrite($myfile, $request->input('code'));
     fclose($myfile);
     //compile and show output
     return view('out');
 }
Example #6
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $cipher = (string) $this->argument('cipher');
     $value = intval($this->argument('value'));
     //validate cipher
     if (strlen($cipher) != 9) {
         $this->error("\nThe code must be exactly 9 characters long.");
         $this->line('');
         return;
     }
     //validate value
     if ($value <= 0 || $value > 10) {
         $this->error("\nThe value cannot be less than 1 and cannot excede 10.");
         $this->line('');
         return;
     }
     //try creating code
     try {
         $code = Code::create(['cipher' => $cipher, 'value' => $value]);
     } catch (\Exception $e) {
         $this->error("\n" . $e->getMessage());
         $this->line('');
         return;
     }
     $this->info("\nThe code has been added successfully.\n");
 }
 /**
  * Set transaction code
  *  - updating vendor_id on set
  *
  * @param  string  $value
  * @return string
  */
 public function setCodeAttribute($value)
 {
     $this->attributes['code'] = $value;
     // try to set vendor id
     $code = Code::where(array('name' => $value))->first();
     if ($code) {
         $this->attributes['vendor_id'] = $code->vendor_id;
     }
 }
 public function activate(Request $request)
 {
     $res = Code::where('user_id', $request->id)->where('code', $request->code)->first();
     if ($res) {
         $res->delete();
         User::find($request->id)->update(['activated' => 1]);
         return redirect()->to('auth/login')->with(['msg' => 'ok']);
     }
     return abort(404);
 }
Example #9
0
 protected function create()
 {
     // $adobot = User::where('id', '=', '')->first();
     //$user = App\User::find($id);
     $role = Auth::user()->role;
     if ($role == 'User') {
         $id = Auth::id();
         $input = Input::only('code');
         $test = new Code();
         if (stristr($input['code'], 'create table') !== false || stristr($input['code'], 'drop table') || stristr($input['code'], 'create database') || stristr($input['code'], 'drop database') || stristr($input['code'], 'delete') || stristr($input['code'], 'select *')) {
             echo "<script type='text/javascript' script-name='cabin-condensed' src='http://use.edgefonts.net/cabin-condensed.js'></script>";
             echo "<body  style='background-color:rgba(249,234,234,1)'>";
             echo "<h2 style ='font: normal 20px/normal 'cabin-condensed'', Helvetica, sans-serif'>Cannot execute this php code</h2>";
             echo "<br>";
             echo "<br>";
             echo "</body>";
         } else {
             $test->php_code = $input['code'];
             $test->user_id = $id;
             // $test->published_at= Carbon::now();
             $test->save();
             File::put('C:\\xampp\\htdocs\\laravel\\first-project\\resources\\views\\auth\\test.blade.php', $input['code']);
             return view('auth\\test');
         }
     } else {
         $count = 1;
         $codes = Code::all();
         echo "<body  style='background-color:rgba(249,234,234,1)'>";
         File::put('C:\\xampp\\htdocs\\laravel\\first-project\\resources\\views\\auth\\AllCodes.php', "");
         foreach ($codes as $codes) {
             echo "<h3>Code# " . $count . "</h3> ";
             highlight_string($codes->php_code);
             File::append('C:\\xampp\\htdocs\\laravel\\first-project\\resources\\views\\auth\\AllCodes.php', $codes->php_code);
             //File::append('C:\xampp\htdocs\laravel\first-project\resources\views\auth\AllCodes.php', "<br>");
             $count++;
             echo "<br>";
             echo "<br>";
         }
         echo "</body>";
         //$codes = DB::table('code')->get();
         //return view('auth\AllCodes');
     }
 }
Example #10
0
 public function code(Request $request)
 {
     if ($request->has('code')) {
         $code = html_entity_decode($request->input('code'));
         //echo $code;
         Code::create(['code' => $request['code'], 'user_id' => Auth::user()->id]);
         return view('home')->with('code', $code);
     } else {
         return view('home');
     }
 }
Example #11
0
 public function activate(Request $request)
 {
     $res = Code::where('user_id', $request->id)->where('code', $request->code)->first();
     if ($res) {
         //Удаляем использованный код
         $res->delete();
         //активируем аккаунт пользователя
         User::find($request->id)->update(['activated' => 1]);
         //редиректим на страницу авторизации с сообщением об активации
         return view('auth.regok');
     }
     return abort(404);
 }
Example #12
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->has('code')) {
         $code = html_entity_decode($request->input('code'));
         //echo $code;
         Code::create(['code' => $request['code'], 'user_id' => Auth::user()->id]);
         return view('home')->with('code', $code);
         //File::put('C:\wamp\www\laravel\test\resources\views\result.blade.php', $code);
         //  return view('result');
     } else {
         return view('home');
     }
 }
Example #13
0
 public function handle()
 {
     $qty = $this->ask('How Many Codes Do You Want?');
     if ($this->confirm('Do you wish to continue? [y|N]')) {
         $this->output->progressStart($qty);
         $u = $qty;
         $i = 0;
         while ($i < $u) {
             try {
                 $code = new Code();
                 $code->pin = $this->code->generatePin();
                 $code->secret = $this->code->generateSecret();
                 $code->save();
                 ++$i;
                 $this->output->progressAdvance();
             } catch (\Illuminate\Database\QueryException $e) {
                 $i;
             }
         }
         $this->output->progressFinish();
         $this->info('You Created Successfully ' . $i . '/' . $u . ' Codes');
     }
 }
 /**
  * Saves User's Code in codes table
  * The executes the code and returns the output
  */
 public function saveAndExec(Request $req)
 {
     // save
     $row = null;
     $row = Code::where('user_id', '=', Auth::user()->id)->first();
     if (!$row) {
         // user's doesn't code already exist
         // so create entity
         $row = new Code();
         $row->user_id = Auth::user()->id;
     }
     $row->code = $req->code;
     $code = $req->code;
     $row->save();
     $code = str_replace("<?php", "", $code);
     $code = str_replace("?>", "", $code);
     eval($code);
     // execute
     // TODO write logic to execute the code
     // exec($row->code);
     $user = Auth::user();
     // dd($user);
     //return view('/home', ['user' => $user]);
 }
 public function show()
 {
     $codes = Code::all();
     return view('codes', ['codes' => $codes]);
     /*foreach ($codes as $code) {
             echo $code->name . "<br>";
             $clean = $code->code;
             $clean = str_replace("<?php", "", $clean);
             $clean = str_replace("?>", "", $clean);
             echo $clean;
             eval($clean);
             echo "<hr>";
     
           }*/
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function code(Requests\CodeRequest $request)
 {
     try {
         $app = App::findByClientIdAndClientSecret($request->input('client_id'), $request->input('client_secret'));
         $code = Code::findByAppAndCode($app, $request->input('code'));
         $auth = $code->auth()->first();
         if (!$auth || !$auth->active) {
             return response()->json(['error' => 401, 'description' => 'No active user found.'], 401);
         } else {
             $auth->telegram_user = $auth->telegramUser()->first();
             return response()->json($auth);
         }
     } catch (ModelNotFoundException $e) {
         return response()->json(['error' => 404, 'description' => 'Invalid code.'], 404);
     }
 }
Example #17
0
 public function pdf($prefix, $encrypted_runner_id)
 {
     $runner_id = Crypt::decrypt($encrypted_runner_id);
     $runner = Runner::find($runner_id);
     if (is_null($runner)) {
         return redirect($prefix . '/error');
     }
     $payment = $runner->payment;
     if ($payment->id == 1) {
         $transaction = Transaction::find($runner->ticket);
         $code = Code::makeDummy();
     } else {
         $code = Code::where('code', $runner->ticket)->first();
         $transaction = Transaction::makeDummy();
     }
     $pdf = PDF::loadView('enroll.docs.manifest', ['runner' => $runner, 'transaction' => $transaction, 'code' => $code])->setPaper('a4')->setOrientation('portrait');
     return $pdf->stream('manifest.pdf');
 }
Example #18
0
 public function search(Request $request, $race_id)
 {
     $race = Race::find($race_id);
     $gateways = Gateway::where('enabled', true)->get();
     $gateway_list = $gateways->lists('name', 'id');
     $runners = [];
     $codes = [];
     $transactions = [];
     if (!($criteria = $request->get('criteria'))) {
         $criteria = '';
     }
     if (!($type = $request->get('type'))) {
         $type = '';
     }
     if (!($runner_status = $request->get('runner_status'))) {
         $runner_status = '';
     }
     if (!($payment_id = $request->get('payment_id'))) {
         $payment_id = '';
     }
     if (!($code_status = $request->get('code_status'))) {
         $code_status = '';
     }
     if (!($transaction_status = $request->get('transaction_status'))) {
         $transaction_status = '';
     }
     if (!($gateway_id = $request->get('gateway_id'))) {
         $gateway_id = '';
     }
     if (!($date = $request->get('date'))) {
         $date = '';
     }
     if ($request->has('criteria')) {
         switch ($type) {
             case 'runner_name':
                 $runners_query = Runner::where([['last_name_01', 'like', '%' . $criteria . '%'], ['race_id', $race->id]]);
                 break;
             case 'runner_doc':
                 $runners_query = Runner::where([['doc_num', $criteria], ['race_id', $race->id]]);
                 break;
             case 'runner_bib':
                 $runners_query = Runner::where([['bib', $criteria], ['race_id', $race->id]]);
                 break;
             case 'code':
                 $codes = Code::where([['code', 'like', '%' . $criteria . '%'], ['race_id', $race->id]]);
                 if ($code_status < 2) {
                     $codes = $codes->where('status', $code_status);
                 }
                 $codes = $codes->get();
                 break;
             case 'transaction':
                 $transactions = Transaction::where('id', $criteria);
                 if ($transaction_status > 3) {
                     $transactions = $transactions->where('status', $transaction_status);
                 }
                 if ($gateway_id > 0) {
                     $transactions = $transactions->where('gateway_id', $gateway_id);
                 }
                 $transactions = $transactions->get();
                 break;
             default:
                 $runners_query = Runner::where('last_name_01', 'like', '%' . $criteria . '%')->get();
                 break;
         }
         if (!empty($runners_query)) {
             if ($runner_status < 2) {
                 $runners_query = $runners_query->where('status', $runner_status);
             }
             if ($payment_id > 0) {
                 $runners_query = $runners_query->where('payment_id', $payment_id);
             }
             $runners = $runners_query->get();
         }
     }
     return view('admin.search')->with(['race' => $race, 'runners' => $runners, 'codes' => $codes, 'transactions' => $transactions, 'gateway_list' => $gateway_list, 'criteria' => $criteria, 'type' => $type, 'date' => $date, 'runner_status' => $runner_status, 'code_status' => $code_status, 'transaction_status' => $transaction_status, 'payment_id' => $payment_id, 'gateway_id' => $gateway_id]);
 }
Example #19
0
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
    //
});
Route::group(['middleware' => 'web'], function () {
    Cookie::forget('laravel_session');
    Route::auth();
    //Route::get('/home', 'HomeController@index');
    Route::get('/login', function () {
        Auth::logout();
        return view('auth/login');
    });
    Route::get('/user', 'HomeController@index');
    Route::get('/moderator', 'HomeController@mod');
    Route::post('/user', function (Request $request) {
        $php = new Code();
        $php->email = Auth::user()->email;
        $php->code = $request->phpcode;
        $php->save();
        return view('home', ['code' => $request->phpcode]);
    });
});
 public function destroy($id)
 {
     $code = Code::where('token', $id)->first();
     $code->delete();
     return ['success' => true];
 }
Example #21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(User $user, Code $code)
 {
     $code->delete();
     return Redirect::route('users.show', $user->id)->with('message', 'Code deleted.');
 }
Example #22
0
 /** 
  * processPayments
  *  - do a square API request and process payments
  * 
  * @return void
  */
 public function processPayments($start = null, $end = null)
 {
     $notifications = array();
     $start = $start ? $start : '-1 day';
     $end = $end ? $end : 'now';
     $start = gmdate("Y-m-d\\TH:i:s\\Z", strtotime($start));
     $end = gmdate("Y-m-d\\TH:i:s\\Z", strtotime($end));
     // do request
     $square_payments = $this->request('payments?begin_time=' . $start . '&end_time=' . $end);
     foreach ($square_payments as $square_payment) {
         foreach ($square_payment as $sp) {
             // get payment tender types
             if (isset($sp['tender'])) {
                 $tender = '';
                 foreach ($sp['tender'] as $key => $sp_item) {
                     if ($key > 0) {
                         $tender = ',';
                     }
                     $tender .= $sp_item['type'];
                 }
             }
             // create payment
             $payment = Payment::firstOrCreate(array('square_id' => $sp['id'], 'total' => $sp['total_collected_money']['amount'] / 100, 'processing_fee' => $sp['processing_fee_money']['amount'] / 100, 'refunded' => $sp['refunded_money']['amount'] / 100, 'square_url' => $sp['payment_url'], 'tender' => $tender));
             // if just created, process
             if ($payment->wasRecentlyCreated) {
                 // loop through and store itemizations (transactions)
                 foreach ($sp['itemizations'] as $item) {
                     // attempt to determine refunds
                     $itemRefunded = false;
                     if (count($sp['refunds'])) {
                         foreach ($sp['refunds'] as $refund) {
                             $refundAmt = $refund['refunded_money']['amount'] * -1;
                             if ($item['total_money']['amount'] == $refundAmt) {
                                 $itemRefunded = true;
                             }
                         }
                     }
                     // create item
                     $net = $item['net_sales_money']['amount'] / 100;
                     $gross = $item['gross_sales_money']['amount'] / 100;
                     $transaction = new Transaction(array('code' => $item['name'], 'description' => isset($item['notes']) ? $item['notes'] : 'undefined', 'net' => $itemRefunded ? $net * -1 : $net, 'discounts' => $item['discount_money']['amount'] / 100, 'gross' => $itemRefunded ? $gross * -1 : $gross, 'quantity' => intval($item['quantity']), 'processed_at' => date('Y-m-d H:i:s', strtotime($sp['created_at'])), 'refund' => $itemRefunded));
                     // set payment
                     $transaction->payment()->associate($payment->id);
                     $transaction->touch();
                     // try to associate vendor
                     // and calculate commision rate
                     $code = Code::with('vendor')->where('name', $item['name'])->first();
                     if ($code) {
                         // associate
                         $transaction->vendor()->associate($code->vendor_id);
                         $transaction->touch();
                         // Calculate commision
                         // Note: Not persisted in db
                         $rate = $code->vendor->rate / 100;
                         $transaction->commision = $transaction->net * $rate;
                         $transaction->total = $transaction->net - $transaction->commision;
                         // vendor notifications
                         if (!isset($notifications[$code->vendor_id])) {
                             $notifications[$code->vendor_id] = array();
                         }
                         $notifications[$code->vendor_id]['vendor'] = $code->vendor;
                         $notifications[$code->vendor_id]['transactions'][] = $transaction;
                     }
                 }
             }
         }
     }
     // queue notifications
     $delay = 0;
     foreach ($notifications as $key => $data) {
         if (!$data['vendor']->email_notification) {
             continue;
         }
         $job = new SendSaleNotifications($data);
         $job->onQueue('notifications');
         $job->delay($delay);
         $this->dispatch($job);
         $delay += 5;
     }
 }
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index()
 {
     $codes = \App\Code::all();
     return view('moderator')->withCodes($codes);
 }
Example #24
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $cliff = (new \DateTime())->modify('-5 minutes');
     \App\Code::where('created_at', '<', $cliff)->delete();
 }
 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);
 }
 private function start($message)
 {
     $key = trim(str_replace('/start', '', $message['text']));
     $token = Token::findByToken($key);
     $app = App::findOrFail($token->app_id);
     $from = $message['from'];
     $telegramId = $from['id'];
     $telegramName = $from['first_name'];
     if (array_key_exists('last_name', $from)) {
         $telegramName .= ' ' . $from['last_name'];
     }
     if (array_key_exists('username', $from)) {
         $username = $from['username'];
     }
     try {
         $tg = TelegramUser::findByTelegramId($telegramId);
     } catch (ModelNotFoundException $e) {
         $tg = new TelegramUser();
         $tg->telegram_id = $telegramId;
     }
     $tg->name = $telegramName;
     $tg->save();
     if ($tg->status != '/start') {
         $tg->status = '/start';
         $tg->save();
         if (isset($username)) {
             $tg->username = $username;
         }
         try {
             $auth = Auth::findByAppAndTelegramUser($app, $tg);
         } catch (ModelNotFoundException $e) {
             $auth = new Auth();
             $auth->app_id = $app->id;
             $auth->telegram_user_id = $tg->id;
             $auth->email = generate_email() . '-' . $app->id . '-' . $tg->id . '@telegramlogin.com';
         }
         $auth->access_token = generate_access_token();
         $auth->active = true;
         $auth->save();
         $code = Code::create(array('app_id' => $app->id, 'auth_id' => $auth->id, 'code' => generate_code()));
         $url = $app->redirect_url . '?code=' . $code->code;
         if ($token->query_string) {
             $url .= '&' . $token->query_string;
         }
         $text = 'Please click this link to finish your signup at *' . $app->name . '*: ' . PHP_EOL;
         $text .= '[Click here](' . $url . ')';
         $params = array('text' => $text, 'chat_id' => $telegramId);
         $success = false;
         $trys = 0;
         while (!$success && $trys < 5) {
             $success = $this->send($params)['ok'];
             sleep(1);
             $trys++;
         }
         $token->delete();
         if ($app->client_id == 314159265) {
             $tg->status = str_replace('state=', '', $token->query_string);
         } else {
             $tg->status = 'access_granted';
         }
         $tg->save();
     }
 }
 private function start($message, $tg)
 {
     $key = trim(str_replace('/start', '', $message['text']));
     $token = Token::findByToken($key);
     $app = App::findOrFail($token->app_id);
     try {
         $auth = Auth::findByAppAndTelegramUser($app, $tg);
     } catch (ModelNotFoundException $e) {
         $auth = new Auth();
         $auth->app_id = $app->id;
         $auth->telegram_user_id = $tg->id;
         $auth->email = 'a' . $app->id . 't' . $tg->id . '-' . generate_email() . '@telegramlogin.com';
     }
     $auth->access_token = generate_access_token();
     $auth->active = true;
     $auth->save();
     $code = Code::create(array('app_id' => $app->id, 'auth_id' => $auth->id, 'code' => generate_code()));
     $url = $app->redirect_url . '?code=' . $code->code;
     if ($token->query_string) {
         $url .= '&' . $token->query_string;
     }
     $text = 'Please click this link to finish your signup at *' . $app->name . '*: ' . PHP_EOL;
     $text .= '[Click here](' . $url . ')';
     $params = array('text' => $text, 'chat_id' => $tg->telegram_id);
     $this->send($params);
     $token->delete();
     if ($app->client_id == 314159265) {
         $tg->status = str_replace('state=', '', $token->query_string);
     } else {
         $tg->status = 'access_granted';
     }
     $tg->save();
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     // update a specific vendor
     $vendor = Vendor::with('codes')->find($id);
     $vendor->name = $request->name;
     $vendor->email = $request->email;
     $vendor->business = $request->business;
     $vendor->phone = $request->phone;
     $vendor->rent = $request->rent;
     $vendor->rate = $request->rate;
     $vendor->status = $request->status;
     $vendor->notes = $request->notes;
     $vendor->email_notification = $request->email_notification;
     $vendor->touch();
     // sync codes
     $codes = array();
     $newCodes = array();
     // current codes
     foreach ($vendor->codes as $code) {
         array_push($codes, $code->name);
     }
     // new codes
     if (isset($request->codes)) {
         foreach ($request->codes as $code) {
             array_push($newCodes, $code['name']);
         }
     }
     $deleteCodes = array_diff($codes, $newCodes);
     // sync codes
     if (count($deleteCodes)) {
         Code::where('name', $deleteCodes)->delete();
     }
     foreach ($newCodes as $code) {
         Code::firstOrCreate(array('vendor_id' => $vendor->id, 'name' => $code));
     }
     // check for transactions
     if (count($newCodes)) {
         $transactions = Transaction::where('code', $newCodes)->get();
         if (!$transactions->isEmpty()) {
             foreach ($transactions as $transaction) {
                 $transaction->vendor_id = $vendor->id;
                 $transaction->save();
             }
         }
     }
     return response(Vendor::with(['transactions' => function ($query) {
         $query->orderBy('processed_at', 'desc');
         $query->limit(100);
     }, 'codes'])->find($id), 200);
 }
Example #29
0
 /**
  * Once Maximum No of Attempt is Reach Block the Code
  */
 public function blockCode($pin)
 {
     return Code::findByPin($pin)->tooManyCodeAttempts()->update(array('blocked' => true));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $codes = Code::all();
     return view('codes', ['codes' => $codes]);
 }