/** * Sets up db by running migration and seeder. * * @return \Illuminate\Http\RedirectResponse */ public function setupDb() { if (\Cache::get('setup_db', false)) { $request = \Request::instance(); $method = $request->method(); if (Verbs::GET === $method) { return view('setup', ['version' => config('df.version')]); } else { if (Verbs::POST === $method) { try { if (\Cache::pull('setup_db', false)) { \Artisan::call('migrate', ['--force' => true]); \Artisan::call('db:seed', ['--force' => true]); if ($request->ajax()) { return json_encode(['success' => true, 'redirect_path' => '/setup']); } else { return redirect()->to('/setup'); } } else { if ($request->ajax()) { return json_encode(['success' => false, 'message' => 'Setup not required. System is already setup']); } } } catch (\Exception $e) { if ($request->ajax()) { return json_encode(['success' => false, 'message' => $e->getMessage()]); } else { return view('errors.generic', ['error' => $e->getMessage(), 'version' => config('df.version')]); } } } } } return redirect()->to('/'); }
/** * {@inheritdoc} */ protected function hasInvalidState() { if ($this->isStateless()) { return false; } $urlState = $this->request->input('state'); $cacheState = \Cache::pull($urlState); return !(strlen($cacheState) > 0 && $urlState === $cacheState); }
/** * Get the token credentials for the request. * * @return \League\OAuth1\Client\Credentials\TokenCredentials */ protected function getToken() { $temp = null; if ($this->usesState()) { $temp = $this->request->getSession()->get('oauth.temp'); } else { $key = $this->request->get('oauth_token'); $temp = \Cache::pull($key); } return $this->server->getTokenCredentials($temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')); }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciado' . PHP_EOL; $start = microtime(true); $cacheKey = md5(uniqid('')); $totalUsers = User::count(); $pid = pcntl_fork(); if ($pid == -1) { die('could not fork =('); } else { if ($pid) { // we are the parent //É necessário reconectar no banco, os processos vão compartilhar //a conexão, o que irá gerar erro \DB::reconnect('mysql'); //Pega os usuários da primeira metade do total $users = $this->getUsers($totalUsers / 2, 0); //Aguarda o processo filho terminar pcntl_wait($status); //Faz um merge do que o processo pai e filho processaram //Os dados do processo filho estão no cache $users = array_merge($users, \Cache::pull($cacheKey)); } else { // we are the child //É necessário reconectar no banco, os processos vão compartilhar //a conexão, o que irá gerar erro \DB::reconnect('mysql'); //Pega os usuários da segunda metade do total $users = $this->getUsers($totalUsers / 2, $totalUsers / 2); //Armazena os usuários processados no cache \Cache::forever($cacheKey, $users); die; } } echo 'Processados ' . count($users) . ' usuários' . PHP_EOL; echo 'Demorou ' . number_format((microtime(true) - $start) * 1000, 2, ',', '') . 'ms' . PHP_EOL; }
/** * 清除缓存 * @param string $cachename * @return boolean */ public static function removeCache($cachename) { //TODO: remove cache implementation return \Cache::pull($cachename); }
/** * {@inheritdoc} */ protected function getToken() { $key = $this->request->get('oauth_token'); $temp = \Cache::pull($key); return $this->server->getTokenCredentials($temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier')); }
public function testMakeLoginToken() { $user = $this->createUser(); $token = $user->makeLoginToken($user->user_id); $id = Cache::pull('login_token_' . $token); $this->assertEquals($id, $user->user_id); }
<a href="http://github.com/atrauzzi/laravel-drydock">Github</a> @if($lastCronRun) <div class="notice">Last cron run {{ $lastCronRun }} (runs every minute)</div> @endif <hr /> <input type="email" id="email" placeholder="Enter an email address..." /> <input type="text" id="message" placeholder="Enter a message..." /> <a href="javascript:void(0)" onclick="location.href='/dev/queue/test?message=' + message.value + '&email=' + email.value; message.value=''; email.value='';">Queue it!</a> <br /> <?php $message = Cache::pull('last-message'); ?> <div id="last-message"> @if($message) <div> <h4>Your message is done processing!</h4> <div class="notice">{{ $message }}</div> </div> @endif </div> </div> </div> </body> </html>
Route::post('activate/FirstLink', ['as' => '1stlinkactivation', 'uses' => 'CodeController@activateFirstLink']); // after first link is activated dont show anymore this url to them Route::post('signup', ['as' => 'signup', 'uses' => 'Auth\\AuthController@create']); // Route::get('{link?}', ['as' => 'links', 'uses' => 'LinkController@getRefLink']); Route::get('activeSponsor/{id}', function ($id) { $id = App\Link::where('id', $id)->firstOrFail()->activeSponsor($id); return $id; }); // Route::get('code/all', ['as' => 'codeall', 'uses' => 'CodeController@index']); Route::get('code/{linkID}/{PINCODE}', ['as' => 'code', 'uses' => 'CodeController@attachLink']); // Update user account data // Route::put('profile', ['as' => 'profile/update', 'uses' => 'UserController@update']); // Not working yet Route::get('/vue', function () { return view('vue'); }); Route::get('api/users', function () { $value = Cache::rememberForever('users', function () { return \App\Profile::latest()->take(50)->select('display_name', 'created_at')->get(); // Should Only Fetch the Users Display Name! }); return $value = Cache::pull('users'); }); //Route::post('api/users', function(){ // App\User::create(Request::all()); //}); // Route::get('getCookie', function () { return view('welcome'); }); //Route::get('/activate/{code}', 'Auth\AuthController@activateAccount Route::get('{link?}', ['as' => 'reflink', 'uses' => 'LinkController@showRefLink']);
/** * Actiovation account */ public function getActivation($code = null) { if (Session::get('activated')) { return View::make(Config::get('larauth::views.activation')); } if (Input::get('code')) { $code = Input::get('code'); } if ($code) { try { $user = Sentry::findUserByActivationCode($code); $user->attemptActivation($code); // добавляем пользователя в группы foreach (Config::get('larauth::append_groups') as $group) { try { $oGroup = Sentry::findGroupByName($group); } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) { Log::alert("Попытка добавдения пользователя :user_email в несуществующую группу :group", ['user_email' => $user->email, 'group' => $group]); } $user->addGroup($oGroup); } $data = ['email' => $user->email, 'password' => Cache::pull(md5($user->email)), 'subject' => trans('larauth::larauth.registration_success')]; $this->sendMail(Config::get('larauth::views.mail_registration'), $data); return Redirect::route('larauth.activation')->with('activated', TRUE); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::route('larauth.activation')->with('error', trans('larauth::larauth.wrong_activation_code')); } } return View::make(Config::get('larauth::views.activation'), ['error' => Session::get('error'), 'code' => $code]); }
/* |-------------------------------------------------------------------------- | 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 (Router $route) { $route->get('/', function () { $lastCronRun = new \Carbon\Carbon(Cache::get('last-cron')); $lastCronRun = $lastCronRun->diffForHumans(); return view('welcome', compact('lastCronRun')); }); $route->get('/dev/info', function () { ob_start(); phpinfo(); $phpinfo = ob_get_contents(); ob_end_clean(); return new Response($phpinfo); }); $route->get('/dev/queue/test', function (Request $request) { dispatch(new TestJob($request->get('message'), $request->get('email'))); return new Response(null, 204); }); $route->get('/api/web/last-message', function (Request $request) { return new JsonResponse(Cache::pull('last-message')); }); });
/* * Main page */ Route::filter('dashboardFilter', function () { if (!Schema::hasTable('users')) { return Redirect::to('start'); } if (!User::all()->count()) { return Redirect::to('register'); } if (!Auth::check()) { return Redirect::to('login'); } }); Route::get('/', array('before' => array('dashboardFilter', 'nexmo'), function () { return View::make('hello', array('credit_balance' => Cache::pull('nexmo'), 'numbers' => Number::all())); })); /* * Login page */ Route::filter('loginFilter', function () { if (!Schema::hasTable('users')) { return Redirect::to('start'); } if (!User::all()->count()) { return Redirect::to('register'); } }); Route::get('/login', array('before' => array('loginFilter', 'nexmo'), 'as' => 'login', function () { return View::make('login'); }));