user.inc.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. Class User {
  3. private $username = "";
  4. private $password = "";
  5. private $email = "";
  6. public function __construct($username) {
  7. if($username != NULL) {
  8. $this->username = $username;
  9. }
  10. }
  11. public function login($username, $password) {
  12. global $db;
  13. $this->username = $username;
  14. $this->password = $password;
  15. $user = $db->query("SELECT * FROM `users` WHERE `username` = '" . $username . "'");
  16. if($user->password === md5($password)) {
  17. $_SESSION['loggedIn'] = true;
  18. $_SESSION['username'] = $this->username;
  19. header("Location: http://vpn.mmnx.de/index.php?action=profile");
  20. } else {
  21. return false;
  22. }
  23. }
  24. public function logout() {
  25. $this->username = "";
  26. $this->password = "";
  27. $this->email = "";
  28. $_SESSION['loggedIn'] = false;
  29. unset($_SESSION['username']);
  30. session_destroy();
  31. header("Location: http://vpn.mmnx.de/index.php");
  32. }
  33. public function getClients() {
  34. global $db;
  35. //$clients = $db->query("SELECT * FROM `clients` WHERE `owned_by` = '" . $this->username . "'");
  36. //sizeof($clients);
  37. //return $clients->name;
  38. return $this->username;
  39. }
  40. }
  41. ?>