Announcement

Collapse
No announcement yet.

Duplicated Users

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duplicated Users

    Hello,

    I have a TFA working with ESPOCRM, but some of the users are being created twice.
    This is making the users list displaying some users twice as well.

    How can I avoid the system do not create the user again (with the same username, name, surname, email) ?

    Is there any new check to create into the user entity?

    Thanks.

  • #2
    Hi,

    How do you create users? Do you use POST /api/v1/User request?

    Comment


    • #3
      Thank you for your answer.


      In Espo/Core/Utils/Authentication folder, we created a new file to make our authentication.

      Using this class to make the authentication, we are doing:



      Code:
      namespace Espo\Core\Utils\Authentication;
      use Espo\Core\Exceptions\Error;
      use Espo\Core\Utils\Config;
      use Espo\Core\ORM\EntityManager;
      use Espo\Core\Utils\Auth;
      class NewLogin extends Base
      {
          /**
           * NewLogin login
           *
           * @param  string $username
           * @param  string $password
           * @param  \Espo\Entities\AuthToken $authToken
           *
           * @return \Espo\Entities\User | null
           */
          public function login($username = null, $password = null, \Espo\Entities\AuthToken $authToken = null)
          {
              foreach ($_SERVER as $name => $value) {
                  if (substr($name, 0, 5) == 'HTTP_') {
                      $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
                  }
              }
      
      (...)
      
      if (!isset($user)) {
                  $user = $this->getEntityManager()->getRepository('User')->findOne([
                      'whereClause' => [
                          'email' => trim($_SERVER['HTTP_USER_EMAIL']),
                      ],
                  ]);
      
                  if (!isset($user)) {
                      $user = $this->createUser([
                          'userName' => $username,
                          'emailAddress' => $_SERVER['HTTP_USER_EMAIL'] ?: "",
                          'firstName' => $_SERVER['HTTP_USER_GIVEN_NAME'] ?: "",
                          'lastName' => $_SERVER['HTTP_USER_FAMILY_NAME'] ?: "",
                      ]);
      
                      $this->getEntityManager()->saveEntity($user);
                  }
      }

      But, for some reason, the user sometimes is created twice.

      Comment

      Working...
      X