/**
  *This method checks for the logged in user.
  *@param null
  *@return void
  */
 public function __construct()
 {
     //check for logged in user
     if (!Session::get('userInfo') or Session::get('userInfo')['user_type'] != 'admin') {
         Redirect::to('home');
     }
 }
 /**
  *This method parses user submitted login info 
  *
  *@param array $data The user information submitted inthe form data
  *@return void
  */
 public function postIndex()
 {
     //prepare user info to send to the database
     $data = array('email' => Input::get('email'), 'password' => Input::get('password'));
     //check if use exists
     $user = UsersModel::checkUser($data);
     //check if user was found
     if ($user) {
         //check if the passwords do not match
         if ($user['password'] != md5($data['password'])) {
             //reload the form with error message
             $data['error'] = 'Invalid Password. Try again!';
             //load the form
             View::render('login/form', $data);
         }
         //password is correct - set user data in session
         Session::set('userInfo', $user);
         //check if this is admin user, //redirect to the appropriate user
         if ($user['user_type'] == 'admin') {
             Redirect::to($user['user_type']);
         }
         //else, redirect to the home controller
         Redirect::to('home');
     } else {
         //compose the error information
         $data['error'] = 'User not found!';
         //reload the form with the error message
         View::render('login/form', $data);
     }
 }
 /**
  *This method checks for the logged in user.
  *@param null
  *@return void
  */
 public function __construct()
 {
     //check for logged in user
     if (!Session::get('userInfo')) {
         Redirect::to('login');
     }
     if (Session::get('userInfo')['user_type'] == 'admin') {
         Redirect::to('admin');
     }
 }
 /**
  * This methods upload a user's profile pic.
  * @param int $user_id The id of the user whose photo we upload
  * @return void
  */
 public function saveProfilePic($user_id)
 {
     $upload = Upload::doUpload('profile-pic');
     if ($upload->success) {
         $save_pic_path = UsersModel::where('id = ?', $user_id)->save(array('profile_pic' => substr($upload->upload_path_relative, 7)));
         $userInfo = UsersModel::where('id = ?', $user_id)->all();
         $userInfo = $userInfo->result_array();
         Session::set('userInfo', $userInfo[0]);
         if ($save_pic_path->updateSuccess()) {
             Redirect::to(array('admin'));
         }
     }
 }
 /**
  *This method loads the login form 
  *
  *@param null
  *@return void
  */
 public function getLogout()
 {
     LogModel::where('id = ?', Session::get('log_id'))->save(array('online' => false));
     UsersModel::where('id = ?', Session::get('userInfo')['id'])->save(array('online' => false));
     //destry all session data
     Session::flush();
     //load the login form
     View::render('login/form');
 }