/**
  * postSignin
  * --------------------------------------------------
  * @return Processes the signin request, signs in the user
  * --------------------------------------------------
  */
 public function postSignin()
 {
     /* Validation */
     $rules = array('email' => 'required|email', 'password' => 'required');
     /* run the validation rules on the inputs */
     $validator = Validator::make(Input::all(), $rules);
     /* Everything is OK */
     if (!$validator->fails() and Auth::attempt(Input::only('email', 'password'))) {
         /* Track event | SIGN IN */
         $tracker = new GlobalTracker();
         $tracker->trackAll('lazy', array('en' => 'Sign in', 'el' => Auth::user()->email));
         /* Make welcome message */
         if (Auth::user()->name) {
             $message = 'Welcome back, ' . Auth::user()->name . '!';
         } else {
             $message = 'Welcome back.';
         }
         /* Redirect to dashboard */
         return Redirect::route('dashboard.dashboard')->with('success', $message);
         /* Something is not OK (bad credentials) */
     } else {
         /* Redirect to signin with error message */
         return Redirect::route('auth.signin')->with('error', 'The provided email address or password is incorrect.')->withInput(Input::except('password'));
     }
 }
 /**
  * postAuthentication
  * --------------------------------------------------
  * @return Saves the user authentication data
  * --------------------------------------------------
  */
 public function postAuthentication()
 {
     /* Validation rules */
     $rules = array('email' => 'required|email|unique:users', 'password' => 'required|min:4');
     /* Run validation rules on the inputs */
     $validator = Validator::make(Input::all(), $rules);
     /* Everything is ok */
     if (!$validator->fails()) {
         /* Create the user */
         $user = $this->createUser(Input::all());
         /* Log in the user*/
         Auth::login($user);
         /* Track events */
         $tracker = new GlobalTracker();
         /* Track event | SIGN UP */
         $tracker->trackAll('lazy', array('en' => 'Sign up', 'el' => Auth::user()->email));
         /* Track event | TRIAL STARTS */
         $tracker->trackAll('lazy', array('en' => 'Trial starts', 'el' => Auth::user()->email));
         /* Redirect to next step */
         return Redirect::route('signup-wizard.personal-widgets');
         /* Validator failed */
     } else {
         /* Render the page */
         return Redirect::route('signup-wizard.authentication')->with('error', $validator->errors()->get(key($validator->invalid()))[0]);
     }
 }
 /**
  * doAddWidget
  * --------------------------------------------------
  * @return Creates a widget instance and sends to wizard.
  * --------------------------------------------------
  */
 public function doAddWidget($descriptorID)
 {
     /* Get the widget descriptor */
     $descriptor = WidgetDescriptor::find($descriptorID);
     if (is_null($descriptor)) {
         return Redirect::back()->with('error', 'Something went wrong, your widget cannot be found.');
     }
     /* Create new widget instance */
     $className = $descriptor->getClassName();
     /* Looking for existing widgets. */
     foreach (Auth::user()->widgets() as $widget) {
         if ($widget->descriptor->type == $descriptor->type) {
             if ($widget->state == 'hidden') {
                 /* The widget is hidden, restoring it. */
                 $widget->state = 'active';
                 $widget->save();
                 return Redirect::route('dashboard.dashboard')->with('success', 'Your hidden widget was restored successfully.');
             } else {
                 /* The widget is active. */
                 return Redirect::route('dashboard.dashboard')->with('error', 'You cannot add multiple instances of this widget type.');
             }
         }
     }
     $widget = new $className(array('settings' => json_encode(array()), 'state' => 'active', 'position' => '{"size_x": 2, "size_y": 2, "row": 0, "col": 0}'));
     $widget->dashboard()->associate(Auth::user()->dashboards[0]);
     $widget->descriptor()->associate($descriptor);
     $widget->save();
     /* Track event | ADD WIDGET */
     $tracker = new GlobalTracker();
     $tracker->trackAll('lazy', array('en' => 'Add widget', 'el' => $className));
     /* If widget has no setup fields, redirect to dashboard automatically */
     $setupFields = $widget->getSetupFields();
     if (empty($setupFields)) {
         return Redirect::route('dashboard.dashboard')->with('success', 'Widget successfully created.');
     }
     return Redirect::route('widget.setup', array($widget->id))->with('success', 'Widget successfully created, please set it up.');
 }
 public function __construct()
 {
     self::$google = new GoogleTracker();
     self::$intercom = new IntercomTracker();
     self::$mixpanel = new MixpanelTracker();
 }