session.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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']['login']);
  26. $return['loggedIn'] = false;
  27. }
  28. return $return;
  29. }
  30. function login($username, $password) {
  31. global $database, $settings;
  32. // Check login
  33. if ($username===$settings['username']&&$password===$settings['password']) {
  34. $_SESSION['login'] = true;
  35. return true;
  36. }
  37. // No login
  38. if ($settings['username']===''&&$settings['password']==='') {
  39. $_SESSION['login'] = true;
  40. return true;
  41. }
  42. return false;
  43. }
  44. function logout() {
  45. session_destroy();
  46. return true;
  47. }
  48. ?>