Giter Site home page Giter Site logo

Comments (12)

visto9259 avatar visto9259 commented on June 11, 2024

@vrkansagara, this looks like you user table in your database does not have a user_id column.

What is the schema for the user table in your database?

The /data folder provides example schemas to build the user table.

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

@visto9259 I am trying to use LmcUser + LmcRbacMvc where I am getting this error. I have already configured using this way 'user_entity_class' => \User\Entity\User::class,

<?php

namespace User\Entity;

use LmcUser\Entity\User as LmcUserEntity;
use LmcRbacMvc\Identity\IdentityInterface;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use LmcUser\Entity\UserInterface;
use Rbac\Role\RoleInterface;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User extends LmcUserEntity implements IdentityInterface
{

  /**
   * @var int|null
   *
   * @ORM\Id
   * @ORM\Column(name="user_id", type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $id;

  /**
   * @var string
   * @ORM\Column(name="username",type="string", length=128, unique=true, nullable=true)
   */
  protected $username;

  /**
   * @var string
   * @ORM\Column(name="email",type="string", length=128, unique=true, nullable=false)
   */
  protected $email;

  /**
   * @var string
   * @ORM\Column(name="display_name",type="string", length=128, unique=false, nullable=true)
   */
  protected $displayName;

  /**
   * @var string
   * @ORM\Column(name="password",type="string", length=128, unique=false, nullable=false)
   */
  protected $password;

  /**
   * @var int
   * @ORM\Column(name="state",type="integer", unique=false, nullable=true)
   */
  protected $state;

  /**
   * Get id.
   *
   * @return int
   */
  public function getId()
  {
    return $this->id;
  }

  /**
   * Set id.
   *
   * @param  int $id
   * @return UserInterface
   */
  public function setId($id)
  {
    $this->id = (int) $id;
    return $this;
  }

  /**
   * Get username.
   *
   * @return string
   */
  public function getUsername()
  {
    return $this->username;
  }

  /**
   * Set username.
   *
   * @param  string $username
   * @return UserInterface
   */
  public function setUsername($username)
  {
    $this->username = $username;
    return $this;
  }

  /**
   * Get email.
   *
   * @return string
   */
  public function getEmail()
  {
    return $this->email;
  }

  /**
   * Set email.
   *
   * @param  string $email
   * @return UserInterface
   */
  public function setEmail($email)
  {
    $this->email = $email;
    return $this;
  }

  /**
   * Get displayName.
   *
   * @return string
   */
  public function getDisplayName()
  {
    return $this->displayName;
  }

  /**
   * Set displayName.
   *
   * @param  string $displayName
   * @return UserInterface
   */
  public function setDisplayName($displayName)
  {
    $this->displayName = $displayName;
    return $this;
  }

  /**
   * Get password.
   *
   * @return string
   */
  public function getPassword()
  {
    return $this->password;
  }

  /**
   * Set password.
   *
   * @param  string $password
   * @return UserInterface
   */
  public function setPassword($password)
  {
    $this->password = $password;
    return $this;
  }

  /**
   * Get state.
   *
   * @return int
   */
  public function getState()
  {
    return $this->state;
  }

  /**
   * Set state.
   *
   * @param  int $state
   * @return UserInterface
   */
  public function setState($state)
  {
    $this->state = $state;
    return $this;
  }

  /**
   * @var Collection
   * @ORM\ManyToMany(targetEntity="\User\Entity\FlatRole")
   * @ORM\JoinTable(name="user_flatrole",
   *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")},
   *      inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
   * )
   */
  private $roles;

  public function __construct()
  {
    $this->roles = new ArrayCollection();
  }

  /**
   * {@inheritDoc}
   */
  public function getRoles()
  {
    return $this->roles->toArray();
  }

  /**
   * Set the list of roles
   * @param Collection $roles
   */
  public function setRoles(Collection $roles)
  {
    $this->roles->clear();
    foreach ($roles as $role) {
      $this->roles[] = $role;
    }
  }

  /**
   * Add one role to roles list
   * @param \Rbac\Role\RoleInterface $role
   */
  public function addRole(RoleInterface $role)
  {
    $this->roles[] = $role;
  }

}

User table structure look like this.

image

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

I also running with the another issue when I switched to the above User.php entity as bellow
image

from lmcuser.

visto9259 avatar visto9259 commented on June 11, 2024

For the roles issue, do you have a roles column in your table?
I don't see it the screen capture of the table structure that you shared above.

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

That roles come from the relation , I think @visto9259

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

Problems looks like the guest role is not assigned while user creation is fired.
image

This role should be assigned as default while user is being created using LmcRbacMvc

I do also suspect that user_id is not mapped while user is being registered.

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

image

This patch should be needed here

    public function hydrate(array $data, $object)
    {
        if (!$object instanceof UserEntityInterface) {
            throw new Exception\InvalidArgumentException('$object must be an instance of LmcUser\Entity\UserInterface');
        }

        if (isset($data['id'])) {
          $data = $this->mapField('user_id', 'id', $data);
        }

        return $this->hydrator->hydrate($data, $object);
    }

looks like there is issue here https://github.com/LM-Commons/LmcUser/blob/master/src/Mapper/UserHydrator.php#L64

from lmcuser.

visto9259 avatar visto9259 commented on June 11, 2024

Hi @vrkansagara ,
I am still trying to reproduce the issues in my own dev setup.
Have you found a resolution or do you have more info to provide?
Are you using ORM for the user entities? Off the shelf, LmcUser does not use ORM for the user table. There is another module to use ORM for user https://github.com/LM-Commons/LmcUserDoctrineORM.
LmcUser when fetching users does not use ORM (I think) and since the roles come from the relation defined in your entity, roles do not get pulled into the user entity.

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

yes, @visto9259 , I do confirm that I was not using LmcUserDoctrineORM. so facing this issue.

I also facing much difficult to setup the FlatRole using LmcUserMVC so can you consider to as proposal for the demo repository where it can show the working model for following packages.

  • LmcUser
  • LmcAdmin
  • LmcRbacMvc
  • LmcUserDoctrineORM

this combination is useful to show the basic Dashboard application so any one can easily start using this combination package and start creating application.

from lmcuser.

visto9259 avatar visto9259 commented on June 11, 2024

That would be a good idea but we lack the bandwidth to do so. This is all based on volunteer work.
I wrote a tutorial on the basics of how to use LmcUser: https://www.vistomedia.com/laminas-user-authentication-using-lmcuser/
Take a look. I intended to write a tutorial on LmcRbacMvc as a follow up but did not have the time to get to it.

There are thousands of installs of LmcUser and LmcRbacMvc without issues. There could be bugs in the code but I suspect that there is something not set up properly in your application.

Can you share details on how you define the database adapter in your config? LmcUser uses the class \Laminas\Db\Adapter\Adapter::class as the database adapter. You need a database config somewhere in your config files which I assume you have.
Please share your lmc_user and lmc_rbac configs.

from lmcuser.

vrkansagara avatar vrkansagara commented on June 11, 2024

@visto9259 , I figured out the issue as i said here. #49 (comment)

So this issue can be closed.

I have couple of improvement , I will make it PR

from lmcuser.

visto9259 avatar visto9259 commented on June 11, 2024

This is just the explanation for the warning and that I knew that the issue was where you pointed out.
You can submit a PR for it.
What about the other issues that you reported?

from lmcuser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.