user.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Shibboleth;
  3. require_once __DIR__.'/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. /**
  52. * @param string $id
  53. */
  54. public function shibboleth_id_exists($id)
  55. {
  56. return $this->exist(array('shibb_unique_id' => $id));
  57. }
  58. /**
  59. *
  60. * @param User $object
  61. */
  62. protected function before_save($object)
  63. {
  64. $object->username = $object->username ? $object->username : $this->generate_username();
  65. $object->password = $object->password ? $object->password : api_generate_password();
  66. $object->language = $object->language ? $object->language : $this->default_language();
  67. }
  68. function default_language()
  69. {
  70. return api_get_setting('platformLanguage');
  71. }
  72. function generate_username()
  73. {
  74. $result = uniqid('s', true);
  75. $result = str_replace('.', '', $result);
  76. while ($this->username_exists($result))
  77. {
  78. $result = uniqid('s', true);
  79. $result = str_replace('.', '', $result);
  80. }
  81. return $result;
  82. }
  83. }