本文整理汇总了PHP中AppBundle\Entity\User::setApiKey方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setApiKey方法的具体用法?PHP User::setApiKey怎么用?PHP User::setApiKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\User
的用法示例。
在下文中一共展示了User::setApiKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load(ObjectManager $manager)
{
$user = new User();
$user->setUsername('admin');
$user->setUserFirstName('stamat');
$user->setUserLastName('stamativan');
$user->setEmail('admin@test.com');
$user->setApiKey(null);
$encoder = $this->container->get('security.password_encoder');
$password = $encoder->encodePassword($user, 'faster');
$user->setPassword($password);
$manager->persist($user);
$manager->flush();
$user2 = new User();
$user2->setUsername('suxorr');
$user2->setUserFirstName('mario');
$user2->setUserLastName('hristev');
$user2->setEmail('hristevmario@gmail.com');
$user2->setApiKey(null);
$encoder2 = $this->container->get('security.password_encoder');
$password2 = $encoder2->encodePassword($user2, 'azsammario123');
$user2->setPassword($password2);
$manager->persist($user2);
$manager->flush();
$user3 = new User();
$user3->setUsername('teacher');
$user3->setUserFirstName('Пешо');
$user3->setUserLastName('Петкоф');
$user3->setEmail('teacher@test.com');
$user3->setApiKey(null);
$encoder3 = $this->container->get('security.password_encoder');
$password3 = $encoder3->encodePassword($user3, 'slower');
$user3->setPassword($password3);
$manager->persist($user3);
$manager->flush();
$roleAdmin = new Role();
$roleAdmin->setRole('ROLE_ADMIN');
$roleAdmin->addUser($user);
$roleAdmin->addUser($user2);
$roleAdmin->addUser($user3);
$manager->persist($roleAdmin);
$roleTeacher = new Role();
$roleTeacher->setRole('ROLE_TEACHER');
$roleTeacher->addUser($user);
$roleTeacher->addUser($user2);
$roleTeacher->addUser($user3);
$manager->persist($roleTeacher);
$roleUser = new Role();
$roleUser->setRole('ROLE_USER');
$roleUser->addUser($user);
$roleUser->addUser($user2);
$roleUser->addUser($user3);
$manager->persist($roleUser);
$user->addRole($roleAdmin);
$user->addRole($roleTeacher);
$user->addRole($roleUser);
$user2->addRole($roleAdmin);
$user2->addRole($roleTeacher);
$user2->addRole($roleUser);
$user3->addRole($roleTeacher);
$user3->addRole($roleUser);
$manager->flush();
}
示例2: setApiKey
/**
* {@inheritDoc}
*/
public function setApiKey($apiKey)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setApiKey', array($apiKey));
return parent::setApiKey($apiKey);
}
示例3: load
public function load(ObjectManager $manager)
{
// Users
$userNew = new User();
$userNew->setUsername('rasben');
$userNew->setPassword('rasben2');
$userNew->setFullName('Benjamin Rasmussen');
$userNew->setApiKey('apirasben');
$manager->persist($userNew);
$manager->flush();
$userNew = new User();
$userNew->setUsername('elvis');
$userNew->setPassword('elvis2');
$userNew->setFullName('Elvis Presley');
$userNew->setApiKey('apielvis');
$manager->persist($userNew);
$manager->flush();
$userNew = new User();
$userNew->setUsername('sherlock');
$userNew->setPassword('sherlock2');
$userNew->setFullName('Sherlock Holmes');
$userNew->setApiKey('apisherlock');
$manager->persist($userNew);
$manager->flush();
$userNew = new User();
$userNew->setUsername('alexander');
$userNew->setPassword('alexander2');
$userNew->setFullName('Alexander The Great');
$userNew->setApiKey('apialexander');
$manager->persist($userNew);
$manager->flush();
// Kitchens
$kitchenNew = new Kitchen();
$kitchenNew->setName('The Copenhagen Kitchen');
$kitchenNew->setLocation('Copenhagen, DK');
$manager->persist($kitchenNew);
$manager->flush();
$kitchenNew = new Kitchen();
$kitchenNew->setName('The London Kitchen');
$kitchenNew->setLocation('London, UK');
$manager->persist($kitchenNew);
$manager->flush();
$kitchenNew = new Kitchen();
$kitchenNew->setName('The Berlin Kitchen');
$kitchenNew->setLocation('Berlin, DE');
$manager->persist($kitchenNew);
$manager->flush();
// Languages
$languageNew = new Language();
$languageNew->setCode('en');
$manager->persist($languageNew);
$manager->flush();
$languageNew = new Language();
$languageNew->setCode('da');
$manager->persist($languageNew);
$manager->flush();
$languageNew = new Language();
$languageNew->setCode('fr');
$manager->persist($languageNew);
$manager->flush();
// User Settings
$userSettingNew = new UserSetting();
$userSettingNew->setUserID($manager->getReference('AppBundle:User', 1));
$userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 1));
$userSettingNew->setAutoOpenDefaultKitchen(2);
$userSettingNew->setModerator(2);
$userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en'));
$manager->persist($userSettingNew);
$manager->flush();
$userSettingNew = new UserSetting();
$userSettingNew->setUserID($manager->getReference('AppBundle:User', 2));
$userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 2));
$userSettingNew->setAutoOpenDefaultKitchen(1);
$userSettingNew->setModerator(1);
$userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en'));
$manager->persist($userSettingNew);
$manager->flush();
$userSettingNew = new UserSetting();
$userSettingNew->setUserID($manager->getReference('AppBundle:User', 3));
$userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 2));
$userSettingNew->setAutoOpenDefaultKitchen(2);
$userSettingNew->setModerator(1);
$userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en'));
$manager->persist($userSettingNew);
$manager->flush();
$userSettingNew = new UserSetting();
$userSettingNew->setUserID($manager->getReference('AppBundle:User', 4));
$userSettingNew->setDefaultKitchenID($manager->getReference('AppBundle:Kitchen', 2));
$userSettingNew->setAutoOpenDefaultKitchen(4);
$userSettingNew->setModerator(2);
$userSettingNew->setLanguageCode($manager->getReference('AppBundle:Language', 'en'));
$manager->persist($userSettingNew);
$manager->flush();
// Roles
$roleNew = new Role();
$roleNew->setTitle('owner');
$manager->persist($roleNew);
$manager->flush();
$roleNew = new Role();
$roleNew->setTitle('editor');
//.........这里部分代码省略.........
示例4: apiKeyAction
/**
*
* @Route("/user/{user}/apikey", name="user.apikey")
* @Method({"POST"})
*/
public function apiKeyAction(User $user, Request $request)
{
$random = bin2hex(random_bytes(30));
$user->setApiKey($random);
/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$this->addFlash('notice', 'Here is a new API key for user ' . $user->getUsername() . ' ' . $random);
return $this->redirectToRoute('user.index');
}