/** * Update an existing metric. * * @param \CachetHQ\Cachet\Models\Metric $metric * * @return \CachetHQ\Cachet\Models\Metric */ public function putMetric(Metric $metric) { $metric->update(Binput::all()); if ($metric->isValid('updating')) { return $this->item($metric); } throw new BadRequestHttpException(); }
/** * Update an existing incident. * * @param \CachetHQ\Cachet\Models\Inicdent $incident * * @return \CachetHQ\Cachet\Models\Incident */ public function putIncident(Incident $incident) { $incident->update(Binput::all()); if ($incident->isValid('updating')) { return $this->item($incident); } throw new BadRequestHttpException(); }
/** * Handle the subscribe user. * * @return \Illuminate\View\View */ public function postSubscribe() { try { $this->dispatch(new SubscribeSubscriberCommand(Binput::get('email'))); } catch (ValidationException $e) { return Redirect::route('subscribe.subscribe')->withInput(Binput::all())->withTitle(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.whoops'), trans('gitamin.subscriber.email.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('explore')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('gitamin.subscriber.email.subscribed'))); }
/** * Update an existing metric. * * @param \CachetHQ\Cachet\Models\Metric $metric * * @return \Illuminate\Http\JsonResponse */ public function putMetric(Metric $metric) { try { $metric->update(Binput::all()); } catch (Exception $e) { throw new BadRequestHttpException(); } return $this->item($metric); }
/** * Creates a new subscriber. * * @return \Illuminate\Http\RedirectResponse */ public function createSubscriberAction() { try { dispatch(new SubscribeSubscriberCommand(Binput::get('email'))); } catch (ValidationException $e) { return Redirect::route('dashboard.subscribers.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.subscribers.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success'))); }
/** * Update an existing incident. * * @param \CachetHQ\Cachet\Models\Inicdent $incident * * @return \Illuminate\Http\JsonResponse */ public function putIncident(Incident $incident) { try { $incident->update(Binput::all()); } catch (Exception $e) { throw new BadRequestHttpException(); } return $this->item($incident); }
/** * Handle the subscribe user. * * @return \Illuminate\View\View */ public function postSubscribe() { $subscriber = Subscriber::create(['email' => Binput::get('email')]); if (!$subscriber->isValid()) { return Redirect::back()->withInput(Binput::all())->with('title', sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))->with('errors', $subscriber->getErrors()); } $successMsg = sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.subscribed')); event(new CustomerHasSubscribedEvent($subscriber)); return Redirect::route('status-page')->with('success', $successMsg); }
/** * Handle the subscribe user. * * @return \Illuminate\View\View */ public function postSubscribe() { try { $subscriber = Subscriber::create(['email' => Binput::get('email')]); } catch (ValidationException $e) { return Redirect::route('subscribe.subscribe')->withInput(Binput::all())->withTitle(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))->withErrors($e->getMessageBag()); } event(new CustomerHasSubscribedEvent($subscriber)); return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.subscribed'))); }
/** * Creates a new subscriber. * * @return \Illuminate\Http\RedirectResponse */ public function createSubscriberAction() { $email = Binput::get('email'); $subscriber = Subscriber::create(['email' => $email]); if (!$subscriber->isValid()) { return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure')))->with('errors', $subscriber->getErrors()); } $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success')); event(new CustomerHasSubscribedEvent($subscriber)); return Redirect::back()->with('success', $successMsg); }
/** * Creates a new subscriber. * * @return \Illuminate\Http\RedirectResponse */ public function createSubscriberAction() { $email = Binput::get('email'); try { $subscriber = Subscriber::create(['email' => $email]); } catch (ValidationException $e) { return Redirect::route('dashboard.subscribers.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure')))->withErrors($e->getMessageBag()); } event(new CustomerHasSubscribedEvent($subscriber)); return Redirect::route('dashboard.subscribers.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success'))); }
/** * Updates a metric point. * * @param \CachetHQ\Cachet\Models\Metric $metric * @param \CachetHQ\Cachet\Models\MetircPoint $metricPoint * * @return \Illuminate\Http\JsonResponse */ public function putMetricPoint(Metric $metric, MetricPoint $metricPoint) { $metricPointData = Binput::all(); $metricPointData['metric_id'] = $metric->id; if ($timestamp = array_pull($metricPointData, 'timestamp')) { $pointTimestamp = Carbon::createFromFormat('U', $timestamp); $metricPointData['created_at'] = $pointTimestamp->format('Y-m-d H:i:s'); } $metricPoint->update($metricPointData); return $this->item($metricPoint); }
/** * Updates a components ordering. * * @return array */ public function postUpdateComponentOrder() { $componentData = Binput::all(); unset($componentData['component'][0]); // Remove random 0 index. foreach ($componentData['component'] as $componentId => $order) { $component = Component::find($componentId); $component->update(['order' => $order]); } return $componentData; }
/** * Handle the subscribe user. * * @return \Illuminate\View\View */ public function postSubscribe() { $email = Binput::get('email'); try { dispatch(new SubscribeSubscriberCommand($email)); } catch (AlreadySubscribedException $e) { return Redirect::route('subscribe.subscribe')->withTitle(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))->withErrors(trans('cachet.subscriber.email.already-subscribed', ['email' => $email])); } catch (ValidationException $e) { return Redirect::route('subscribe.subscribe')->withInput(Binput::all())->withTitle(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.subscribed'))); }
/** * Creates a new subscriber. * * @return \Illuminate\Http\RedirectResponse */ public function createSubscriberAction() { $verified = app(Repository::class)->get('setting.skip_subscriber_verification'); try { $subscribers = preg_split("/\r\n|\n|\r/", Binput::get('email')); foreach ($subscribers as $subscriber) { dispatch(new SubscribeSubscriberCommand($subscriber, $verified)); } } catch (ValidationException $e) { return Redirect::route('dashboard.subscribers.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.subscribers.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success'))); }
/** * Updates a user. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\View\View */ public function postUpdateUser(User $user) { $items = Binput::all(); $passwordChange = array_get($items, 'password'); if (trim($passwordChange) === '') { unset($items['password']); } $user->update($items); if (!$user->isValid()) { return Redirect::back()->withInput(Binput::except('password'))->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->with('errors', $user->getErrors()); } $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')); return Redirect::back()->with('success', $successMsg); }
/** * Updates a user. * * @param \CachetHQ\Cachet\Models\User $user * * @return \Illuminate\View\View */ public function postUpdateUser(User $user) { $items = Binput::all(); $passwordChange = array_get($items, 'password'); if (trim($passwordChange) === '') { unset($items['password']); } try { $user->update($items); } catch (ValidationException $e) { return Redirect::back()->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::back()->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success'))); }
/** * Handles the actual app setup. * * @return \Illuminate\Http\RedirectResponse */ public function postIndex() { $postData = Binput::all(); $v = Validator::make($postData, ['settings.app_name' => 'required', 'settings.app_domain' => 'required', 'settings.show_support' => 'boolean', 'user.username' => 'alpha_dash|required', 'user.email' => 'email|required', 'user.password' => 'required']); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); // TODO: Do we want to just use Model::unguard() here? $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => 1]); Auth::login($user); $settings = array_get($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { Setting::create(['name' => $settingName, 'value' => $settingValue]); } return Redirect::to('dashboard'); } else { // No good, let's try that again. return Redirect::back()->withInput()->with('errors', $v->messages()); } }
/** * Updates the current user. * * @return \Illuminate\View\View */ public function postUser() { $items = Binput::all(); $passwordChange = array_get($items, 'password'); $enable2FA = (bool) array_pull($items, 'google2fa'); // Let's enable/disable auth if ($enable2FA && !Auth::user()->hasTwoFactor) { $items['google_2fa_secret'] = Google2FA::generateSecretKey(); } elseif (!$enable2FA) { $items['google_2fa_secret'] = ''; } if (trim($passwordChange) === '') { unset($items['password']); } try { Auth::user()->update($items); } catch (ValidationException $e) { return Redirect::back()->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::back()->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success'))); }
/** * Updates the current user. * * @return \Illuminate\View\View */ public function postUser() { $items = Binput::all(); $passwordChange = array_get($items, 'password'); $enable2FA = (bool) array_pull($items, 'google2fa'); // Let's enable/disable auth if ($enable2FA && !Auth::user()->hasTwoFactor) { $items['google_2fa_secret'] = Google2FA::generateSecretKey(); } elseif (!$enable2FA) { $items['google_2fa_secret'] = ''; } if (trim($passwordChange) === '') { unset($items['password']); } $user = Auth::user(); $user->update($items); if (!$user->isValid()) { return Redirect::back()->withInput(Binput::except('password'))->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->with('errors', $user->getErrors()); } $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')); return Redirect::back()->with('success', $successMsg); }
/** * Updates the given incident. * * @param \CachetHQ\Cachet\Models\Incident $schedule * @param \CachetHQ\Cachet\Dates\DateFactory $dates * * @return \Illuminate\Http\RedirectResponse */ public function editScheduleAction(Incident $schedule, DateFactory $dates) { $scheduleData = Binput::get('incident'); // Parse the schedule date. $scheduledAt = $dates->createNormalized('d/m/Y H:i', $scheduleData['scheduled_at']); if ($scheduledAt->isPast()) { $messageBag = new MessageBag(); $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied'])); return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withErrors($messageBag); } $scheduleData['scheduled_at'] = $scheduledAt; // Bypass the incident.status field. $scheduleData['status'] = 0; try { $schedule->update($scheduleData); } catch (ValidationException $e) { return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success'))); }
/** * Edit an metric. * * @param \CachetHQ\Cachet\Models\Metric $metric * * @return \Illuminate\Http\RedirectResponse */ public function editMetricAction(Metric $metric) { $metricData = Binput::get('metric', null, false); $metric->update($metricData); if (!$metric->isValid()) { return Redirect::back()->withInput(Binput::all())->with('title', sprintf('<strong>%s</strong>', trans('dashboard.notifications.awesome')))->with('errors', $metric->getErrors()); } $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.edit.success')); return Redirect::to('dashboard/metrics')->with('success', $successMsg); }
/** * Update an existing incident. * * @param int $id * * @return \CachetHQ\Cachet\Models\Incident */ public function putIncident($id) { return $this->incident->update($id, Binput::all()); }
/** * Handles the actual app setup, including user, settings and env. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ public function postStep3() { $postData = Binput::all(); $v = Validator::make($postData, $this->rulesStep1 + $this->rulesStep2 + $this->rulesStep3); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => User::LEVEL_ADMIN]); Auth::login($user); $setting = app('setting'); $settings = array_pull($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { $setting->set($settingName, $settingValue); } $envData = array_pull($postData, 'env'); // Write the env to the .env file. foreach ($envData as $envKey => $envValue) { $this->writeEnv($envKey, $envValue); } Session::flash('setup.done', true); if (Request::ajax()) { return Response::json(['status' => 1]); } return Redirect::to('dashboard'); } if (Request::ajax()) { return Response::json(['errors' => $v->getMessageBag()], 400); } return Redirect::route('setup.index')->withInput()->withErrors($v->getMessageBag()); }
/** * Edit an incident. * * @param \CachetHQ\Cachet\Models\Incident $incident * * @return \Illuminate\Http\RedirectResponse */ public function editIncidentAction(Incident $incident) { $incidentData = Binput::get('incident'); if (array_has($incidentData, 'created_at') && $incidentData['created_at']) { $incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); $incidentData['created_at'] = $incidentDate; $incidentData['updated_at'] = $incidentDate; } else { unset($incidentData['created_at']); } try { $incident->update($incidentData); } catch (ValidationException $e) { return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure')))->withErrors($e->getMessageBag()); } $componentStatus = array_pull($incidentData, 'component_status'); if ($incident->component) { $incident->component->update(['status' => $componentStatus]); } return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success'))); }
/** * Updates the given incident. * * @param \CachetHQ\Cachet\Models\Incident $schedule * * @return \Illuminate\Http\RedirectResponse */ public function editScheduleAction(Incident $schedule) { $scheduleData = Binput::get('incident'); // Parse the schedule date. $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); if ($scheduledAt->isPast()) { $messageBag = new MessageBag(); $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied'])); return Redirect::back()->withErrors($messageBag); } $scheduleData['scheduled_at'] = $scheduledAt; // Bypass the incident.status field. $scheduleData['status'] = 0; $schedule->update($scheduleData); if (!$schedule->isValid()) { segment_track('Dashboard', ['event' => 'Edited Schedule', 'success' => false]); return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->with('errors', $schedule->getErrors()); } segment_track('Dashboard', ['event' => 'Edited Schedule', 'success' => true]); $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success')); return Redirect::to('dashboard/schedule')->with('success', $successMsg); }
/** * Updates a component group. * * @param \CachetHQ\Cachet\Models\ComponentGroup $group * * @return \Illuminate\Http\RedirectResponse */ public function updateComponentGroupAction(ComponentGroup $group) { try { $group = $this->dispatch(new UpdateComponentGroupCommand($group, Binput::get('name'), Binput::get('order', 0))); } catch (ValidationException $e) { return Redirect::route('dashboard.components.groups.edit', ['id' => $group->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.components.groups.edit', ['id' => $group->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.edit.success'))); }
/** * Edit an incident. * * @param \CachetHQ\Cachet\Models\Incident $incident * * @return \Illuminate\Http\RedirectResponse */ public function editIncidentAction(Incident $incident) { try { $incident = dispatch(new UpdateIncidentCommand($incident, Binput::get('name'), Binput::get('status'), Binput::get('message'), Binput::get('visible', true), Binput::get('component_id'), Binput::get('component_status'), Binput::get('notify', true), Binput::get('created_at'), null, null)); } catch (ValidationException $e) { return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure')))->withErrors($e->getMessageBag()); } if ($incident->component) { $incident->component->update(['status' => Binput::get('component_status')]); } return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success'))); }
/** * Updates a component group. * * @param \CachetHQ\Cachet\Models\ComponentGroup $group * * @return \Illuminate\Http\RedirectResponse */ public function updateComponentGroupAction(ComponentGroup $group) { $groupData = Binput::get('group'); try { $group->update($groupData); } catch (ValidationException $e) { return Redirect::route('dashboard.components.group.edit', ['id' => $group->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.components.group.edit', ['id' => $group->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.edit.success'))); }
/** * Handles the actual app setup, including user, settings and env. * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ public function postStep3() { $postData = Binput::all(); $v = Validator::make($postData, ['env.cache_driver' => 'required|in:' . implode(',', array_keys($this->cacheDrivers)), 'env.session_driver' => 'required|in:' . implode(',', array_keys($this->cacheDrivers)), 'settings.app_name' => 'required', 'settings.app_domain' => 'required', 'settings.app_timezone' => 'required', 'settings.app_locale' => 'required', 'settings.show_support' => 'boolean', 'user.username' => ['required', 'regex:/\\A(?!.*[:;]-\\))[ -~]+\\z/'], 'user.email' => 'email|required', 'user.password' => 'required']); if ($v->passes()) { // Pull the user details out. $userDetails = array_pull($postData, 'user'); $user = User::create(['username' => $userDetails['username'], 'email' => $userDetails['email'], 'password' => $userDetails['password'], 'level' => 1]); Auth::login($user); $settings = array_pull($postData, 'settings'); foreach ($settings as $settingName => $settingValue) { Setting::create(['name' => $settingName, 'value' => $settingValue]); } $envData = array_pull($postData, 'env'); // Write the env to the .env file. foreach ($envData as $envKey => $envValue) { $this->writeEnv($envKey, $envValue); } Session::flash('setup.done', true); if (Request::ajax()) { return Response::json(['status' => 1]); } return Redirect::to('dashboard'); } if (Request::ajax()) { return Response::json(['errors' => $v->getMessageBag()], 400); } return Redirect::back()->withInput()->withErrors($v->getMessageBag()); }
/** * Edit an metric. * * @param \CachetHQ\Cachet\Models\Metric $metric * * @return \Illuminate\Http\RedirectResponse */ public function editMetricAction(Metric $metric) { try { $metric->update(Binput::get('metric', null, false)); } catch (ValidationException $e) { return Redirect::route('dashboard.metrics.edit', ['id' => $metric->id])->withInput(Binput::all())->withTitle(sprintf('<strong>%s</strong>', trans('dashboard.notifications.whoops')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.metrics.edit', ['id' => $metric->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.edit.success'))); }