public static function Init($params)
 {
     DebugManager::Log("Got a logout request!", '@');
     $account = AccountController::Create($params);
     SessionManager::Create($account);
     return new ResponseObject();
 }
Пример #2
0
 /**
  * Initialize Page Manager
  *
  * ## Overview
  *
  * @uses SatanBarbaraApp
  * @uses SessionManager
  * @uses ViewManager
  * @uses DebugManager
  * @uses RouteManager
  * @uses PageView
  *
  * @see RouteManager
  *
  * @param array An array of creds for SendGrid API.
  * @return true Always unless fatal error or exception is thrown.
  *
  * @version 2015-07-05.1
  * @since 0.5.1b
  * @author TronNet DevOps [Sean Murray] <*****@*****.**>
  */
 public static function Init($params)
 {
     DebugManager::Log("Initializing Page Manager", '@');
     DebugManager::Log($params);
     $appConfig = SatanBarbaraApp::GetConfig();
     /**
      * @todo have config in it's own 'config' position instead of array_merge
      */
     $data = array('app' => array_merge($appConfig[SATANBARBARA_CURRENT_ENVIRONMENT], array()), 'page' => $params);
     DebugManager::Log("checking if logged in...", null, 3);
     if (SessionManager::IsLoggedIn()) {
         $data['session'] = array('is_auth' => true, 'account' => SessionManager::GetAccount());
         DebugManager::Log("Got an account, checking for a saved program...", null, 3);
     }
     $Page = ucfirst($params['page']) . 'View';
     DebugManager::Log("Searching for view with class name: " . $Page);
     if ($Page::HasAccess(SessionManager::GetAccessLevel())) {
         $Page::Init($data);
         ViewManager::Render($Page);
     } else {
         DebugManager::Log("looks like this page requires auth but user isn't authenticated!");
         RouteManager::GoToPageURI('login');
     }
     return true;
 }
Пример #3
0
 public static function IsBetaAccount()
 {
     DebugManager::Log("Checking session account if beta account", '@');
     if (isset(static::$account['role'])) {
         return self::$_roles[static::$account['role']] == 'beta' || static::$account['id'] == '0';
     } else {
         return false;
     }
 }
 public static function Init($params)
 {
     DebugManager::Log("Got a logout request!", '@');
     $params['start'] = date('c', strtotime($params['start']));
     $params['end'] = date('c', strtotime($params['end']));
     $Account = SessionManager::GetAccount();
     try {
         $Event = EventController::Create($params);
     } catch (Exception $e) {
         return new ResponseObject("Error", 1);
     }
     if (isset($params['acts']) && is_array($params['acts'])) {
         foreach ($params['acts'] as $pos => $act) {
             try {
                 $Act = ActController::Create(array('title' => $act));
             } catch (Exception $e) {
                 $Acts = ActController::Search(array('title' => $act));
                 $Act = reset($Acts);
             }
             try {
                 if (isset($params['slots'][$pos])) {
                     $slot = date('c', strtotime($params['slots'][$pos]));
                 } else {
                     if (isset($slot)) {
                         $slot = date('c', strtotime('+1 hour', $slot));
                     } else {
                         $slot = date('c', strtotime('+30 minutes', $params['start']));
                     }
                 }
                 $Performance = PerformanceController::Create(array('act_id' => $Act['id'], 'event_id' => $Event['id'], 'position' => $pos, 'slot' => $slot));
             } catch (Exception $e) {
             }
         }
     }
     if (isset($params['venue'])) {
         try {
             $Venue = VenueController::Create(array('title' => $params['venue']));
         } catch (Exception $e) {
             $Venues = VenueController::Search(array('title' => $params['venue']));
             $Venue = reset($Venues);
         }
         try {
             $Hoster = HosterController::Create(array('venue_id' => $Venue['id'], 'event_id' => $Event['id']));
         } catch (Exception $e) {
         }
     }
     $Attendee = AttendeeController::Create(array('account_id' => $Account['id'], 'event_id' => $Event['id'], 'privilege_level' => 3, 'role' => 3, 'type' => 3));
     self::$defaultRedirect = 'event/' . $Event['id'];
     return new ResponseObject();
 }
Пример #5
0
 public static function Init($params)
 {
     DebugManager::Log("Got a logout request!", '@');
     /**
      * @todo ValidateLogin should provide a token, which is passed to
      *       SessionManager
      */
     if (AccountController::ValidateLogin($params)) {
         $account = AccountController::Search($params);
         SessionManager::Create(true, reset($account));
     } else {
         self::$defaultRedirect = 'login';
     }
     return new ResponseObject();
 }
 public static function Init($params)
 {
     DebugManager::Log("Got a logout request!", '@');
     $Account = SessionManager::GetAccount();
     try {
         $Location = LocationController::Create($params);
     } catch (Exception $e) {
         $Locations = LocationController::Search($params);
         $Location = reset($Locations);
     }
     try {
         $Venue = VenueController::Update(array('ids' => $params['venue_id'], 'location_id' => $Location['id']));
     } catch (Exception $e) {
     }
     self::$defaultRedirect = 'venue/' . $Venue['id'];
     return new ResponseObject();
 }
 public static function Init($requestParams)
 {
     $appConfig = SatanBarbaraApp::GetConfig();
     $data = $requestParams['params'];
     DebugManager::Log("Got a " . $requestParams['request']['action'] . " request!", '@');
     DebugManager::Log("Got some data");
     DebugManager::Log($data);
     $requestName = ucfirst($requestParams['request']['action']) . 'Request';
     DebugManager::Log("Searching for view with class name: " . $requestName);
     if ($requestName::HasAccess(SessionManager::GetAccessLevel())) {
         $response = $requestName::Init($data);
     } else {
         DebugManager::Log("looks like this page requires auth but user isn't authenticated!");
         RouteManager::GoToPageURI('login', array("message" => "That page requires authenticated access!"));
     }
     if (isset($data['_format']) && $data['_format'] == 'json') {
         self::AJAXResponse($response);
     } else {
         $format = isset($data['_format']) ? $data['_format'] : 'html';
         if (isset($data['_redirect'])) {
             $redirect = $data['_redirect'];
         } else {
             if (isset($requestName::$defaultRedirect)) {
                 $redirect = $requestName::$defaultRedirect;
             } else {
                 $redirect = 'home';
                 // $requestParams['uri']; <-- can't do this, it will cause circular loop because it's getting current URI and not last URI.
             }
         }
         $redirectURI = $redirect;
         $HTTPVars = array();
         if ($response->message != 'Success!') {
             if ($response->code) {
                 $HTTPVars['error'] = $response->message;
             } else {
                 $HTTPVars['success'] = $response->message;
             }
         }
         RouteManager::GoToPageURI($redirectURI, $HTTPVars);
     }
 }
Пример #8
0
 public static function Init($params)
 {
     DebugManager::Log("Got a logout request!", '@');
     SessionManager::Destroy();
     return new ResponseObject();
 }
Пример #9
0
 /**
  * Upload An Image
  * 
  * ## Overview
  *
  * @uses $_FILES
  *
  * @param string $file_field Name of file upload field in html form.
  * @param string $new_name Name of file upload.
  * @param bool $check_image Check if uploaded file is a valid image.
  * @param bool $random_name Generate random filename for uploaded file
  * @param bool $force Force file overwrites.
  *
  * @return array A set of error messages.
  *
  * @version 2015-07-05.1
  * @since 0.6.5b
  * @author TronNet DevOps [Sean Murray] <*****@*****.**>
  */
 public static function Upload($file_field = null, $new_name = false, $check_image = false, $random_name = false, $force = false)
 {
     DebugManager::Log("Uploading Image!", '@', 0);
     //Config Section
     //Set file upload path
     $path = self::GetPath();
     DebugManager::Log($path . $new_name, null, 0);
     //Set max file size in bytes
     $max_size = 1000000;
     //Set default file extension whitelist
     $whitelist_ext = array('jpg', 'png', 'gif');
     //Set default file type whitelist
     $whitelist_type = array('image/jpeg', 'image/png', 'image/gif');
     //The Validation
     // Create an array to hold any output
     $out = array('error' => null);
     if (!$file_field) {
         $out['error'][] = "Please specify a valid form field name";
     }
     if (!$path) {
         $out['error'][] = "Please specify a valid upload path";
     }
     if (count($out['error']) > 0) {
         return $out;
     }
     //Make sure that there is a file
     if (!empty($_FILES[$file_field]) && $_FILES[$file_field]['error'] == 0) {
         // Get filename
         $file_info = pathinfo($_FILES[$file_field]['name']);
         $name = $file_info['filename'];
         $ext = $file_info['extension'];
         //Check file has the right extension
         if (!in_array($ext, $whitelist_ext)) {
             $out['error'][] = "Invalid file Extension";
         }
         //Check that the file is of the right type
         if (!in_array($_FILES[$file_field]["type"], $whitelist_type)) {
             $out['error'][] = "Invalid file Type";
         }
         //Check that the file is not too big
         if ($_FILES[$file_field]["size"] > $max_size) {
             $out['error'][] = "File is too big";
         }
         //If $check image is set as true
         if ($check_image) {
             if (!getimagesize($_FILES[$file_field]['tmp_name'])) {
                 $out['error'][] = "Uploaded file is not a valid image";
             }
         }
         //Create full filename including path
         if ($new_name) {
             $name = $new_name;
         }
         if ($random_name) {
             // Generate random filename
             $tmp = str_replace(array('.', ' '), array('', ''), microtime());
             if (!$tmp || $tmp == '') {
                 $out['error'][] = "File must have a name";
             }
             $newname = $tmp . '.' . $ext;
         } else {
             $newname = $name . '.' . $ext;
         }
         //Check if file already exists on server
         if (file_exists($path . $newname)) {
             if ($force) {
                 unlink($path . $newname);
             } else {
                 $out['error'][] = "A file with this name already exists";
             }
         }
         if (count($out['error']) > 0) {
             //The file has not correctly validated
             return $out;
         }
         if (move_uploaded_file($_FILES[$file_field]['tmp_name'], $path . $newname)) {
             /**
              * @todo probably can do this with image in memory instead of writing then rewriting
              */
             DebugManager::Log("Uploaded Image!", null, 1);
             DebugManager::Log("Checking image is png...", null, 1);
             if ($ext != 'png') {
                 DebugManager::Log("Nope! Going to convert it!", null, 1);
                 $finalImage = new Imagick($path . $newname);
                 $finalImage->setImageFormat("png");
                 DebugManager::Log("Getting rid of old image: " . $path . $newname, null, 1);
                 unlink($path . $newname);
                 $newname = $name . '.png';
                 if ($finalImage->writeImage($path . $newname)) {
                     DebugManager::Log("Sweet, it should now be at: " . $path . $newname, null, 1);
                 } else {
                     DebugManager::Log("There were problems writing the image!", null, 1);
                 }
             }
             //Success
             $out['filepath'] = $path;
             $out['filename'] = $newname;
             return $out;
         } else {
             $out['error'][] = "Server Error!";
         }
     } else {
         $out['error'][] = "No file uploaded";
         return $out;
     }
 }
 public static function SendRedemptionTemplate($params)
 {
     DebugManager::Log("Sending a Redemption Email Template!", '@');
     DebugManager::Log($params);
     $interface = self::GetInterface();
     DebugManager::Log("Setting Sendgrid Email Headers");
     $email = new SendGrid\Email();
     $email->addTo($params['toEmail'])->setFromName($params['fromName'])->setFrom($params['fromEmail'])->setSubject($params['subject'])->setText("You used " . $params['points'] . " visits to redeem")->setHtml("You used " . $params['points'] . " visits to redeem")->addSubstitution(':title', array($params['title']))->addSubstitution(':id', array($params['id']))->addSubstitution(':advertiser_title', array($params['advertiser_title']))->addSubstitution(':advertiser_subtitle', array($params['advertiser_subtitle']))->addSubstitution(':description', array($params['description']))->addSubstitution(':advertiser_description', array($params['advertiser_description']))->addSubstitution(':subtitle', array($params['subtitle']))->addSubstitution(':name', array($params['toName']))->addSubstitution(':offer', array($params['title']))->addSubstitution(':instructions', array($params['instructions']))->addSubstitution(':points', array($params['points']))->setTemplateId(self::$_templates['rewardRedeemed']);
     DebugManager::Log($email);
     DebugManager::Log("Sending Sendgrid Email!!");
     $response = true;
     if (!self::$dry_run) {
         $response = $interface->send($email);
     }
     DebugManager::Log("Got a response!");
     DebugManager::Log($response);
     return $response;
 }
 /**
  * Get Application Config Data
  *
  * @return array An array of app settings.
  *
  * @version 2015-07-05.1
  * @since 0.5.1b
  * @author TronNet DevOps [Sean Murray] <*****@*****.**>
  */
 public static function GetConfig()
 {
     DebugManager::Log("Getting Application Configurations");
     DebugManager::Log(self::$appConfig);
     return self::$appConfig;
 }
Пример #12
0
 /**
  * Set Session Account
  *
  * ## Overview
  *
  * @uses SessionManager
  * @uses DebugManager
  *
  * @return array The current account associated with this session.
  *
  * @version 2015-07-05.1
  * @since 0.5.1b
  * @author TronNet DevOps [Sean Murray] <*****@*****.**>
  */
 public static function SetAccount($account, $persist = false)
 {
     DebugManager::Log("Setting Session Account", '@');
     DebugManager::Log("Current: ");
     DebugManager::Log(self::$account);
     if ($account) {
         $match = AccountController::Get(array('ids' => $account['id']));
         if (count($match)) {
             $account = $match;
         }
     } else {
         /**
          * Allowing to set 'null' to destroy session
          */
         // throw new Exception("No account was provided! Can't set session account!");
     }
     self::$account = $account;
     if ($persist) {
         $_SESSION['account'] = $account;
     }
     DebugManager::Log("New: ");
     DebugManager::Log(self::$account);
     return true;
 }
 /**
  * Send A Notification via SendGrid
  *
  * ## Overview
  *
  * @uses NotificationManager
  *
  * @see SatanBarbaraApp
  *
  * @param array The HTTP params for SendGrid API; such as message, to, etc.
  * @return string A response string for request from SendGrid API.
  *
  * @version 2015-07-05.1
  * @since 0.5.1b
  * @author TronNet DevOps [Sean Murray] <*****@*****.**>
  */
 public static function Send(array $params)
 {
     DebugManager::Log("Sending an email via SendGrid", '@');
     DebugManager::Log($params);
     return SendgridConnector::SendEmail($params);
 }
Пример #14
0
 * Metalsite Application PHP Configuration.
 *
 * Loads the application PHP config file. This file will determine the
 * current environment setup as well as define global constants and paths
 * that are utilized in the Metalsite Application Core.
 */
require_once SATANBARBARA_PATH . '/www/lib/config.php';
/**
 * Metalsite Application PHP Class Autoloader.
 *
 * Defines the paths to search for Application specific classes and loads
 * them if found. All classes in the Application Core are loaded by this 
 * mechanism.
 */
require_once SATANBARBARA_APP_PATH . '/lib/autoloader.php';
DebugManager::Log(SATANBARBARA_APP_PACKAGE_NAME . " Entry Point", '@');
/**
 * Metalsite API PHP Class Autoloader.
 *
 * Defines the paths to search for API specific classes and loads them
 * if found. All classes in the API are loaded by this mechanism.
 */
require_once SATANBARBARA_API_PATH . '/lib/autoloader.php';
/**
 * Initialize Metalsite Application.
 *
 * Utilizing the constants and autoloaders included above, initialize the
 * Metalsite Application. This is where all session, routing, data and 
 * requests are handled.
 */
SatanBarbaraApp::Init();