/** * Store a new post. * * @return \Illuminate\Http\Response */ public function store() { $input = array_merge(['user_id' => Credentials::getuser()->id], Binput::only(['title', 'summary', 'body'])); $val = PostRepository::validate($input, array_keys($input)); if ($val->fails()) { return Redirect::route('content.posts.create')->withInput()->withErrors($val->errors()); } $post = PostRepository::create($input); return Redirect::route('content.posts.show', ['posts' => $post->id])->with('success', 'Your post has been created successfully.'); }
/** * Store a new page. * * @return \Illuminate\Http\Response */ public function store() { $input = array_merge($this->getInput(), ['user_id' => Credentials::getuser()->id]); $val = PageRepository::validate($input, array_keys($input)); if ($val->fails()) { return Redirect::route('pages.create')->withInput()->withErrors($val->errors()); } $page = PageRepository::create($input); // write flash message and redirect return Redirect::route('pages.show', ['pages' => $page->slug])->with('success', 'Your page has been created successfully.'); }
/** * Store a new event. * * @return \Illuminate\Http\Response */ public function store() { $input = array_merge(['user_id' => Credentials::getuser()->id], Binput::only(['title', 'location', 'date', 'body'])); $val = EventRepository::validate($input, array_keys($input)); if ($val->fails()) { return Redirect::route('events.create')->withInput()->withErrors($val->errors()); } $input['date'] = Carbon::createFromFormat(Config::get('date.php_format'), $input['date']); $event = EventRepository::create($input); return Redirect::route('events.show', ['events' => $event->id])->with('success', 'Your event has been created successfully.'); }
/** * Store a new comment. * * @param int $postId * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * * @return \Illuminate\Http\JsonResponse */ public function store($postId) { $input = array_merge(Binput::only('body'), ['user_id' => Credentials::getuser()->id, 'post_id' => $postId, 'version' => 1]); if (CommentRepository::validate($input, array_keys($input))->fails()) { throw new BadRequestHttpException('Your comment was empty.'); } $this->throttler->hit(); $comment = CommentRepository::create($input); $contents = View::make('posts.comment', ['comment' => $comment, 'post_id' => $postId]); return Response::json(['success' => true, 'msg' => 'Comment created successfully.', 'contents' => $contents->render(), 'comment_id' => $comment->id], 201); }
/** * Attempt to find the user id of the currently logged in user. * * @return int|null */ protected function getUserId() { if (Credentials::check()) { return Credentials::getUser()->id; } elseif (isset($this['user_id']) && $this['user_id']) { return $this['user_id']; } }
/** * Logout the specified user. * * @return \Illuminate\Http\Response */ public function Logout() { Credentials::logout(); return Redirect::to(Config::get('core.home', '/')); }
/** * Reset the user's password. * * @param int $id * @param string $code * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * * @return \Illuminate\Http\Response */ public function getPassword($id, $code) { if (!$id || !$code) { throw new BadRequestHttpException(); } try { $user = Credentials::getUserProvider()->findById($id); $password = Str::random(); if (!$user->attemptResetPassword($code, $password)) { return Redirect::to(Config::get('core.home', '/'))->with('error', 'There was a problem resetting your password. Please contact support.'); } $mail = ['password' => $password, 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - New Password Information']; Mail::queue('emails.password', $mail, function ($message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); return Redirect::to(Config::get('core.home', '/'))->with('success', 'Your password has been changed. Check your email for the new password.'); } catch (UserNotFoundException $e) { return Redirect::to(Config::get('core.home', '/'))->with('error', 'There was a problem resetting your password. Please contact support.'); } }
/** * Update the user's password. * * @return \Illuminate\Http\Response */ public function patchPassword() { $input = Binput::only(['password', 'password_confirmation']); $val = UserRepository::validate($input, array_keys($input)); if ($val->fails()) { return Redirect::route('account.profile')->withInput()->withErrors($val->errors()); } unset($input['password_confirmation']); $user = Credentials::getUser(); $this->checkUser($user); $mail = ['url' => URL::to(Config::get('core.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - New Password Notification']; Mail::queue('emails.newpass', $mail, function ($message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); $user->update($input); return Redirect::route('account.profile')->with('success', 'Your password has been updated successfully.'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $this->credentials->getThrottleProvider()->enable(); return $next($request); }
/** * Suspend an existing user. * * @param int $id * * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * * @return \Illuminate\Http\Response */ public function suspend($id) { try { $throttle = Credentials::getThrottleProvider()->findByUserId($id); $throttle->suspend(); } catch (UserNotFoundException $e) { throw new NotFoundHttpException('User Not Found', $e); } catch (UserSuspendedException $e) { $time = $throttle->getSuspensionTime(); return Redirect::route('users.suspend', ['users' => $id])->withInput()->with('error', "This user is already suspended for {$time} minutes."); } catch (UserBannedException $e) { return Redirect::route('users.suspend', ['users' => $id])->withInput()->with('error', 'This user has already been banned.'); } return Redirect::route('users.show', ['users' => $id])->with('success', 'The user has been suspended successfully.'); }