Exemple #1
0
 /**
  * Function used to draw a menu
  *
  * @param string $name The identifier of the menu
  */
 static function Draw($name)
 {
     $menu = Cache::Read('menus/' . $name);
     if (!$menu) {
         if (Database::Exists(LWC::QUERY_MENU, [':name', $name])) {
             $menu = Database::Data();
             if (Database::Fetch(LWC::QUERY_MENU_ITEMS, [':menu', $menu['id'], PDO::PARAM_INT])) {
                 foreach (Database::Data() as $item) {
                     if (Database::Fetch(LWC::QUERY_MENU_SUBITEMS, [[':parent', $item['id'], PDO::PARAM_INT], [':menu', $menu['id'], PDO::PARAM_INT]])) {
                         foreach (Database::Data() as $subitem) {
                             $item['subitems'][] = $subitem;
                         }
                     }
                     $menu['items'][] = $item;
                 }
             }
             Cache::Write('menus/' . $name, $menu);
         } else {
             return;
         }
     }
     if (session('rank') >= $menu['minrank'] && session('rank') <= $menu['maxrank']) {
         Template::Load('menu/navbar', $menu);
     }
 }
 /**
  * Function for reading a session
  *
  * Will use the given id to load a session from the database.
  *
  * @param string $id A PHP session id to search for in the database
  *
  * @return string Will return an empty string if session does not exist - session data otherwise
  */
 public function read($id)
 {
     if (Database::Exists(LWC::QUERY_SESSION_READ, [':id', $id, PDO::PARAM_STR])) {
         $data = base64_decode(Database::Get("data"));
         // Decode the session data from the database
         $this->checksum = md5($data);
         // Calculate a checksum of the data
         return $data;
         // Return the data
     } else {
         return '';
     }
     // Return an empty string - PHP will know the session does not exist.
 }
Exemple #3
0
 /**
  * This constructor will prepare this form
  *
  * Will read the requested form from the databse or from a cached file.
  *
  * @param string $name The name of the form to read
  * @param array $data This data will be used to fill out the form (specify 'field_name' => 'value')
  */
 function __construct($name = null, $data = array())
 {
     if (!is_null($name)) {
         $form = Cache::Read('forms/' . $name);
         // Get form from cache...
         if (!$form) {
             if (Database::Exists(LWC::QUERY_FORM, [':name', $name])) {
                 $form = Database::Data();
                 // Get the form
                 $fields = array();
                 if (Database::Fetch(LWC::QUERY_FORM_ITEMS, [':id', $form['id'], PDO::PARAM_INT])) {
                     foreach (Database::Data() as $row) {
                         if (isset($row['properties'])) {
                             $properties = explode('&', $row['properties']);
                             // ...and split them like HTTP parameters
                             foreach ($properties as $property) {
                                 $pair = explode('=', $property);
                                 // Explode each of the properties by =
                                 if (sizeof($pair) == 1) {
                                     $row[$pair[0]] = true;
                                 } else {
                                     if (sizeof($pair) == 2) {
                                         $row[$pair[0]] = $pair[1];
                                     }
                                 }
                                 // Otherwise we will set the proper value
                             }
                         }
                         unset($row['properties']);
                         // We unset the properties field after it has been parsed
                         $fields[$row['identifier']] = $row;
                         // The row is now prepared and can be used as field
                     }
                 } else {
                     Lightwork::Log('Form has no fields: ' . $form['identifier'], Lightwork::LOG_WARN);
                 }
                 $form['fields'] = $fields;
                 // Assign this fields to this form
             } else {
                 Lightwork::Log('Form does not exist: ' . $form['identifier'], Lightwork::LOG_WARN);
             }
         }
         Cache::Write('forms/' . $name, $form);
         // Write this form to the cache
         $this->form = $form;
         // Set the local form
         $this->data = $data;
         // Set the local form data from parameters
     }
 }
Exemple #4
0
 /**
  * Function to log a user in
  *
  * Will check email/username and password against database.
  *
  * @param string $identifier The username or email address for an account
  * @param string $pasword The password of the account
  *
  * @return bool Will return true if the user was logged in successfully, false otherwise
  */
 static function Login($identifier, $password)
 {
     if (Database::Exists('SELECT password, id, username, rank FROM lw_users WHERE (email = :email OR username = :username) AND enabled = 1', [[':email', $identifier], [':username', $identifier]])) {
         if (password_verify($password, Database::Get('password'))) {
             session('loggedin', true);
             session('userid', Database::Get('id'));
             session('username', Database::Get('username'));
             session('rank', Database::Get('rank'));
             Lightwork::Log('User logged in.', Lightwork::LOG_DEBUG);
             return true;
         }
     }
     Lightwork::Log('User failed to provide proper credentials.', Lightwork::LOG_DEBUG);
     return false;
 }