Ver Fonte

Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

jmontoyaa há 8 anos atrás
pai
commit
8998f9b58f

+ 11 - 6
main/auth/external_login/newUser.ldap.php

@@ -44,26 +44,31 @@ require_once dirname(__FILE__) . '/functions.inc.php';
 
 $ldap_user = extldap_authenticate($login, $password);
 if ($ldap_user !== false) {
+    $em = Database::getManager();
     $chamilo_user = extldap_get_chamilo_user($ldap_user);
     //username is not on the ldap, we have to use $login variable
     $chamilo_user['username'] = $login;
     $chamilo_uid = external_add_user($chamilo_user);
-    if ($chamilo_uid !== false) {
+
+    $chamiloUser = $em->find('ChamiloUserBundle:User', $chamilo_uid);
+
+    if ($chamiloUser) {
         $loginFailed = false;
-        $_user['user_id'] = $chamilo_uid;
-        $_user['status'] = (isset($chamilo_user['status']) ? $chamilo_user['status'] : 5);
+        $_user['user_id'] = $chamiloUser->getId();
+        $_user['status'] = $chamiloUser->getStatus();
         $_user['uidReset'] = true;
         Session::write('_user', $_user);
         $uidReset = true;
         // Is user admin?
         if ($chamilo_user['admin'] === true) {
             $is_platformAdmin = true;
-            Database::query("INSERT INTO admin values ('$chamilo_uid')");
+            Database::query("INSERT INTO admin values ('{$chamiloUser->getId()}')");
         }
-        Event::event_login($chamilo_uid);
+        Event::event_login($chamiloUser->getId());
+
+        MessageManager::sendNotificationByRegisteredUser($chamiloUser);
     }
 } else {
     $loginFailed = true;
     $uidReset = false;
-    unset($_user['user_id']);
 }

+ 34 - 0
main/inc/lib/message.lib.php

@@ -1834,4 +1834,38 @@ class MessageManager
 
         return $form;
     }
+
+    /**
+     * Send a notification to all amdinistrators when a new user is registered
+     * @param \Chamilo\UserBundle\Entity\User $user
+     */
+    public static function sendNotificationByRegisteredUser(\Chamilo\UserBundle\Entity\User $user)
+    {
+        $tplMailBody = new Template(null, false, false, false, false, false, false);
+        $tplMailBody->assign('user', $user);
+        $tplMailBody->assign('is_western_name_order', api_is_western_name_order());
+        $tplMailBody->assign('manageUrl', api_get_path(WEB_CODE_PATH) . 'admin/user_edit.php?user_id=' . $user->getId());
+
+        $layoutContent = $tplMailBody->get_template('mail/new_user_mail_to_admin.tpl');
+
+        $emailsubject = '[' . get_lang('UserRegistered') . '] ' . $user->getUsername();
+        $emailbody = $tplMailBody->fetch($layoutContent);
+
+        $admins = UserManager::get_all_administrators();
+
+        foreach ($admins as $admin_info) {
+            MessageManager::send_message(
+                $admin_info['user_id'],
+                $emailsubject,
+                $emailbody,
+                [],
+                [],
+                null,
+                null,
+                null,
+                null,
+                $user->getId()
+            );
+        }
+    }
 }

+ 2 - 2
main/inc/local.inc.php

@@ -555,11 +555,11 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) {
 
             if (isset($extAuthSource) && is_array($extAuthSource)) {
                 foreach ($extAuthSource as $thisAuthSource) {
-                    if (!empty($thisAuthSource['newUser']) && file_exists($thisAuthSource['newUser'])) {
+                    if (isset($thisAuthSource['newUser']) && file_exists($thisAuthSource['newUser'])) {
                         include_once($thisAuthSource['newUser']);
                     } else {
                         error_log(
-                            'Chamilo Authentication file '. $thisAuthSource['newUser'].
+                            'Chamilo Authentication external file' .
                             ' could not be found - this might prevent your system from using'.
                             ' the authentication process in the user creation process',
                             0

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
main/lang/english/trad4all.inc.php


Diff do ficheiro suprimidas por serem muito extensas
+ 1 - 1
main/lang/spanish/trad4all.inc.php


+ 13 - 0
main/template/default/mail/new_user_mail_to_admin.tpl

@@ -0,0 +1,13 @@
+<h4>{{ 'UserRegistered'|get_lang }}</h4>
+<ul>
+    {% if is_western_name_order %}
+        <li>{{ 'FirstName'|get_lang }}: {{ user.getFirstName() }}</li>
+        <li>{{ 'LastName' }}: {{ user.getLastName() }}</li>
+    {% else  %}
+        <li>{{ 'LastName' }}: {{ user.getLastName() }}</li>
+        <li>{{ 'FirstName' }}: {{ user.getFirstName() }}</li>
+    {% endif %}
+    <li>{{ 'Email'|get_lang }}: {{ user.getEmail() }}</li>
+    <li>{{ 'Status'|get_lang }}: {{ user.getStatus() }}</li>
+</ul>
+<p>{{ 'ManageUser'|get_lang }}: <a href="{{ manageUrl }}">{{ manageUrl }}</a></p>

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff