/** * Save the site to the database, create a config and add that config to nginx. * * @param $request * @param $groupId * * @return bool */ public function handle($request, $groupId) { $uuid = $this->site->generateUuid($request['port'] . $request['name']); $site = $this->createSite($request, $groupId, $uuid); event(new SiteWasCreated($site, $request)); return [true, null]; }
public function newComment(Bin $bin, Requests\Bins\NewComment $request) { $comment = $bin->comments()->create(['user_id' => auth()->user()->getAuthIdentifier(), 'message' => $request->input('message')]); event(new UserCommentedOnBin($comment)); session()->flash('success', 'Success! Comment added!'); return redirect()->to($comment->getCommentUrl()); }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); $path = parse_url($app->url(), PHP_URL_PATH); $errorDir = __DIR__ . '/../../error'; if (!$app->isInstalled()) { $app->register('Flarum\\Install\\InstallServiceProvider'); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); $pipe->pipe($path, new HandleErrors($errorDir, true)); } elseif ($app->isUpToDate() && !$app->isDownForMaintenance()) { $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale')); event(new ConfigureMiddleware($pipe, $path, $this)); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')])); $pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode())); } else { $pipe->pipe($path, function () use($errorDir) { return new HtmlResponse(file_get_contents($errorDir . '/503.html', 503)); }); } return $pipe; }
/** * Increase a song's play count as the currently authenticated user. * * @param Request $request * * @return \Illuminate\Http\JsonResponse */ public function play(Request $request) { if ($interaction = Interaction::increasePlayCount($request->input('song'), $request->user())) { event(new SongStartedPlaying($interaction->song, $interaction->user)); } return response()->json($interaction); }
/** * Execute the job. * * @return void */ public function handle() { // Delete the post from database $this->post->delete(); // Fire Event and Listeners event(new DeletedPost($this->post)); }
public static function boot() { parent::boot(); static::created(function (EventLog $eventLog) { event(new NewEventLog($eventLog)); }); }
/** * @param $user_firstname * @param $user_lastname * @param $email * @param $password * @param $user_phone * @return static */ public static function register($user_firstname, $user_lastname, $email, $password, $user_phone) { $user = new static(compact('user_firstname', 'user_lastname', 'email', 'password', 'user_phone')); // $user = Event::fire(new UserRegistred($user)); event(new UserHasRegistred($user, $password)); return $user; }
/** * Override the boot method to bind model event listeners. * * @return void */ public static function boot() { parent::boot(); static::saved(function (Deployment $model) { event(new ModelChanged($model, 'deployment')); }); }
/** * Execute the job. * * @param \Illuminate\Http\Request $request * @return \Apolune\Contracts\Account\Account|null */ public function handle(Request $request) { $this->account->password = bcrypt($request->get('password')); $this->account->save(); event(new ChangedPassword($this->account)); return $this->account; }
/** * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); $this->guard()->login($user); return $this->registered($request, $user) ?: redirect($this->redirectPath()); }
/** * Perform authentication before a request is executed. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param $grant * * @return mixed * @throws AccessDeniedException */ public function handle($request, Closure $next, $grant = null) { $route = $this->router->getCurrentRoute(); /** * FOR (Internal API requests) * @note GRANT(user) will always be able to access routes that are protected by: GRANT(client) * * For OAuth grants from password (i.e. Resource Owner: user) * @Auth will only check once, because user exists in auth afterwards * * For OAuth grants from client_credentials (i.e. Resource Owner: client) * @Auth will always check, because user is never exists in auth */ if (!$this->auth->check(false)) { $this->auth->authenticate($route->getAuthenticationProviders()); $provider = $this->auth->getProviderUsed(); /** @var OAuth2 $provider */ if ($provider instanceof OAuth2) { // check oauth grant type if (!is_null($grant) && $provider->getResourceOwnerType() !== $grant) { throw new AccessDeniedException(); } } // login user through Auth $user = $this->auth->getUser(); if ($user instanceof User) { \Auth::login($user); event(new UserLoggedInEvent($user)); } } return $next($request); }
public static function save($data) { $code = (new Parcels())->getNextCode(); $description = $data[0]; event(new ActivityLog(auth()->user()->username . ' created a parcel ' . $description . ' with the code ' . $code . ' successfully via CSV Upload.')); return auth()->user()->parcels()->create(['weight' => 1, 'town_id' => 1, 'status_id' => 1, 'description' => $description, 'code' => $code, 'destination' => $data[1]]); }
/** * Handle the subscribe customer command. * * @param \CachetHQ\Cachet\Commands\Subscriber\VerifySubscriberCommand $command * * @return void */ public function handle(VerifySubscriberCommand $command) { $subscriber = $command->subscriber; $subscriber->verified_at = Carbon::now(); $subscriber->save(); event(new SubscriberHasVerifiedEvent($subscriber)); }
/** * @param UploadAvatar $command * @return \Flarum\Core\Users\User * @throws \Flarum\Core\Exceptions\PermissionDeniedException */ public function handle(UploadAvatar $command) { $actor = $command->actor; $user = $this->users->findOrFail($command->userId); // Make sure the current user is allowed to edit the user profile. // This will let admins and the user themselves pass through, and // throw an exception otherwise. if ($actor->id !== $user->id) { $user->assertCan($actor, 'edit'); } $tmpFile = tempnam(sys_get_temp_dir(), 'avatar'); $command->file->moveTo($tmpFile); $manager = new ImageManager(); $manager->make($tmpFile)->fit(100, 100)->save(); event(new AvatarWillBeSaved($user, $actor, $tmpFile)); $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]); if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) { $mount->delete($file); } $uploadName = Str::lower(Str::quickRandom()) . '.jpg'; $user->changeAvatarPath($uploadName); $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}"); $user->save(); $this->dispatchEventsFor($user); return $user; }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); $path = config('hyn.laravel-flarum.paths.api'); // if ($app->isInstalled() && $app->isUpToDate()) { $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); $pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\FakeHttpMethods')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithHeader')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale')); event(new ConfigureMiddleware($pipe, $path, $this)); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.api.routes')])); $pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\HandleErrors')); // } else { // $pipe->pipe($path, function () { // $document = new Document; // $document->setErrors([ // [ // 'code' => 503, // 'title' => 'Service Unavailable' // ] // ]); // // return new JsonApiResponse($document, 503); // }); // } return $pipe; }
/** * Handle the creation of the Field in the Database * @param $command * @return static */ public function handle($command) { $command->namespace = EntityModel::find($command->entity_id)->namespace; $field = FieldModel::create((array) $command); event(new FieldWasCreated($field)); return $field; }
/** * @param EditTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(EditTag $command) { $actor = $command->actor; $data = $command->data; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'edit', $tag); $attributes = array_get($data, 'attributes', []); if (isset($attributes['name'])) { $tag->name = $attributes['name']; } if (isset($attributes['slug'])) { $tag->slug = $attributes['slug']; } if (isset($attributes['description'])) { $tag->description = $attributes['description']; } if (isset($attributes['color'])) { $tag->color = $attributes['color']; } if (isset($attributes['isHidden'])) { $tag->is_hidden = (bool) $attributes['isHidden']; } if (isset($attributes['isRestricted'])) { $tag->is_restricted = (bool) $attributes['isRestricted']; } event(new TagWillBeSaved($tag, $actor, $data)); $this->validator->assertValid($tag->getDirty()); $tag->save(); return $tag; }
/** * Creates new product description with given options. * * @param array $options * * @return Description * @throws ModelNotFoundException */ public function addProductDescription($productId, $options = []) { $product = $this->getProduct($productId); $description = $product->descriptions()->save(new Description(['body' => $options['body']])); event(new Events\DescriptionWasCreated($description)); return $description->fresh(); }
/** * Handle the update component group command. * * @param \CachetHQ\Cachet\Bus\Commands\ComponentGroup\UpdateComponentGroupCommand $command * * @return \CachetHQ\Cachet\Models\ComponentGroup */ public function handle(UpdateComponentGroupCommand $command) { $group = $command->group; $group->update($this->filter($command)); event(new ComponentGroupWasUpdatedEvent($group)); return $group; }
/** * Execute the job. * * @return void */ public function handle() { // Delete Artist from Database $this->artist->delete(); // Fire the Event and the Listeners event(new DeletedArtist($this->artist)); }
/** * Boot the model. * * @return void */ public static function boot() { parent::boot(); static::created(function (self $preset) { event(new PresetCreated($preset)); }); }
/** * @param Role $role */ public function removeRole(Role $role) { if ($this->getRoles()->contains($role)) { $this->getRoles()->removeElement($role); event(new UserGotRemovedFromRole($this, $role)); } }
/** * Saves all datamodels in all services to the database. */ public function save() { $data = $this->getData(); $repo = \App::make(YoutubeRepository::class); call_user_func([$repo, 'save' . ucfirst(str_plural($this->_params->get('resource')['name']))], $data); event(new PackageSaved($this)); }
/** * Handle the update project group command. * * @param \Gitamin\Commands\Owner\UpdateOwnerCommand $command * * @return \Gitamin\Models\Owner */ public function handle(UpdateOwnerCommand $command) { $owner = $command->owner; $owner->update(['name' => $command->name, 'path' => $command->path, 'user_id' => $command->user_id, 'description' => $command->description]); event(new OwnerWasUpdatedEvent($owner)); return $owner; }
/** * @covers App\Events\NewRegisteredUser::__construct * @covers App\Handlers\Events\LinkUserToExistingContacts::handle * @test */ public function it_fires_NewRegisteredUser_event_and_links_user() { $contact = $this->createContact(['email' => '*****@*****.**']); $user = $this->createUser(['email' => '*****@*****.**', 'password' => bcrypt('demoguest')]); event(new NewRegisteredUser($user)); $this->seeInDatabase('contacts', ['email' => $user->email, 'user_id' => $user->id]); }
/** * Handle the claim invite command. * * @param \CachetHQ\Cachet\Commands\User\ClaimInviteCommand $command * * @return void */ public function handle(ClaimInviteCommand $command) { $invite = $command->invite; $invite->claimed_at = Carbon::now(); $invite->save(); event(new InviteWasClaimed($invite)); }
/** * Store a newly created book in storage. * * @param BookRequest $request * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse */ public function store(BookRequest $request) { $this->book->create($request); event(new BookHasCreated('Δημιουργία βιβλίου: ' . $request->title, Carbon::now()->format('Y-m-d'), 'http://library.gr/cPanel/unpublished/' . $request->get('barcode') . '/confirm', $this->user->myAdministratorHash(), $request->get('barcode'), 1)); flash()->overlay('Συγχαρητήρια', 'το βιβλίο ' . $request->title . ' δημιουργήθηκε με επιτυχία. Αναμένετε έγκριση από τον διαχειριστή'); return redirect()->back(); }
protected static function boot() { parent::boot(); static::creating(function ($adtype) { event(new AdtypeWillBeCreated($adtype)); }); static::created(function ($adtype) { event(new AdtypeWasCreated($adtype)); }); static::updating(function ($adtype) { event(new AdtypeWillBeUpdated($adtype)); }); static::updated(function ($adtype) { event(new AdtypeWasUpdated($adtype)); }); static::deleted(function ($adtype) { event(new AdtypeWasDeleted($adtype)); }); static::deleting(function ($adtype) { event(new AdtypeWillBeDeleted($adtype)); foreach ($adtype->ads as $ad) { $ad->forceDelete(); } $adtype->subscriptions()->detach(); $adtype->users()->detach(); }); }
public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false) { $invoice->load('invitations', 'client.language', 'account'); $entityType = $invoice->getEntityType(); $client = $invoice->client; $account = $invoice->account; if ($client->trashed()) { return trans('texts.email_errors.inactive_client'); } elseif ($invoice->trashed()) { return trans('texts.email_errors.inactive_invoice'); } $account->loadLocalizationSettings($client); $emailTemplate = $account->getEmailTemplate($reminder ?: $entityType); $emailSubject = $account->getEmailSubject($reminder ?: $entityType); $sent = false; if ($account->attatchPDF() && !$pdfString) { $pdfString = $invoice->getPDFString(); } foreach ($invoice->invitations as $invitation) { $response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString); if ($response === true) { $sent = true; } } $account->loadLocalizationSettings(); if ($sent === true) { if ($invoice->is_quote) { event(new QuoteWasEmailed($invoice)); } else { event(new InvoiceWasEmailed($invoice)); } } return $response; }
/** * @param Request $request * @return string */ public function verifyPayment(Request $request) { // Get the details submitted by the form $email = $request->input('email'); $countryCode = $request->input('country'); $source = $request->input('stripeToken'); $order = $request->all(); // If the user is logged in, but does not have a stripe customer id, // we attach it to the them and set the billing_id to be equal to the newly created // customer id if (Auth::check() and Auth::user()->stripe_customer_id == null) { $user = Auth::user(); $email = $user->email; $customer = $this->createNewCustomer($source, $email); $billing_id = $customer->id; $user->stripe_customer_id = $billing_id; //$customerName = $user->first_name . $user->last_name; $user->save(); // Else if the authenticated user already has a Stripe id, we grab their stripe customer id from // the user object } elseif (Auth::check()) { $user = Auth::user(); $billing_id = $user->stripe_customer_id; // If the user is not authenticated, we just create a new customer object // and assign their email to it } elseif (Auth::guest()) { $customer = $this->createNewCustomer($source, $email); $billing_id = $customer->id; } // Get the amount total in the smallest denominator $amount = $this->calculateAmount($countryCode); event(new OrderWasPlaced($amount, $billing_id, $order)); return response()->json(['success' => true, 'message' => 'Your order is now pending, we will let you know!'], 200); }