We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38314
    • 45 Posts
    Quote from: BobRay at Apr 23, 2015, 03:28 AM
    Are you sure you don't want to set the 'display_name' field instead (and set use_display_name to 1).

    I'll try this option BobRay. Hope I will success !
      • 38314
      • 45 Posts
      Back here without any clue. It looks like the Discuss user is created in discuss database when the (mod)User login.

      To reproduce :
      - deactivate Discuss pre and post hooks in login snippet, to be sure Discuss isn't fired
      - create a user in manager
      - login (in frontend) with that newly created user
      - look in modx_discuss_users table : the user is created !

      How can this line be created with just the login of the user ? Is there another posthook ?

      I've also modified in posthook.discusslogin.php dissetup.class.php and in discuss.class.php the line
      'username' => $user->get('username')
      to
      'username' => $user->get('id') //just for testing purpose !
      to check in database if it does anything. But didn't change anything. User is created in modx_discuss_users table with the right username !

      Can anyone explain the link between login in frontend and the creation of user in Discuss without the hooks ?
        • 46886
        • 1,154 Posts
        User isn't added to discuss user list prior to login? Login in front end would *only* utilize Discuss, as the manager login is different, isn't that right?

        I would doubt the *login* created the user in discuss table, rather I would expect, given your info, that all users are automatically added to discuss user table. For example, when i installed Discuss I had several users already created, and all of these users were automatically made members of Discuss.

        When you made the new user, the user lists synced, probably.
          • 38314
          • 45 Posts
          News here : I got it working, but I need some more tests to be sure.

          First of all, I was modifying only the files in the core/components/discuss folder, and I forget that there were snippets !
          So, here's what I did with postHook.DiscussLogin snippet :
          /** @var disUser $disUser */
          $disUser = $modx->getObject('disUser',$c);
          if (empty($disUser)) {
              /* ok, we need to create a parallel disUser obj since none exists */
              /** @var modUserProfile $profile */
              $profile = $user->getOne('Profile');
          
              $disUser = $modx->newObject('disUser');
              $disUser->fromArray(array(
                  'user' => $user->get('id'),
                  //'username' => $user->get('username'), //don't create username here, need fullname
                  
                  'password' => $user->get('password'),
                  'salt' => $user->get('salt'),
                  'confirmed' => true,
                  'confirmedon' => date('Y-m-d H:I:S'),
                  'createdon' => date('Y-m-d H:I:S'),
                  'source' => 'internal',
                  'status' => disUser::ACTIVE,
              ));
              if ($profile) {
                  $disUser->fromArray($profile->toArray());
                  $disUser->set('birthdate',strftime($discuss->dateFormat,$profile->get('dob')));
                  $disUser->set('gender',$profile->get('gender') == 2 ? 'f' : 'm');
                  $name = $profile->get('fullname');
                  $name = explode(' ',$name);
                  $disUser->fromArray(array(
                      'username' => $profile->get('fullname'), //create username with the fullname
                      'name_first' => $name[0],
                      'name_last' => isset($name[1]) ? $name[1] : '',
                  ));
              }
              $disUser->save();
          }


          Now, my users are created in Discuss once they log in (in frontend). I confirm they aren't created before. They don't appear in discuss's users database.

          Tryied to update profile with login snippet and the data where synced in discuss database.

          But now, the posthook.discusslogin.php dissetup.class.php and in discuss.class.php files (not snippets in manager ;-) have the same hack as shown upper. So, I need to "reset" back the files now to be sure. Because in discuss.class.php I changed 'source' => 'internal', with 'source' => 'discuss.class.php', and I saw it in 50% of my creation/login tests... Weird.

          I need more investigate to get it solved wink

          PS : strange behavior of my Modx these days, my error.log files isn't created anymore. If I create it manually, it remains blank. Lack of feedback sad
            • 46886
            • 1,154 Posts
            Wow very interesting! Have you gotten it working right?
              • 38314
              • 45 Posts
              Quote from: nuan88 at May 01, 2015, 09:12 AM
              Wow very interesting! Have you gotten it working right?

              Hi Nuan88,

              Yes, but I didn't have much time to investigate more further. I'll go in production in a few weeks so I guess it's all good. My Discuss's users are displayed just like I wanted.

              I still don't understand why I don't need to call Discuss Hooks in the login page (&preHooks=`preHook.DiscussLogin` &postHooks=`postHook.DiscussLogin` ) ? They're off and it works as this.
              As I said, still need more testing before using it in production, but it looks like we're on the right way !