session.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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) {
  10. global $settings;
  11. $return['config'] = $settings;
  12. unset($return['config']['password']);
  13. // No login
  14. if ($settings['username']===''&&$settings['password']==='') $return['config']['login'] = false;
  15. else $return['config']['login'] = true;
  16. if ($mode==='admin') {
  17. $return['loggedIn'] = true;
  18. } else {
  19. unset($return['config']['username']);
  20. unset($return['config']['thumbQuality']);
  21. unset($return['config']['sorting']);
  22. unset($return['config']['login']);
  23. $return['loggedIn'] = false;
  24. }
  25. return $return;
  26. }
  27. function login($username, $password) {
  28. global $database, $settings;
  29. // Check login
  30. if ($username===$settings['username']&&$password===$settings['password']) {
  31. $_SESSION['login'] = true;
  32. return true;
  33. }
  34. // No login
  35. if ($settings['username']===''&&$settings['password']==='') {
  36. $_SESSION['login'] = true;
  37. return true;
  38. }
  39. return false;
  40. }
  41. function logout() {
  42. session_destroy();
  43. return true;
  44. }
  45. ?>