/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ('testing' == App::environment()) { return $next($request); } return parent::handle($request, $next); }
/** * @param Request $request * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function getLogin(Request $request) { if (App::environment('demo')) { $request->session()->flashInput(['email' => '*****@*****.**', 'password' => 'secret']); } return view('user::public.login'); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0'); if (!App::environment('production')) { $this->call('UsersTableSeeder'); $this->call('ProfilesTableSeeder'); } $this->call('RolesTableSeeder'); $this->call('DestinationsTableSeeder'); $this->call('LocationsTableSeeder'); $this->call('MissionTypesTableSeeder'); $this->call('VehiclesTableSeeder'); $this->call('StatisticsTableSeeder'); $this->call('PartsTableSeeder'); $this->call('MissionsTableSeeder'); $this->call('PartFlightsTableSeeder'); $this->call('TagsTableSeeder'); $this->call('NotificationTypesTableSeeder'); $this->call('NotificationsTableSeeder'); $this->call('AstronautsTableSeeder'); $this->call('SpacecraftTableSeeder'); $this->call('SpacecraftFlightsTableSeeder'); $this->call('PayloadsTableSeeder'); $this->call('TelemetryTableSeeder'); $this->call('PrelaunchEventsTableSeeder'); DB::statement('SET FOREIGN_KEY_CHECKS=1'); }
public function upload(FormUploadRequest $request) { $attributes = $request->all(); // fetch the file $file = $request->file('file'); if (!$file->isValid()) { throw new Exception('File is not valid'); } if (App::environment() == 'testing') { $destinationDir = public_path() . '/testdata/forms'; } else { $destinationDir = public_path() . '/data/forms'; } $slug = str_slug($attributes['name']); $destinationFile = $attributes['year'] . '-' . $slug . '.' . $file->getClientOriginalExtension(); $file->move($destinationDir, $destinationFile); $form = new Form(); $form->year = $attributes['year']; $form->name = str_replace('-', '_', str_slug($attributes['name'])); $form->slug = $attributes['year'] . '-' . $slug; $form->location = str_replace(public_path(), '', $destinationDir . '/' . $destinationFile); $form->extension = $file->getClientOriginalExtension(); $form->size = filesize($destinationDir . '/' . $destinationFile); $form->md5 = md5($destinationDir . '/' . $destinationFile); $form->save(); $resource = new Item($form, new FormTransformer(), 'forms'); return response()->json($this->fractal()->createData($resource)->toArray(), Response::HTTP_CREATED); }
/** * Reverse the migrations. * * @return void */ public function down() { if (\Illuminate\Support\Facades\App::environment('local')) { Schema::drop('settings'); } else { throw new Exception('Migrating down is prohibited.'); } }
/** * Run a pull on the QA git repo if merged into master * * @return \Illuminate\Http\Response */ public function postPullRequest(Request $Request) { $request = $Request->all(); if (App::environment() === 'qa' && $request['action'] === 'closed' && $request['pull_request']['merged'] === true && $request['pull_request']['base']['ref'] === 'qa') { exec('cd /var/www/qa.hometeachme.org/ && git pull'); } return new Response('pull request received!', 200); }
public function __construct() { if (App::environment() == 'testing') { $this->destinationDir = public_path() . '/testdata/minutes'; } else { $this->destinationDir = public_path() . '/data/minutes'; } }
public function subscribe($events) { if (empty(Slack::getEndpoint()) || App::environment('local')) { return; } $events->listen('new-signup', [$this, 'onNewSignup']); $events->listen('new-conference', [$this, 'onNewConference']); }
public function run() { if (App::environment() == 'local') { //Delete all records from the users table DB::table('users')->delete(); //Create a demo user User::create(array('email' => '*****@*****.**', 'password' => Hash::make('user'), 'firstname' => 'User', 'lastname' => 'Demo', 'status' => 1)); } }
public static function sendAdminEmail($data) { Mail::send([], $data, function ($message) use($data) { $message->to(Config::get('mail.admin_email')); $message->subject(App::environment() . ': ' . $data['subject']); $message->setBody(App::environment() . ': ' . $data['text']); }); return true; }
public static function sendEmailPlain($data) { Mail::send([], $data, function ($message) use($data) { $message->to($data['email']); $message->subject(App::environment() . ': ' . $data['subject']); $message->setBody(App::environment() . ': ' . $data['text']); }); return true; }
public function handle() { if (App::environment() == 'production') { $this->error("Production? Not sure if I can run this on production"); exit; } $this->app_folder = base_path(); $this->repo_name = $this->argument('repo_name'); $this->runScripts(); }
/** * @param TelegramMessageRequest $request * * @return JsonResponse */ public function store(TelegramMessageRequest $request) { $content = ['chat_id' => StaffTelegramGroup::id(), 'text' => sprintf('(%s) %s', App::environment(), $request->text())]; try { $message = $this->telegram->sendMessage($content); $this->webUi->successMessage("Sent message `{$message->getMessageId()}` to staff"); } catch (\Exception $e) { $this->webUi->errorMessage(sprintf('Failed to send message to staff: %s (%s)', $e->getMessage(), json_encode($content))); } return $this->webUi->redirect('telegram.index'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // && !App::environment('local') // dd($request->getRequestUri()); if ($request->secure() && !App::environment('local')) { // return redirect('https://www.colorme.vn'); // return redirect()->secure($request->getRequestUri()); return redirect($request->getRequestUri()); } return $next($request); }
/** * Run the database seeds. * * @return void */ public function run() { if (\Illuminate\Support\Facades\App::environment() === 'local') { Model::unguard(); $this->cleanDatabase(); $this->call('UserTableSeeder'); $this->call('RoleTableSeeder'); $this->call('PageTableSeeder'); Model::reguard(); } }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $period = RegistrationPeriod::current()->first(); $period_id = $period ? $period->id : NULL; if (App::environment() == 'local') { return ['first_name' => 'required', 'contact_email' => 'required|unique:registrations,contact_email,NULL,id,registration_period_id,' . $period_id . '|max:255', 'contact_mobile' => 'required|min:8|max:16', 'national_id' => 'required|unique:registrations,national_id,NULL,id,registration_period_id,' . $period_id]; } $skill_levels = implode(',', array_keys(config('registration.skill_levels'))); $social_status = implode(',', array_keys(config('registration.social_status'))); return ['first_name' => 'required|max:255|min:2', 'second_name' => 'required|max:255|min:2', 'third_name' => 'required|max:255|min:2', 'fourth_name' => 'max:255', 'last_name' => 'required|max:255|min:2', 'last_name_latin' => 'required|max:255|min:2', 'fourth_name_latin' => 'max:255', 'third_name_latin' => 'required|max:255|min:2', 'second_name_latin' => 'required|max:255|min:2', 'first_name_latin' => 'required|max:255|min:2', 'gender' => 'required|in:f,m', 'birthday' => 'required|date', 'nationality_type' => 'in:O,E|required', 'passeport_issued' => 'date|required_with:passeport_number', 'passeport_country_id' => 'exists:lists_countries,id|required_with:passeport_number', 'passeport_expire' => 'date|required_with:passeport_number', 'stay_type' => 'sometimes|required|in:work,companion,tourism,non_resident', 'national_id' => 'required|unique:registrations,national_id,NULL,id,registration_period_id,' . $period_id . '', 'contact_region' => '', 'contact_postalbox' => 'required|max:255', 'degrees.*.degree_country_id' => 'required|exists:lists_countries,id', 'birth_country_id' => 'required|exists:lists_countries,id', 'nationality_country_id' => 'sometimes|required|exists:lists_countries,id', 'nationality_city_id' => 'sometimes|required|exists:lists_cities,id', 'nationality_state_id' => 'sometimes|required|exists:lists_states,id', 'contact_country_id' => 'required|exists:lists_countries,id', 'contact_city_id' => 'sometimes|required|exists:lists_cities,id', 'contact_state_id' => 'sometimes|required|exists:lists_states,id', 'contact_email' => 'required|unique:registrations,contact_email,NULL,id,registration_period_id,' . $period_id . '|max:255', 'contact_mobile' => 'required|numeric', 'degrees.*.degree_graduation_year' => 'required|numeric', 'contact_phone' => 'numeric', 'contact_fax' => 'numeric', 'degrees.*.degree_speciality' => 'required', 'degrees.*.degree_institution' => 'required', 'degrees.*.degree_score' => 'required', 'social_status' => 'required|in:' . $social_status, 'social_job_status' => 'required', 'social_job' => 'required_if:social_job_status,employed', 'social_job_start' => 'required_if:social_job_status,employed', 'social_experience' => 'required_if:social_job_status,employed', 'social_job_employer' => 'required_if:social_job_status,employed', 'social_job_country_id' => 'required_if:social_job_status,employed|exists:lists_countries,id', 'social_job_city_id' => 'required_if:social_job_status,employed|exists:lists_cities,id', 'health_status' => 'in:0,1|required', 'health_disabled_type' => 'required_if:health_status,disabled', 'health_disabled_size' => 'required_if:health_status,disabled', 'computer_skills' => 'in:' . $skill_levels, 'internet_skills' => 'in:' . $skill_levels, 'internet_link' => '', 'cyber_cafe' => '', 'computer_availability' => '']; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // check current environment if (App::environment() !== "development" && App::environment() !== "testing") { // check given credentials if ($request->getUser() !== config('app.api_user') || $request->getPassword() !== config('app.api_password')) { return response()->json(['error' => 'Invalid credentials.'], 401)->header('WWW-Authenticate', 'Basic'); } } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed * * @throws \Illuminate\Session\TokenMismatchException */ public function handle($request, Closure $next) { if ('testing' === App::environment() && $request->exists('_token')) { $input = $request->all(); $input['_token'] = $request->session()->token(); $request->replace($input); } if ($this->isReading($request) || $this->shouldPassThrough($request) || $this->tokensMatch($request)) { return $this->addCookieToResponse($request, $next($request)); } throw new TokenMismatchException(); }
public function run() { Eloquent::unguard(); if (App::environment('testing')) { $this->testingDeleteTables(); } $this->globalSeeds(); if (App::environment('testing')) { $this->testingSeeds(); } Eloquent::reguard(); }
/** * Boot package. */ public function boot() { $this->symfonyContainer = new SymfonyContainer(App::environment(), false); $this->routebuilder = new LaraverRouteBuilder(); $this->routeManager = new SymfonyRoutesManager($this->symfonyContainer, $this->routebuilder); $this->symfonyCommandsFacade = new SymfonyCommandsFacade($this->symfonyContainer); $this->loadAutoloader(base_path('packages')); $this->setupRoutes($this->app->router); $this->loadViewsFrom(realpath(__DIR__ . '/../views'), 'SymfonysFacade'); $this->registerCommands(); $this->publishes([__DIR__ . '/config/symfo.php' => config_path('symfo.php')]); }
/** * Execute the console command. * * @return void */ public function fire() { $this->bootSilverstripe(); if (\Director::isLive()) { $env = App::environment(); $this->error("This command is not allowed on the '{$env}' environment."); return; } $defaultMember = \Security::findAnAdministrator(); if (!$defaultMember->Email) { // must be a new install, admin user has no username // ask the user for one $member = $defaultMember; $member->Email = $this->ask("What username/email do you want to give to the default CMS admin user? [admin]:", 'admin'); } else { for (;;) { $username = $this->ask("What username do you want to edit? [{$defaultMember->Email}]: ", $defaultMember->Email); if ($username == $defaultMember->Email) { $member = $defaultMember; break; } $member = \Member::get()->filter('Email', $username)->First(); if ($member && $member->Exists()) { break; } $this->error("Username '{$username}' not found."); } } for (;;) { for (;;) { $password = $this->secret("Enter a new password: "******"I can't let you set a blank password."); } $confirm = $this->secret("Enter again to confirm: "); if ($confirm == $password) { break; } $this->error("Those passwords don't match."); } $member->Password = $password; $member->PasswordEncryption = SilverstripeConfig::inst()->get('Security', 'password_encryption_algorithm'); try { $this->info("Saving CMS account '{$member->Email}'..."); $member->write(); $this->info('Password changed successfully.'); } catch (Exception $e) { $this->error('Error: ' . $e->getMessage()); } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); if (App::environment() === 'production') { $this->call(UserTableSeeder::class); $this->call(UserProfileTableSeeder::class); } else { $this->call(UserTableSeeder::class); $this->call(UserProfileTableSeeder::class); $this->call(OrganizationTableSeeder::class); } Model::reguard(); }
/** * Creates a connection for the database of the $user * the name of the connection will be 'RevoRetail_{$user}' * This doesn't check if the database exists * * @param $user * @param $shouldConnect * @param bool $reports true to connect to the read only database insatance */ function createDBConnection($user, $shouldConnect = false, $reports = false) { $prefix = config('tenants.DB_TENANTS_PREFIX'); $database = $prefix . $user; $host = $reports ? config('tenants.DB_REPORTS_HOST') : config('tenants.DB_HOST'); $username = config('tenants.DB_USERNAME'); $password = config('tenants.DB_PASSWORD'); $tablesPrefix = config('tenants.DB_TABLES_PREFIX'); Config::set('database.connections.' . $user, ['driver' => App::environment('testing') ? 'sqlite' : 'mysql', 'host' => $host, 'database' => App::environment('testing') ? ':memory:' : $database, 'username' => $username, 'password' => $password, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => $tablesPrefix]); if ($shouldConnect) { DB::setDefaultConnection($user); } }
/** * Fire the install script. * * @param Command $command * * @throws Exception * * @return mixed */ public function fire(Command $command) { if (!$this->finder->isFile('.env')) { throw new Exception('SocietyCMS is not installed. Please run "php artisan society:install" first.'); } if ($command->option('refresh') && !App::environment('demo')) { throw new Exception('Refresh option is only available in demo mode.'); } if (!$command->option('force') && !$command->option('refresh')) { if (!$command->confirm('Are you sure you want to start Demo Mode?')) { throw new Exception('Demo Mode cancelled'); } } }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($this->isHttpException($e)) { $code = $e->getStatusCode(); if ($code !== 500 || App::environment('production') || App::environment('staging')) { $page = Page::findByInternalName($code); if ($page) { $request = Request::create($page->url()->getLocation(), 'GET'); return response(Route::dispatch($request)->getContent(), $code); } } } return parent::render($request, $e); }
private function fellowshipOneAuth($username, $password = null) { $f1 = App::make('faithpromise.fellowshipone.api'); // $f1 = new API([ // 'key' => env('F1_KEY'), // 'secret' => env('F1_SECRET'), // 'baseUrl' => env('F1_API_URI') // ]); if (App::environment('local')) { $f1->debug = true; } $f1->login2ndParty($username, $password, API::TOKEN_CACHE_CUSTOM, ['setAccessToken' => function ($username, $token = null) { }, 'getAccessToken' => function ($username) { }]); }
/** * Add files to publishable array & autopublish them in case directory does not exist. * * @param array $paths * @param null $group */ protected function publishes(array $paths, $group = null) { parent::publishes($paths, $group); if ($this->onlyDevelopment && App::environment() != 'local') { return; } if ($this->needsPublish) { return; } foreach ($paths as $path) { if (!$this->isPublished($path)) { $this->needsPublish = true; return; } } }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if (App::environment('prod')) { if ($e->getStatusCode() == 404) { if ($request->segment(1) == 'admin' && Auth::check()) { View::share('auser', Auth::user()); return \Response::view('admin.errors.404', [], 404); } else { return \Response::view('errors.404', [], 404); } } } if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } return parent::render($request, $e); }
private function resetDatabase() { $env = App::environment(); $this->output->writeln("Truncating tables in {$env} environment"); if (App::isLocal()) { foreach ($this->tables as $table) { $this->output->writeln("Truncating {$table}"); DB::statement('TRUNCATE TABLE ' . $table . ' CASCADE;'); } } elseif (App::runningUnitTests()) { Eloquent::unguard(); foreach ($this->tables as $table) { $this->output->writeln("Truncating {$table}"); DB::statement('TRUNCATE TABLE ' . $table . ' CASCADE;'); } } }
public function register() { $this->app->bind('React', function () { if (App::environment('production') && Cache::has('reactSource') && Cache::has('componentsSource')) { $reactSource = Cache::get('reactSource'); $componentsSource = Cache::get('componentsSource'); } else { $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'react'); $reactSource = file_get_contents(config('react.source')); $componentsSource = file_get_contents(config('react.components')); if (App::environment('production')) { Cache::forever('reactSource', $reactSource); Cache::forever('componentsSource', $componentsSource); } } return new React($reactSource, $componentsSource); }); }