user.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Shibboleth;
  3. require_once dirname(__FILE__) . '/scaffold/user.class.php';
  4. /**
  5. * A Chamilo user. Model for the User table.
  6. *
  7. * Should be moved to the core. It only exists because it is not available through
  8. * the API.
  9. *
  10. * The _User objet is generated by the scaffolder. User inherits from it to allow
  11. * modifications without touching the generated file. Don't modify _User as
  12. * it may change in the future. Instead add modifications to this class.
  13. *
  14. * @license see /license.txt
  15. * @author Laurent Opprecht <laurent@opprecht.info>, Nicolas Rod for the University of Geneva
  16. */
  17. class User extends _User
  18. {
  19. }
  20. /**
  21. * Store for User objects. Interact with the database. Allows to save and retrieve
  22. * user objects.
  23. *
  24. * Should be moved to the core. It only exists because it is not available through
  25. * the API.
  26. *
  27. * The _UserStore objet is generated by the scaffolder. This class inherits from it to allow
  28. * modifications without touching the generated file. Don't modify the _ object as
  29. * it may change in the future. Instead add modifications to this class.
  30. *
  31. * @copyright (c) 2012 University of Geneva
  32. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  33. * @author Laurent Opprecht <laurent@opprecht.info>
  34. */
  35. class UserStore extends _UserStore
  36. {
  37. function __construct()
  38. {
  39. parent::__construct();
  40. ShibbolethUpgrade::update();
  41. }
  42. /**
  43. *
  44. * @param string $id
  45. * @return User
  46. */
  47. public function get_by_shibboleth_id($id)
  48. {
  49. return $this->get(array('shibb_unique_id' => $id));
  50. }
  51. public function shibboleth_id_exists($id)
  52. {
  53. return $this->exist(array('shibb_unique_id' => $id));
  54. }
  55. /**
  56. *
  57. * @param User $object
  58. */
  59. protected function before_save($object)
  60. {
  61. $object->username = $object->username ? $object->username : $this->generate_username();
  62. $object->password = $object->password ? $object->password : api_generate_password();
  63. $object->language = $object->language ? $object->language : $this->default_language();
  64. }
  65. function default_language()
  66. {
  67. return api_get_setting('platformLanguage');
  68. }
  69. function generate_username()
  70. {
  71. $result = uniqid('s', true);
  72. $result = str_replace('.', '', $result);
  73. while ($this->username_exists($result))
  74. {
  75. $result = uniqid('s', true);
  76. $result = str_replace('.', '', $result);
  77. }
  78. return $result;
  79. }
  80. }