newUser.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. Template to automatically create a new user with information from anywhere.
  4. This file is loaded by main/inc/local.inc.php
  5. To use it please add this line to main/inc/conf/configuration.php :
  6. $extAuthSource["external_logininfo"]["newUser"] = $_configuration['root_sys']."main/auth/external_logininfo/newUser.php";
  7. You also have to implements the external_get_user_info function in functions.inc.php
  8. */
  9. use ChamiloSession as Session;
  10. require_once __DIR__.'/functions.inc.php';
  11. //MAIN CODE
  12. //$login and $password variables are setted in main/inc/local.inc.php
  13. if ($password != DEFAULT_PASSWORD) {
  14. $user = false;
  15. } else {
  16. $user = external_get_user_info($login, $password);
  17. }
  18. if ($user !== false && ($chamilo_uid = external_add_user($user)) !== false) {
  19. //log in the user
  20. $loginFailed = false;
  21. $_user['user_id'] = $chamilo_uid;
  22. $_user['uidReset'] = true;
  23. Session::write('_user', $_user);
  24. $uidReset = true;
  25. //Autosubscribe to courses
  26. if (!empty($user['courses'])) {
  27. $autoSubscribe = explode('|', $user['courses']);
  28. foreach ($autoSubscribe as $code) {
  29. if (CourseManager::course_exists($code)) {
  30. CourseManager::subscribeUser($_user['user_id'], $code);
  31. }
  32. }
  33. }
  34. // Is User Admin ?
  35. if ($user['admin']) {
  36. $is_platformAdmin = true;
  37. Database::query("INSERT INTO admin values ('$chamilo_uid')");
  38. }
  39. // Can user create course
  40. $is_allowedCreateCourse = (bool) (($user['status'] == COURSEMANAGER) or (api_get_setting('drhCourseManagerRights') and $user['status'] == SESSIONADMIN));
  41. Event::eventLogin($chamilo_uid);
  42. } else {
  43. $loginFailed = true;
  44. unset($_user['user_id']);
  45. $uidReset = false;
  46. }