/**
  * Store a newly created Authenticated Session in storage.
  *
  * @return Response
  */
 public function store()
 {
     try {
         // Login credentials
         $credentials = array('email' => Input::get('username'), 'password' => Input::get('password'));
         // Configure throttling
         $throttle = Sentry::findThrottlerByUserLogin($credentials['email']);
         $throttle->setAttemptLimit(5);
         $throttle->setSuspensionTime(30);
         // Authenticate the user
         $user = Sentry::authenticate($credentials, false);
         // Authentication was successful
         $this->check_password_expired($user);
         Session::flash('alert_success', 'Logged in successfully.');
         return Redirect::intended('/dashboard');
     } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
         // echo 'Login field is required.';
         Session::flash('alert_warning', 'Please fill in the required fields marked with a red asterisk.');
         return Redirect::to('/login')->withInput();
     } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) {
         // echo 'Password field is required.';
         Session::flash('alert_warning', 'Please fill in the required fields marked with a red asterisk.');
         return Redirect::to('/login')->withInput();
     } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) {
         // echo 'Wrong password, try again.';
         Session::flash('alert_warning', 'Login failed. Please check your credentials and try again.');
         return Redirect::to('/login')->withInput();
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         // echo 'User was not found.';
         Session::flash('alert_warning', 'Login failed. Please check your credentials and try again.');
         return Redirect::to('/login')->withInput();
     } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) {
         Session::flash('alert_info', 'Your account is pending approval. A representative from ACME will contact you in 1-2 business days.');
         // Session::flash('alert_danger', 'User is not activated.');
         return Redirect::to('/login')->withInput();
     } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) {
         Session::flash('alert_danger', 'Your account is temporarily suspended due to ' . $throttle->getAttemptLimit() . ' failed login attempts. Please try again in ' . $throttle->getSuspensionTime() . ' minutes.');
         return Redirect::to('/login')->withInput();
     } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) {
         Session::flash('alert_danger', 'User is banned.');
         return Redirect::to('/login')->withInput();
     } catch (\RuntimeException $e) {
         // An unexpected error occurred.
         Log::error(date("Y-m-d H:i:s") . '- RuntimeException in app/contorllers/SessionController: ' . '\\$data = ' . print_r($data) . $e);
         Session::flash('alert_danger', 'An unexpected error occurred.');
         return Redirect::to('/login')->withInput();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     // get the application key for creating API Keys, and current time
     $key = Config::get('app.key');
     $now = Carbon::now();
     /**
      * Add users
      */
     // super user
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'first_name' => 'Super', 'last_name' => 'User', 'password' => 'password', 'activated' => 1, 'api_key' => md5('*****@*****.**' . $key . time()), 'permissions' => array('superuser' => 1), 'created_at' => $now, 'updated_at' => $now, 'created_by' => 1, 'updated_by' => 1, 'owned_by' => 1));
     // admin user
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'first_name' => 'Admin', 'last_name' => 'User', 'password' => 'password', 'activated' => 1, 'api_key' => md5('*****@*****.**' . $key . time()), 'permissions' => array(), 'created_at' => $now, 'updated_at' => $now, 'created_by' => 1, 'updated_by' => 1, 'owned_by' => 2));
     // api (regular) user
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'first_name' => 'API', 'last_name' => 'User', 'password' => 'password', 'activated' => 1, 'api_key' => md5('*****@*****.**' . $key . time()), 'permissions' => array(), 'created_at' => $now, 'updated_at' => $now, 'created_by' => 1, 'updated_by' => 1, 'owned_by' => 3));
     // inactive user
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'first_name' => 'Inactive', 'last_name' => 'User', 'password' => 'password', 'activated' => 0, 'api_key' => md5('*****@*****.**' . $key . time()), 'permissions' => array(), 'created_at' => $now, 'updated_at' => $now, 'created_by' => 1, 'updated_by' => 1, 'owned_by' => 4));
     // banned user
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'first_name' => 'Banned', 'last_name' => 'User', 'password' => 'password', 'activated' => 1, 'api_key' => md5('*****@*****.**' . $key . time()), 'permissions' => array(), 'created_at' => $now, 'updated_at' => $now, 'created_by' => 1, 'updated_by' => 1, 'owned_by' => 5));
     $throttle = Sentry::findThrottlerByUserLogin('*****@*****.**');
     $throttle->ban();
     // suspended user
     Sentry::getUserProvider()->create(array('email' => '*****@*****.**', 'first_name' => 'Suspended', 'last_name' => 'User', 'password' => 'password', 'activated' => 1, 'api_key' => md5('*****@*****.**' . $key . time()), 'permissions' => array(), 'created_at' => $now, 'updated_at' => $now, 'created_by' => 1, 'updated_by' => 1, 'owned_by' => 6));
     $throttle = Sentry::findThrottlerByUserLogin('*****@*****.**');
     $throttle->suspend();
     /**
      * Add groups
      */
     Sentry::getGroupProvider()->create(array('name' => 'Administrators', 'permissions' => array('user.put' => 1, 'user.get' => 1, 'user.post' => 1, 'user.delete' => 0, 'foo.put' => 1, 'foo.get' => 1, 'foo.post' => 1, 'foo.delete' => 1, 'bar.put' => 1, 'bar.get' => 1, 'bar.post' => 1, 'bar.delete' => 1)));
     Sentry::getGroupProvider()->create(array('name' => 'API Users', 'permissions' => array('user.put' => 0, 'user.get' => 0, 'user.post' => 0, 'user.delete' => 0, 'foo.put' => 0, 'foo.get' => 1, 'foo.post' => 0, 'foo.delete' => 0, 'bar.put' => 0, 'bar.get' => 1, 'bar.post' => 0, 'bar.delete' => 0)));
     /**
      * Add users to groups
      */
     // get the groups
     $admins = Sentry::getGroupProvider()->findByName('Administrators');
     $api_users = Sentry::getGroupProvider()->findByName('API Users');
     // get the users
     $admin_user = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     $api_user = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     $inactive_user = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     $banned_user = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     $suspended_user = Sentry::getUserProvider()->findByLogin('*****@*****.**');
     // add them to groups
     $admin_user->addGroup($admins);
     $api_user->addGroup($api_users);
     $inactive_user->addGroup($api_users);
     $banned_user->addGroup($api_users);
     $suspended_user->addGroup($api_users);
     // create foos table
     Schema::create('foos', function ($table) {
         $table->increments('id');
         $table->integer('fooint');
         $table->string('foostr');
         $table->date('foodate');
     });
     // create bars table
     Schema::create('bars', function ($table) {
         $table->increments('id');
         $table->integer('barint');
         $table->string('barstr');
         $table->date('bardate');
     });
     // create bazes table
     Schema::create('bazes', function ($table) {
         $table->increments('id');
         $table->integer('bazint');
         $table->string('bazstr');
         $table->date('bazdate');
     });
 }