/** * Updates a component with the entered info. * * @param \CachetHQ\Cachet\Models\Component $component * * @throws \Exception * * @return \CachetHQ\Cachet\Models\Component */ public function postUpdateComponent(Component $component) { if (!$component->update(Binput::except(['_token']))) { throw new Exception(trans('dashboard.components.edit.failure')); } return $component; }
/** * Updates a component with the entered info. * * @param \CachetHQ\Cachet\Models\Component $component * * @throws \Exception * * @return \CachetHQ\Cachet\Models\Component */ public function postUpdateComponent(Component $component) { if (!$component->update(Binput::except(['_token']))) { throw new Exception('Failed to update the component.'); } return $component; }
/** * Updates a project with the entered info. * * @param \Gitamin\Models\Project $project * * @throws \Exception * * @return \Gitamin\Models\Project */ public function postUpdateProject(Project $project) { if (!$project->update(Binput::except(['_token']))) { throw new Exception(trans('dashboard.projects.edit.failure')); } return $project; }
/** * Logs the user in. * * @return \Illuminate\Http\RedirectResponse */ public function postLogin() { if (Auth::attempt(Binput::only(['email', 'password']))) { return Redirect::intended('dashboard'); } Throttle::hit(Request::instance(), 10, 10); return Redirect::back()->withInput(Binput::except('password'))->with('error', 'Invalid email or password'); }
/** * Creates a new team member. * * @return \Illuminate\Http\RedirectResponse */ public function postAddUser() { try { $this->dispatch(new AddTeamMemberCommand(Binput::get('username'), Binput::get('password'), Binput::get('email'), Binput::get('level'))); } catch (ValidationException $e) { return Redirect::route('dashboard.team.add')->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.add.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.team.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.add.success'))); }
/** * Get all groups. * * @return \Illuminate\Http\JsonResponse */ public function getGroups() { $groups = ComponentGroup::query(); $groups->search(Binput::except(['sort', 'order', 'per_page'])); if ($sortBy = Binput::get('sort')) { $direction = Binput::has('order') && Binput::get('order') == 'desc'; $groups->sort($sortBy, $direction); } $groups = $groups->paginate(Binput::get('per_page', 20)); return $this->paginator($groups, Request::instance()); }
/** * Get all incidents. * * @return \Illuminate\Http\JsonResponse */ public function getIncidents() { $incidentVisibility = app(Guard::class)->check() ? 0 : 1; $incidents = Incident::where('visible', '>=', $incidentVisibility); $incidents->search(Binput::except(['sort', 'order', 'per_page'])); if ($sortBy = Binput::get('sort')) { $direction = Binput::has('order') && Binput::get('order') == 'desc'; $incidents->sort($sortBy, $direction); } $incidents = $incidents->paginate(Binput::get('per_page', 20)); return $this->paginator($incidents, Request::instance()); }
/** * Logs the user in. * * @return \Illuminate\Http\RedirectResponse */ public function postLogin() { $loginData = Binput::only(['email', 'password']); // Validate login credentials. if (Auth::validate($loginData)) { // Log the user in for one request. Auth::once($loginData); // We probably want to add support for "Remember me" here. Auth::attempt($loginData); return Redirect::intended('dashboard'); } return Redirect::route('auth.login')->withInput(Binput::except('password'))->withError(trans('forms.login.invalid')); }
/** * 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'))); }
/** * Create a new subscriber. * * @return \Illuminate\Http\JsonResponse */ public function postSubscribers() { $subscriberData = Binput::except('verify'); try { $subscriber = Subscriber::create($subscriberData); } catch (Exception $e) { throw new BadRequestHttpException(); } // If we're auto-verifying the subscriber, don't bother with this event. if (!Binput::get('verify')) { event(new CustomerHasSubscribedEvent($subscriber)); } return $this->item($subscriber); }
/** * Create a new Comment row in the database table. * * @param \KieranSmith\Facebook\Models\User * @param \KieranSmith\Facebook\Models\Status * * @return \Illuminate\Http\RedirectResponse */ public function comment($statusOwner, $status) { $user = Auth::user(); $statusOwnerID = $statusOwner['id']; $statusID = $status['id']; $theComment = Binput::except(['_token']); $commentData = ['status_id' => $statusID, 'user_id' => $user['id'], 'comment' => $theComment['comment']]; $comment = Comment::create($commentData); if ($user['id'] == $statusOwnerID) { return Redirect::to('me'); } else { return Redirect::to('person/' . $statusOwnerID); } }
/** * Get all components. * * @return \Illuminate\Http\JsonResponse */ public function getComponents() { if (app(Guard::class)->check()) { $components = Component::whereRaw('1 = 1'); } else { $components = Component::enabled(); } $components->search(Binput::except(['sort', 'order', 'per_page'])); if ($sortBy = Binput::get('sort')) { $direction = Binput::has('order') && Binput::get('order') == 'desc'; $components->sort($sortBy, $direction); } $components = $components->paginate(Binput::get('per_page', 20)); return $this->paginator($components, Request::instance()); }
/** * Update an existing component. * * @param \CachetHQ\Cachet\Models\Componet $component * * @return \CachetHQ\Cachet\Models\Component */ public function putComponent(Component $component) { $component->update(Binput::except('tags')); if (!$component->isValid('updating')) { throw new BadRequestHttpException(); } if (Binput::has('tags')) { $tags = preg_split('/ ?, ?/', Binput::get('tags')); // For every tag, do we need to create it? $componentTags = array_map(function ($taggable) use($component) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $component->tags()->sync($componentTags); } return $this->item($component); }
/** * Handle a signup request. * * @param string|null $code * * @return \Illuminate\View\View */ public function postSignup($code = null) { if ($code === null) { throw new NotFoundHttpException(); } $invite = Invite::where('code', '=', $code)->first(); if (!$invite || $invite->is_claimed) { throw new BadRequestHttpException(); } try { dispatch(new SignupUserCommand(Binput::get('username'), Binput::get('password'), Binput::get('email'), User::LEVEL_USER)); } catch (ValidationException $e) { return Redirect::route('signup.invite', ['code' => $invite->code])->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('cachet.signup.failure')))->withErrors($e->getMessageBag()); } dispatch(new ClaimInviteCommand($invite)); return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success'))); }
/** * Logs the user in. * * @return \Illuminate\Http\RedirectResponse */ public function postLogin() { $loginData = Binput::only(['email', 'password']); // Validate login credentials. if (Auth::validate($loginData)) { // Log the user in for one request. Auth::once($loginData); // Do we have Two Factor Auth enabled? if (Auth::user()->hasTwoFactor) { // Temporarily store the user. Session::put('2fa_id', Auth::user()->id); return Redirect::route('auth.two-factor'); } // We probably want to add support for "Remember me" here. Auth::attempt($loginData); return Redirect::intended('dashboard'); } return Redirect::route('auth.login')->withInput(Binput::except('password'))->withError(trans('forms.login.invalid')); }
/** * 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); }
/** * Handle the unsubscribe. * * @param string|null $code * * @return \Illuminate\View\View */ public function postSignup($code = null) { /* if ($code === null) { throw new NotFoundHttpException(); } $invite = Invite::where('code', '=', $code)->first(); if (!$invite || $invite->claimed()) { throw new BadRequestHttpException(); } */ try { $user = $this->dispatch(new SignupUserCommand(Binput::get('username'), Binput::get('password'), Binput::get('email'), 2)); $namespaceData = ['name' => $user->username, 'path' => $user->username, 'owner_id' => $user->id, 'description' => '', 'type' => 'user']; $this->dispatchFromArray(AddProjectNamespaceCommand::class, $namespaceData); } catch (ValidationException $e) { return Redirect::route('auth.signup', ['code' => $code])->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure')))->withErrors($e->getMessageBag()); } //$this->dispatch(new ClaimInviteCommand($invite)); return Redirect::route('auth.login')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('gitamin.signup.success'))); }
/** * Creates a new group member. * * @return \Illuminate\Http\RedirectResponse */ public function postInviteUser() { try { $this->dispatch(new InviteGroupMemberCommand(array_unique(array_filter((array) Binput::get('emails'))))); } catch (ValidationException $e) { return Redirect::route('dashboard.group.invite')->withInput(Binput::except('password'))->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.group.invite.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.group.invite')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.group.invite.success'))); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { if (Binput::get('remove_banner') == "1") { $setting = Setting::where('name', 'app_banner'); $setting->delete(); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::back()->withErrorMessage("You need to upload an image that is less than {$maxSize}."); } if (!$file->isValid() || $file->getError()) { return Redirect::back()->withErrorMessage($file->getErrorMessage()); } if (strpos($file->getMimeType(), 'image/') !== 0) { return Redirect::back()->withErrorMessage('Only images may be uploaded.'); } // Store the banner. Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]); // Store the banner type Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]); } try { foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) { Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]); } } catch (Exception $e) { return Redirect::back()->withSaved(false); } return Redirect::back()->withSaved(true); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $setting = app(Repository::class); if (Binput::get('remove_banner') === '1') { $setting->set('app_banner', null); } $parameters = Binput::all(); if (isset($parameters['header'])) { if ($header = Binput::get('header', null, false, false)) { $setting->set('header', $header); } else { $setting->delete('header'); } } if (isset($parameters['footer'])) { if ($footer = Binput::get('footer', null, false, false)) { $setting->set('footer', $footer); } else { $setting->delete('footer'); } } if (Binput::hasFile('app_banner')) { $this->handleUpdateBanner($setting); } $excludedParams = ['_token', 'app_banner', 'remove_banner', 'header', 'footer']; try { foreach (Binput::except($excludedParams) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } $setting->set($settingName, $settingValue); } } catch (Exception $e) { return Redirect::back()->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::back()->withSuccess(trans('dashboard.settings.edit.success')); }
/** * Updates the users 'about me' information. * * @return \Illuminate\Http\RedirectResponse */ public function about() { $user = Auth::user(); $aboutData = Binput::except(['_token']); $user->about = $aboutData['about']; $user->save(); return Redirect::to('me'); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup')); if (Binput::get('remove_banner') === '1') { $setting = Setting::where('name', 'app_banner'); $setting->delete(); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.too-big', ['size' => $maxSize])); } if (!$file->isValid() || $file->getError()) { return Redirect::to($redirectUrl)->withErrors($file->getErrorMessage()); } if (!starts_with($file->getMimeType(), 'image/')) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.images-only')); } // Store the banner. Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]); // Store the banner type Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]); } try { foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]); } } catch (Exception $e) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::to($redirectUrl)->withSuccess(trans('dashboard.settings.edit.success')); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup')); $setting = app('setting'); if (Binput::get('remove_banner') === '1') { $setting->set('app_banner', null); } if ($header = Binput::get('header', null, false, false)) { $setting->set('header', $header); } if ($footer = Binput::get('footer', null, false, false)) { $setting->set('footer', $footer); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.too-big', ['size' => $maxSize])); } if (!$file->isValid() || $file->getError()) { return Redirect::to($redirectUrl)->withErrors($file->getErrorMessage()); } if (!starts_with($file->getMimeType(), 'image/')) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.images-only')); } // Store the banner. $setting->set('app_banner', base64_encode(file_get_contents($file->getRealPath()))); // Store the banner type. $setting->set('app_banner_type', $file->getMimeType()); } $excludedParams = ['_token', 'app_banner', 'remove_banner', 'header', 'footer']; try { foreach (Binput::except($excludedParams) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } $setting->set($settingName, $settingValue); } } catch (Exception $e) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::to($redirectUrl)->withSuccess(trans('dashboard.settings.edit.success')); }