Ejemplo n.º 1
0
 /**
  * Gets the records for a specific page and limit
  * @param mixed/int $limit Set to all if you want to retrieve all records.
  * @param int $page The page you want to retrieve
  * @return \stdClass The records from the query
  */
 public function get_records($limit = 25, $page = 1)
 {
     //init
     $this->limit = $limit;
     $this->pageNumber = $page;
     //Set the limit
     $query = $limit == 'all' ? $this->sqlString : $this->sqlString . ' limit ' . ($this->pageNumber - 1) * $this->limit . ', ' . $this->limit;
     $records = DatabaseUtil::get($this->mysqli, $query, $this->passValues);
     //Make an object of the result so that it is more organized
     $result = new \stdClass();
     $result->records = $records;
     $result->page = $this->pageNumber;
     $result->limit = $this->limit;
     $result->total = $this->totalRecords;
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Logs a user in
  * @param string $userEmail Email address the user is trying to login as
  * @param string $password The password the user is trying to login as
  * @return bool|string Returns false if the login is successful or returns an error string if unsuccessful
  */
 public static function login($userEmail, $password)
 {
     //Retrieve information from the users table
     if (!($conn = DatabaseUtil::db_connect(DatabaseUtil::DATABASE_USER))) {
         return 'Database Error contact administration.';
     }
     if ($result = DatabaseUtil::get($conn, 'SELECT * FROM users WHERE emailAddress=? LIMIT 1', [$userEmail])) {
         //check the password
         $result = array_shift($result);
         if (self::hash($password, $result->salt) == $result->password) {
             SessionUtil::session_set('loggedIn', self::user_token($result->salt));
             SessionUtil::session_set('user', serialize($result));
         } else {
             return 'Email or Password are incorrect.';
         }
     } else {
         return 'Email or Password are incorrect.';
     }
 }
Ejemplo n.º 3
0
 private function add_user()
 {
     $user = new \stdClass();
     $user->userName = param('txtName');
     $user->emailAddress = param('txtEmail');
     $user->company = param('txtCompany');
     $user->salt = AuthenticationUtil::salt();
     $user->password = AuthenticationUtil::hash(param('txtPassword'), $user->salt);
     $user->privs = array_sum(param('cbxPrivs'));
     //Make connection
     if (!($dbConnection = DatabaseUtil::db_connect(DatabaseUtil::DATABASE_USER))) {
         return 'Error with database connection. Contact DB admin. ';
     }
     if (!($error = DatabaseUtil::insert($dbConnection, 'users', $user))) {
         return 'User Added';
     } else {
         return $error;
     }
 }