session.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @name Session Module
  4. * @author Philipp Maurer
  5. * @author Tobias Reich
  6. * @copyright 2014 by Philipp Maurer, Tobias Reich
  7. */
  8. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  9. function init($mode, $version) {
  10. global $settings, $configVersion;
  11. // Update
  12. if ($configVersion!==$version)
  13. if (!update($version)) exit('Error: Updating the database failed!');
  14. $return['config'] = $settings;
  15. unset($return['config']['password']);
  16. // No login
  17. if ($settings['username']===''&&$settings['password']==='') $return['config']['login'] = false;
  18. else $return['config']['login'] = true;
  19. if ($mode==='admin') {
  20. $return['loggedIn'] = true;
  21. } else {
  22. unset($return['config']['username']);
  23. unset($return['config']['thumbQuality']);
  24. unset($return['config']['sorting']);
  25. unset($return['config']['dropboxKey']);
  26. unset($return['config']['login']);
  27. $return['loggedIn'] = false;
  28. }
  29. return $return;
  30. }
  31. function login($username, $password) {
  32. global $database, $settings;
  33. // Check login
  34. if ($username===$settings['username']&&$password===$settings['password']) {
  35. $_SESSION['login'] = true;
  36. return true;
  37. }
  38. // No login
  39. if ($settings['username']===''&&$settings['password']==='') {
  40. $_SESSION['login'] = true;
  41. return true;
  42. }
  43. return false;
  44. }
  45. function logout() {
  46. session_destroy();
  47. return true;
  48. }
  49. ?>