/**
  * View a blog post.
  *
  * @param  string  $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     $user = $this->user->currentUser();
     $canComment = $user->can('post_comment');
     if (!$canComment) {
         return Redirect::to($slug . '#comments')->with('error', Lang::get('site.login_to_post'));
     }
     // Get this blog post data
     $post = $this->post->where('slug', '=', $slug)->first();
     // Declare the rules for the form validation
     $rules = array('comment' => 'required|min:3', 'comment_hp' => 'honeypot', 'comment_time' => 'required|honeytime:5');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Save the comment
         $comment = new Comment();
         $comment->user_id = Auth::user()->id;
         $comment->content = Input::get('comment');
         // Was the comment saved with success?
         if ($post->comments()->save($comment)) {
             // Redirect to this blog post page
             return Redirect::to($slug . '#comments')->with('success', Lang::get('site.comment_added'));
         }
         // Redirect to this blog post page
         return Redirect::to($slug . '#comments')->with('error', Lang::get('site.comment_not_Added'));
     }
     // Redirect to this blog post page
     return Redirect::to($slug)->withInput()->withErrors($validator);
 }
 /**
  * View a blog post.
  *
  * @param  string  $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     $user = $this->user->currentUser();
     $canComment = $user->can('post_comment');
     if (!$canComment) {
         return Redirect::to($slug . '#comments')->with('error', 'You need to be logged in to post comments!');
     }
     // Get this blog post data
     $post = $this->post->where('slug', '=', $slug)->first();
     // Declare the rules for the form validation
     $rules = array('comment' => 'required|min:3');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Save the comment
         $comment = new Comment();
         $comment->user_id = Auth::user()->id;
         $comment->content = Input::get('comment');
         // Was the comment saved with success?
         if ($post->comments()->save($comment)) {
             // Redirect to this blog post page
             return Redirect::to($slug . '#comments')->with('success', 'Your comment was added with success.');
         }
         // Redirect to this blog post page
         return Redirect::to($slug . '#comments')->with('error', 'There was a problem adding your comment, please try again.');
     }
     // Redirect to this blog post page
     return Redirect::to($slug)->withInput()->withErrors($validator);
 }
Example #3
0
 /**
  * View a blog post.
  *
  * @param  string  $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     $user = $this->user->currentUser();
     // Get this blog post data
     $client = $this->client->where('slug', '=', $slug)->first();
     // Redirect to this blog post page
     return Redirect::to($slug);
 }
Example #4
0
 public function getUserShow()
 {
     $user = $this->user->currentUser();
     if (empty($user)) {
         return Redirect::to('user/login');
     }
     $userpics = $this->userpic->where('user_id', '=', $user->id)->orderBy('created_at', 'DESC')->take(4)->get();
     //		$user = $this->user->where('id', '=', $user)->first();
     //		if(is_null($user)){
     //				return App::abort(404);
     //		}
     //		//判断是否是用户自己, 若是别人则不显示上传图片和发表攻略链接。
     //		$user = $this->user->currentUser();
     //		if(!empty($user)){
     //				return App::abort(404);
     //		}
     //		//结束判断
     return View::make('fiji/user/user', compact('user', 'userpics'));
 }
Example #5
0
 public static function favoritesForCurrentUser($cookies)
 {
     $currentUser = User::currentUser($cookies);
     $retval = new Favorites();
     $retval->whereRestriction = 'ratings.user_ip = "' . $currentUser->remoteAddr . '"';
     if ($currentUser->isLoggedIn) {
         ///TODO security: need to bind user name
         $retval->whereRestriction = 'ratings.username = "******"';
     }
     return $retval;
 }
Example #6
0
 /**
  * View a blog post.
  *
  * @param  string  $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     $user = $this->user->currentUser();
     $canComment = $user->can('post_comment');
     if (!$canComment) {
         return Redirect::to($slug . '#comments')->with('error', 'You need to be logged in to post comments!');
     }
     $post = $this->post->where('slug', '=', $slug)->first();
     $rules = array('comment' => 'required|min:3');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         $comment = new Comment();
         $comment->user_id = Auth::user()->id;
         $comment->content = Input::get('comment');
         if ($post->comments()->save($comment)) {
             return Redirect::to($slug . '#comments')->with('success', 'Your comment was added with success.');
         }
         return Redirect::to($slug . '#comments')->with('error', 'There was a problem adding your comment, please try again.');
     }
     return Redirect::to($slug)->withInput()->withErrors($validator);
 }
Example #7
0
 /**
  * Summary of getCurrent
  * @param PdoDatabase $database
  * @return User The currently logged in user, or an anonymous coward with userid -1.
  */
 public static function getCurrent(PdoDatabase $database = null)
 {
     if ($database === null) {
         $database = gGetDb();
     }
     if (self::$currentUser === null) {
         if (isset($_SESSION['userID'])) {
             self::$currentUser = self::getById($_SESSION['userID'], $database);
         } else {
             $anonymousCoward = new CommunityUser();
             self::$currentUser = $anonymousCoward;
         }
     }
     return self::$currentUser;
 }