user_mail_confirmation.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. $token = isset($_GET['token']) ? $_GET['token'] : '';
  5. if (!ctype_alnum($token)) {
  6. $token = '';
  7. }
  8. /** @var \Chamilo\UserBundle\Entity\User $user */
  9. $user = UserManager::getManager()->findUserByConfirmationToken($token);
  10. if ($user) {
  11. $user->setActive(1); // Set to 1 to activate the user
  12. $user->setConfirmationToken(null);
  13. Database::getManager()->persist($user);
  14. Database::getManager()->flush();
  15. // See where to redirect the user to, if any redirection has been set
  16. $url = api_get_path(WEB_PATH);
  17. if (!empty($_GET['c'])) {
  18. $courseCode = Security::remove_XSS($_GET['c']);
  19. }
  20. if (!empty($_GET['s'])) {
  21. $sessionId = (int) $_GET['s'];
  22. }
  23. // Get URL to a course, to a session, or an empty string
  24. $courseUrl = api_get_course_url($courseCode, $sessionId);
  25. if (!empty($courseUrl)) {
  26. $url = $courseUrl;
  27. }
  28. Event::addEvent(
  29. LOG_USER_CONFIRMED_EMAIL,
  30. LOG_USER_OBJECT,
  31. api_get_user_info($user->getId()),
  32. api_get_utc_datetime()
  33. );
  34. Display::addFlash(
  35. Display::return_message(get_lang('User confirmed. Now you can login the platform.'), 'success')
  36. );
  37. header('Location: '.$url);
  38. exit;
  39. } else {
  40. Display::addFlash(
  41. Display::return_message(get_lang('Link expired, please try again.'))
  42. );
  43. header('Location: '.api_get_path(WEB_PATH));
  44. exit;
  45. }