public function signup()
 {
     $payment_settings = PaymentSetting::first();
     if ($payment_settings->live_mode) {
         User::setStripeKey($payment_settings->live_secret_key);
     } else {
         User::setStripeKey($payment_settings->test_secret_key);
     }
     $token = Input::get('stripeToken');
     $user_data = array('username' => Input::get('username'), 'email' => Input::get('email'), 'password' => Hash::make(Input::get('password')));
     $input = Input::all();
     unset($input['stripeToken']);
     $validation = Validator::make($input, User::$rules);
     if ($validation->fails()) {
         //echo $validation->messages();
         //print_r($validation->errors()); die();
         return Redirect::to('/signup')->with(array('note' => 'Sorry, there was an error creating your account.', 'note_type' => 'error', 'messages'))->withErrors($validation)->withInput(\Request::only('username', 'email'));
     }
     $user = new User($user_data);
     $user->save();
     try {
         $user->subscription('monthly')->create($token, ['email' => $user->email]);
         Auth::loginUsingId($user->id);
         return Redirect::to('/')->with(array('note' => 'Welcome! Your Account has been Successfully Created!', 'note_type' => 'success'));
     } catch (Exception $e) {
         Auth::logout();
         $user->delete();
         return Redirect::to('/signup')->with(array('note' => 'Sorry, there was an error with your card: ' . $e->getMessage(), 'note_type' => 'error'))->withInput(\Request::only('username', 'email'));
     }
 }
 /**
  * Setup the layout used by the controller.
  *
  * @return void
  */
 public function index()
 {
     $start = (new Carbon('now'))->hour(0)->minute(0)->second(0);
     $end = (new Carbon('now'))->hour(23)->minute(59)->second(59);
     $total_subscribers = count(User::where('active', '=', 1)->where('role', '=', 'subscriber')->where('stripe_active', '=', 1)->get());
     $new_subscribers = count(User::where('active', '=', 1)->where('role', '=', 'subscriber')->where('stripe_active', '=', 1)->whereBetween('created_at', [$start, $end])->get());
     $total_videos = count(Video::where('active', '=', 1)->get());
     $total_posts = count(Post::where('active', '=', 1)->get());
     $settings = Setting::first();
     $data = array('admin_user' => Auth::user(), 'total_subscribers' => $total_subscribers, 'new_subscribers' => $new_subscribers, 'total_videos' => $total_videos, 'total_posts' => $total_posts, 'settings' => $settings);
     return View::make('admin.index', $data);
 }
 /**
  * Display the specified post.
  *
  * @param  int  $id
  * @return Response
  */
 public function index($slug)
 {
     $post = Post::where('slug', '=', $slug)->first();
     //Make sure post is active
     if (!Auth::guest() && Auth::user()->role == 'admin' || $post->active) {
         $author = User::find($post->user_id);
         $data = array('post' => $post, 'author' => $author, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
         return View::make('Theme::post', $data);
     } else {
         return Redirect::to('posts')->with(array('note' => 'Sorry, this post is no longer active.', 'note_type' => 'error'));
     }
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
 public function destroy($id)
 {
     User::destroy($id);
     return Redirect::to('admin/users')->with(array('note' => 'Successfully Deleted User', 'note_type' => 'success'));
 }
 public function renew($username)
 {
     $user = User::where('username', '=', $username)->first();
     $payment_settings = PaymentSetting::first();
     if ($payment_settings->live_mode) {
         User::setStripeKey($payment_settings->live_secret_key);
     } else {
         User::setStripeKey($payment_settings->test_secret_key);
     }
     if (Auth::user()->username == $username) {
         $data = array('user' => $user, 'post_route' => URL::to('user') . '/' . $user->username . '/update', 'type' => 'renew_subscription', 'menu' => Menu::orderBy('order', 'ASC')->get(), 'payment_settings' => $payment_settings, 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
         return View::make('Theme::user', $data);
     } else {
         return Redirect::to('/');
     }
 }