You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.1 KiB

15 years ago
15 years ago
15 years ago
13 years ago
13 years ago
13 years ago
13 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. <?Php
  2. /**
  3. * \class User
  4. * \brief Handles the user's login and user.
  5. *
  6. */
  7. class User {
  8. private $xmppSession;
  9. public $username = '';
  10. private $password = '';
  11. private $config = array();
  12. public $userdir;
  13. public $useruri;
  14. public $sizelimit;
  15. /**
  16. * Class constructor. Reloads the user's session or attempts to authenticate
  17. * the user.
  18. * Note that the constructor is private. This class is a singleton.
  19. */
  20. function __construct()
  21. {
  22. if($this->isLogged()) {
  23. $session = \Sessionx::start();
  24. $this->username = $session->user.'@'.$session->host;
  25. if($session->config)
  26. $this->config = $session->config;
  27. $this->sizelimit = (int)\system\Conf::getServerConfElement('sizeLimit');
  28. $this->userdir = DOCUMENT_ROOT.'/users/'.$this->username.'/';
  29. $this->useruri = BASE_URI.'users/'.$this->username.'/';
  30. }
  31. }
  32. /**
  33. * Get the current size in bytes of the user directory
  34. */
  35. function dirSize()
  36. {
  37. $sum = 0;
  38. foreach($this->getDir() as $s)
  39. $sum = $sum + filesize($s['dir']);
  40. return $sum;
  41. }
  42. /**
  43. * Get a list of the files in the user dir with uri, dir and thumbs
  44. */
  45. function getDir()
  46. {
  47. $dir = array();
  48. if(is_dir($this->userdir))
  49. foreach(scandir($this->userdir) as $s) {
  50. if(
  51. $s != '.' &&
  52. $s != '..' &&
  53. substr($s, 0, 6) != 'thumb_' &&
  54. substr($s, 0, 7) != 'medium_' &&
  55. $s != 'index.html') {
  56. $file = array(
  57. 'uri' => $this->useruri.$s,
  58. 'dir' => $this->userdir.$s,
  59. 'thumb' => $this->useruri.'thumb_'.$s,
  60. 'medium' => $this->useruri.'medium_'.$s);
  61. $dir[$s] = $file;
  62. }
  63. }
  64. return $dir;
  65. }
  66. /**
  67. * Checks if the user has an open session.
  68. */
  69. function isLogged()
  70. {
  71. // User is not logged in if both the session vars and the members are unset.
  72. $session = \Sessionx::start();
  73. if($session->active)
  74. return $session->active;
  75. else
  76. return false;
  77. }
  78. function desauth()
  79. {
  80. $pd = new modl\PresenceDAO();
  81. $pd->clearPresence($this->username);
  82. $s = \Sessionx::start();
  83. $s->destroy();
  84. $sess = Session::start(APP_NAME);
  85. Session::dispose(APP_NAME);
  86. }
  87. function getLogin()
  88. {
  89. return $this->username;
  90. }
  91. function getPass()
  92. {
  93. return $this->password;
  94. }
  95. function setConfig(array $config)
  96. {
  97. $session = \Sessionx::start();
  98. $session->config = $config;
  99. }
  100. function getConfig($key = false)
  101. {
  102. if($key == false)
  103. return $this->config;
  104. if(isset($this->config[$key]))
  105. return $this->config[$key];
  106. }
  107. }