public function __construct(User $user) { $this->setId($user->getId()); $this->setUsername($user->getUsername()); $this->setEmail($user->getEmail()); $this->setApiKey($user->getApiKey()); }
public function load(ObjectManager $manager) { $user = new User(); $user->setUsername('admin'); $user->setEmail('*****@*****.**'); $user->setApiKey(''); $encoder = $this->container->get('security.password_encoder'); $password = $encoder->encodePassword($user, 'faster'); $user->setPassword($password); $manager->persist($user); $manager->flush(); $roleAdmin = new Role(); $roleAdmin->setRole('ROLE_ADMIN'); $roleAdmin->addUser($user); $manager->persist($roleAdmin); $roleUser = new Role(); $roleUser->setRole('ROLE_USER'); $roleUser->addUser($user); $manager->persist($roleUser); $user->addRole($roleAdmin); $user->addRole($roleUser); $manager->flush(); }
private function generateApiKey(User $user) { $apiKey = $user->getId(); $apiKey .= uniqid(md5($user->getUsername() . time())); return $apiKey; }