setUsername() public method

public setUsername ( $username )
コード例 #1
0
 public function setUp()
 {
     $this->user = new User();
     $this->user->setUsername('test');
     $this->user->setEmail('*****@*****.**');
     $this->user->setPassword('test');
     $this->log = new StressLog();
     $this->log->setLocaltime(new \DateTime());
     $this->log->setLevel(6);
     $this->log->setUser($this->user);
 }
コード例 #2
0
ファイル: LoadFixtures.php プロジェクト: jbarad/symfony_demo
 private function loadUsers(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $johnUser = new User();
     $johnUser->setUsername('john_user');
     $johnUser->setEmail('*****@*****.**');
     $encodedPassword = $passwordEncoder->encodePassword($johnUser, 'kitten');
     $johnUser->setPassword($encodedPassword);
     $manager->persist($johnUser);
     $annaAdmin = new User();
     $annaAdmin->setUsername('anna_admin');
     $annaAdmin->setEmail('*****@*****.**');
     $annaAdmin->setRoles(array('ROLE_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten');
     $annaAdmin->setPassword($encodedPassword);
     $manager->persist($annaAdmin);
     $avantripAdmin = new User();
     $avantripAdmin->setUsername('admin');
     $avantripAdmin->setEmail('*****@*****.**');
     $avantripAdmin->setRoles(array('ROLE_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($avantripAdmin, 'adminavantrip');
     $avantripAdmin->setPassword($encodedPassword);
     $manager->persist($avantripAdmin);
     $manager->flush();
 }
コード例 #3
0
ファイル: LoadUserData.php プロジェクト: syrotchukandrew/blog
 public function load(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $user_user = new User();
     $user_user->setUsername('user_user');
     $user_user->setEmail('*****@*****.**');
     $user_user->setRoles(array('ROLE_USER'));
     $user_user->setEnabled(true);
     $encodedPassword = $passwordEncoder->encodePassword($user_user, 'qweasz');
     $user_user->setPassword($encodedPassword);
     $manager->persist($user_user);
     $user_admin = new User();
     $user_admin->setUsername('user_admin');
     $user_admin->setEmail('*****@*****.**');
     $user_admin->setRoles(array('ROLE_ADMIN'));
     $user_admin->setEnabled(true);
     $encodedPassword = $passwordEncoder->encodePassword($user_admin, 'qweasz');
     $user_admin->setPassword($encodedPassword);
     $manager->persist($user_admin);
     $user_moderator = new User();
     $user_moderator->setUsername('user_moderator');
     $user_moderator->setEmail('*****@*****.**');
     $user_moderator->setRoles(array('ROLE_MODERATOR'));
     $user_moderator->setEnabled(true);
     $encodedPassword = $passwordEncoder->encodePassword($user_moderator, 'qweasz');
     $user_moderator->setPassword($encodedPassword);
     $manager->persist($user_moderator);
     $manager->flush();
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userEmail = $response->getEmail();
     $user = $this->userManager->findUserByEmail($userEmail);
     // if null just create new user and set it properties
     if (null === $user) {
         $userData = $response->getResponse();
         $user = new User();
         $user->setUsername($userData['formattedName']);
         $user->setPlainPassword(rand(1000000, 10000000));
         //TODO:find a better option
         //TODO: add location, company name, ..
         $user->setEmail($response->getEmail());
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         $this->em->flush();
         return $user;
     }
     // else update access token of existing user
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     $user->{$setter}($response->getAccessToken());
     //update access token
     return $user;
 }
コード例 #5
0
ファイル: Users.php プロジェクト: ebuzz/skillSearcher
 public function load(ObjectManager $manager)
 {
     $users = array(array('name' => 'Gabe', 'lastName' => 'Newell', 'surName' => '', 'email' => '*****@*****.**', 'password' => 'admin', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_ADMIN', 'image' => 'blog_newell1.jpg', 'positionId' => 1), array('name' => 'Kayla', 'lastName' => 'Person', 'surName' => '', 'email' => '*****@*****.**', 'password' => 'rh', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_RH', 'image' => 'Kayla_Person-small.jpg', 'positionId' => 1), array('name' => 'Alejandro', 'lastName' => 'Hernandez', 'surName' => 'Marquez', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'MikePerson.jpg', 'positionId' => 1), array('name' => 'Bernardo', 'lastName' => 'Lemus', 'surName' => 'Ortiz', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'ralf-a.jpg', 'positionId' => 1), array('name' => 'Christian', 'lastName' => 'Flores', 'surName' => 'Filis', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'img_person.jpg', 'positionId' => 1), array('name' => 'David', 'lastName' => 'Acosta', 'surName' => 'Arellano', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'person3.jpg', 'positionId' => 1), array('name' => 'Eric', 'lastName' => 'Martinez', 'surName' => 'Ibarra', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => '3709.jpg', 'positionId' => 1), array('name' => 'Felipe', 'lastName' => 'Trejo', 'surName' => 'Contreras', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'people_with_arthritis.jpg', 'positionId' => 1), array('name' => 'Gerardo', 'lastName' => 'Garcia', 'surName' => 'Najera', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'img-02.jpg', 'positionId' => 1), array('name' => 'Hugo', 'lastName' => 'Ruiz', 'surName' => 'Sanchez', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'img-10.jpg', 'positionId' => 1), array('name' => 'Ignacio', 'lastName' => 'Corona', 'surName' => 'Silva', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'img-12.jpg', 'positionId' => 1), array('name' => 'Javier', 'lastName' => 'Reyes', 'surName' => 'Leon', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'img-13.jpg', 'positionId' => 1), array('name' => 'Karla', 'lastName' => 'Juarez', 'surName' => 'Mejia', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'images.jpg', 'positionId' => 1), array('name' => 'Lorenzo', 'lastName' => 'Escoto', 'surName' => 'Villalobos', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'img-21.jpg', 'positionId' => 1), array('name' => 'Steve', 'lastName' => 'Jobs', 'surName' => '', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'Jobs0212120.jpg', 'positionId' => 1), array('name' => 'Nestor', 'lastName' => 'Salinas', 'surName' => 'Morales', 'email' => '*****@*****.**', 'password' => 'admin', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'person2.jpg', 'positionId' => 1), array('name' => 'Omar', 'lastName' => 'Torres', 'surName' => 'Zavaleta', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'person-detail.jpg', 'positionId' => 1), array('name' => 'Pedro', 'lastName' => 'Romero', 'surName' => 'Flores', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'poy_nomination_agassi.jpg', 'positionId' => 1), array('name' => 'Ruben', 'lastName' => 'Aceves', 'surName' => 'Nieto', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'person4.jpg', 'positionId' => 1), array('name' => 'Santiago', 'lastName' => 'Soriano', 'surName' => 'Aguilar', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'dan-misener-600_1.jpg', 'positionId' => 1), array('name' => 'Barack', 'lastName' => 'Obama', 'surName' => '', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'u-s-president-barack-obama.jpg', 'positionId' => 1), array('name' => 'Robin', 'lastName' => 'Williams', 'surName' => '', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'tumblr.jpg', 'positionId' => 1), array('name' => 'Bill', 'lastName' => 'Gates', 'surName' => '', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'bill-gates.jpg', 'positionId' => 1), array('name' => 'Kim', 'lastName' => 'Jong', 'surName' => 'Un', 'email' => '*****@*****.**', 'password' => '1234', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'kwc.jpg', 'positionId' => 1), array('name' => 'Vladimir', 'lastName' => 'Putin', 'surName' => '', 'email' => '*****@*****.**', 'password' => 'admin', 'admissionDate' => '12-12-12', 'roles' => 'ROLE_USER', 'image' => 'putinwink.jpg', 'positionId' => 1));
     // Cuando se haga el 'seed' de Usuarios se pondran Roles por default
     // Role : Colaborador
     // $repository = $manager
     // ->getRepository('AppBundle:Role');
     // $roleEntity = $repository->find(1);
     // Position : Software Developer
     $repository = $manager->getRepository('AppBundle:Position');
     $positionEntity = $repository->find(1);
     // dump($roleentity);
     // $roleentity = new Role();
     // $roleentity->setName("ROL NO REAL");
     // $positionentity = new Position();
     // $positionentity->setName("POSICION NO REAL");
     foreach ($users as $user) {
         $entity = new User();
         $entity->setName($user['name']);
         $entity->setLastName($user['lastName']);
         $entity->setSurName($user['surName']);
         $entity->setUsername($user['email']);
         $entity->setPassword($user['password']);
         $entity->setAdmissionDate(new \DateTime("now"));
         $entity->setImage($user['image']);
         $entity->setRoles($user['roles']);
         $entity->setPosition($positionEntity);
         $manager->persist($entity);
     }
     $manager->flush();
 }
コード例 #6
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $userAdmin = new User();
     $userAdmin->setUsername('ricardo75');
     $userAdmin->setFirstName('richard');
     $userAdmin->setLastName('lawson');
     $userAdmin->setEmail('*****@*****.**');
     $userAdmin->setPlainPassword('aberdeen');
     $userAdmin->setRoles(array('ROLE_SUPER_ADMIN'));
     $userAdmin->setEnabled(true);
     $user = new User();
     $user->setUsername('flipshark');
     $user->setFirstName('mick');
     $user->setLastName('jagger');
     $user->setEmail('*****@*****.**');
     $user->setPlainPassword('aberdeen');
     $user->setRoles(array('ROLE_USER'));
     $user->setEnabled(true);
     $user2 = new User();
     $user2->setUsername('elcondor');
     $user2->setFirstName('keith');
     $user2->setLastName('richards');
     $user2->setEmail('*****@*****.**');
     $user2->setPlainPassword('aberdeen');
     $user2->setRoles(array('ROLE_USER'));
     $user2->setEnabled(true);
     $manager->persist($userAdmin);
     $manager->persist($user);
     $manager->persist($user2);
     $manager->flush();
     $this->addReference('user-ricardo75', $userAdmin);
     $this->addReference('user-flipshark', $user);
 }
コード例 #7
0
 /**
  * @Route("/registration/new", name="registrationNew")
  */
 public function registrationAction(Request $request)
 {
     $user = new User();
     $user->setUsername(mb_strtolower($request->get('_username')));
     if ($request->get('_password') != $request->get('_password-2')) {
         $error = 'Пароли не совпадают';
         return $this->render(':user:registration.html.twig', array('error' => $error));
     }
     $plainPassword = $request->get('_password');
     $encoder = $this->container->get('security.password_encoder');
     $encoded = $encoder->encodePassword($user, $plainPassword);
     $user->setPassword($encoded);
     $user->setFirstName($request->get('_firstName'));
     $user->setSecondName($request->get('_secondName'));
     $user->setEmail($request->get('_email'));
     $user->setPost($request->get('_select'));
     //        $user->setRoles('ROLE_USER');
     $em = $this->getDoctrine()->getManager();
     try {
         $em->persist($user);
         $em->flush();
     } catch (\Exception $e) {
         $error = 'Логин уже занят';
         return $this->render(':user:registration.html.twig', array('error' => $error));
     }
     //        if ($this->isGranted('ROLE_ADMIN')) {
     //            return $this->showUserAction($user->getId());
     //        }
     $token = new UsernamePasswordToken($user, $user->getPassword(), 'database_users', $user->getRoles());
     $this->get('security.token_storage')->setToken($token);
     return $this->redirectToRoute('userPage', array('id' => $user->getId()));
 }
コード例 #8
0
ファイル: LoadUser.php プロジェクト: mkhrystunov/guest_book
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername(self::TEST_USER_USERNAME)->setPlainPassword(self::TEST_USER_PASSWORD)->setRoles(['ROLE_ADMIN']);
     $manager->persist($user);
     $manager->flush();
 }
コード例 #9
0
 private function loadPosts(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $user = new User();
     $user->setUsername('vvasia');
     $user->setDisplayName('Vasia Vasin');
     $user->setEmail('*****@*****.**');
     $user->setUuid('uuid');
     $encodedPassword = $passwordEncoder->encodePassword($user, 'password');
     $user->setPassword($encodedPassword);
     $user->setRoles(['ROLE_USER']);
     $manager->persist($user);
     $manager->flush();
     /** @var User $author */
     $author = $manager->getRepository('AppBundle:User')->findOneBy(['email' => '*****@*****.**']);
     foreach (range(1, 10) as $i) {
         $post = new Post();
         $post->setTitle($this->getRandomPostTitle() . ' ' . uniqid())->setSummary($this->getRandomPostSummary())->setSlug($this->container->get('slugger')->slugify($post->getTitle()))->setContent($this->getPostContent())->setAuthor($author)->setPublishedAt(new \DateTime('now - ' . $i . 'days'))->setState($this->getRandomState())->setCategory($category);
         foreach (range(1, 5) as $j) {
             $comment = new Comment();
             $comment->setUser($user)->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'))->setContent($this->getRandomCommentContent())->setPost($post);
             $manager->persist($comment);
             $post->addComment($comment);
         }
         if (rand(0, 1)) {
             $vote = new Vote();
             $vote->setAuthorEmail(rand(0, 1) ? '*****@*****.**' : '*****@*****.**');
             $vote->setPost($post);
             $vote->setVote(rand(0, 1));
         }
         $manager->persist($post);
         $category->addPost($post);
     }
     $manager->flush();
 }
コード例 #10
0
 public function createAction($format)
 {
     try {
         $em = $this->getDoctrine()->getManager();
         $user = new User();
         $params = array();
         $content = $this->get("request")->getContent();
         if (!empty($content)) {
             $params = json_decode($content, true);
             $user->setConfirmationToken($params['confirmationToken']);
             $user->setCredentialsExpireAt($params['credentialsExpireAt']);
             $user->setCredentialsExpired($params['credentialsExpired']);
             $user->setEmail($params['email']);
             $user->setEmailCanonical($params['emailCanonical']);
             $user->setEnabled($params['enabled']);
             $user->setExpired($params['expired']);
             $user->setExpiresAt($params['expiresAt']);
             $user->setLastLogin($params['lastLogin']);
             $user->setLocked($params['locked']);
             $user->setPassword($params['password']);
             $user->setPasswordRequestedAt($params['passwordRequestedAt']);
             $user->setRoles($params['roles']);
             $user->setSalt($params['salt']);
             $user->setUsername($params['username']);
             $user->setUsernameCanonical($params['usernameCanonical']);
         }
         $em->persist($user);
         $em->flush();
         return $this->formatResponse("ok", $format);
     } catch (Exception $ex) {
         return $this->formatResponse("error", $format);
     }
 }
コード例 #11
0
ファイル: LoadUser.php プロジェクト: jszutkowski/example
 public function load(ObjectManager $manager)
 {
     $password = "******";
     $user = new User();
     $user->setUsername('rafael');
     $user->setPassword($this->getEncoder($user)->encodePassword($password, $user->getSalt()));
     $user->setName('Rafael');
     $user->setEmail('*****@*****.**');
     $manager->persist($user);
     $user2 = new User();
     $user2->setUsername('donatello');
     $user2->setPassword($this->getEncoder($user2)->encodePassword($password, $user2->getSalt()));
     $user2->setName('Donatello');
     $user2->setEmail('*****@*****.**');
     $manager->persist($user2);
     $user3 = new User();
     $user3->setUsername('michelangelo');
     $user3->setPassword($this->getEncoder($user3)->encodePassword($password, $user3->getSalt()));
     $user3->setName('Michelangelo');
     $user3->setEmail('*****@*****.**');
     $manager->persist($user3);
     $user4 = new User();
     $user4->setUsername('leonardo');
     $user4->setPassword($this->getEncoder($user4)->encodePassword($password, $user4->getSalt()));
     $user4->setName('Leonardo');
     $user4->setEmail('*****@*****.**');
     $manager->persist($user4);
     $manager->flush();
 }
コード例 #12
0
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     try {
         $resourceOwnerName = $response->getResourceOwner()->getName();
         if (!isset($this->properties[$resourceOwnerName])) {
             throw new \RuntimeException(sprintf("No property defined for entity for resource owner '%s'.", $resourceOwnerName));
         }
         $username = $response->getUsername();
         if (null === ($user = $this->repository->findOneBy(array($this->properties[$resourceOwnerName] => $username)))) {
             throw new UsernameNotFoundException(sprintf("User '%s' not found.", $username));
         }
         return $user;
     } catch (UsernameNotFoundException $e) {
         $rawResponse = $response->getResponse();
         $user = new User($rawResponse['screen_name']);
         $user->setTwitterId($rawResponse['id']);
         $user->setUsername($rawResponse['screen_name']);
         $user->setTodaySinceId('');
         $user->setIsActive(true);
         $user->setCreateAt(new \DateTime());
         $user->setUpdateAt(new \DateTime());
         $this->em->persist($user);
         $this->em->flush();
         return $user;
     }
 }
コード例 #13
0
ファイル: AuthController.php プロジェクト: Quiss/Oon
 /**
  * @Route("/admin-login", name="admin-login")
  * @Template()
  */
 public function loginAction()
 {
     // создание пользователя
     $manager = $this->getDoctrine()->getManager();
     $user = new User();
     $user->setUsername('admin');
     $user->setSalt(md5(time()));
     $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
     $password = $encoder->encodePassword('admin', $user->getSalt());
     $user->setPassword($password);
     $user->setRoles('ROLE_OPERATOR');
     $user->setLastName('admin');
     $user->setFirstName('admin');
     $user->setSurName('admin');
     $user->setPhone('+79161111111');
     //
     $manager->persist($user);
     $manager->flush($user);
     if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
         $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
     } else {
         $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
     }
     $pages = $this->getDoctrine()->getRepository('AppBundle:Page')->findAll();
     return array('error' => $error, 'pages' => $pages);
 }
コード例 #14
0
 public function load(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     for ($i = 0; $i < 3; $i++) {
         $user_user = new User();
         $user_user->setUsername('user_user' . $i);
         $user_user->setEmail('user_user' . $i . '@rainbow.com');
         $user_user->setRoles(array('ROLE_USER'));
         $user_user->setEnabled(true);
         $encodedPassword = $passwordEncoder->encodePassword($user_user, 'qweasz');
         $user_user->setPassword($encodedPassword);
         $manager->persist($user_user);
         $user_manager = new User();
         $user_manager->setUsername('user_manager' . $i);
         $user_manager->setEmail('user_manager' . $i . '@rainbow.com');
         $user_manager->setRoles(array('ROLE_MANAGER'));
         $user_manager->setEnabled(true);
         $encodedPassword = $passwordEncoder->encodePassword($user_manager, 'qweasz');
         $user_manager->setPassword($encodedPassword);
         $manager->persist($user_manager);
     }
     $user_admin = new User();
     $user_admin->setUsername('user_admin');
     $user_admin->setEmail('*****@*****.**');
     $user_admin->setRoles(array('ROLE_ADMIN'));
     $user_admin->setEnabled(true);
     $encodedPassword = $passwordEncoder->encodePassword($user_admin, 'qweasz');
     $user_admin->setPassword($encodedPassword);
     $manager->persist($user_admin);
     $manager->flush();
 }
コード例 #15
0
ファイル: RecordController.php プロジェクト: 8785496/record
 /**
  * @Route("/record/anonymous", name="createRecordAnonymously")
  * @Method("POST")
  */
 public function createAnonymouslyAction(Request $request)
 {
     // user anonymous
     $repository = $this->getDoctrine()->getRepository('AppBundle:User');
     $count = $repository->count();
     $username = '******' . dechex($count);
     $password = chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90));
     $user = new User();
     $user->setUsername($username);
     $user->setPassword(md5($password));
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     $em->flush();
     // record
     $content = $request->getContent();
     $response = json_decode($content, true);
     if ($user != null) {
         $record = new Record();
         $record->setScore($response['score']);
         $record->setUserId($user->getId());
         $em = $this->getDoctrine()->getManager();
         $em->persist($record);
         $em->flush();
         return new JsonResponse(['code' => 1, 'record' => ['id' => $record->getId(), 'score' => $record->getScore(), 'userId' => $record->getUserId()], 'user' => ['username' => $user->getUsername(), 'password' => $password]]);
     } else {
         return new JsonResponse(['code' => 0, 'message' => 'record not save']);
     }
 }
コード例 #16
0
 /**
  * handles the creation of a new User
  * @Route("/register/create", name="create_user")
  */
 public function createUserAction()
 {
     $errorMessage = "";
     $successMessage = "";
     $defaultValues = ['username' => "", 'password' => "", 'passwordconfirm' => "", 'email' => ""];
     // get POST request
     $request = Request::createFromGlobals();
     $username = $request->request->get('username');
     $email = $request->request->get('email');
     $password = $request->request->get('password');
     $passwordconfirm = $request->request->get('passwordconfirm');
     //checks what fields are blank
     if (empty($username) || empty($email) || empty($password) || empty($passwordconfirm)) {
         $errorMessage = "Sie müssen alle Felder ausfüllen!";
         $defaultValues = ['username' => $username, 'password' => $password, 'passwordconfirm' => $passwordconfirm, 'email' => $email];
     } elseif ($password !== $passwordconfirm) {
         $errorMessage = "Die Passwörter müssen übereinstimmen!";
         $defaultValues = ['username' => $username, 'password' => "", 'passwordconfirm' => "", 'email' => $email];
     } else {
         //writes the the new User in the Database
         $user = new User();
         $user->setUsername($username);
         $user->setPassword(password_hash($password, PASSWORD_BCRYPT, array('cost' => 12)));
         $user->setEmail($email);
         $user->setRoles(array('ROLE_USER'));
         $em = $this->getDoctrine()->getManager();
         $em->persist($user);
         $em->flush();
         $successMessage = "Benutzer wurde erfolgreich angelegt!";
     }
     return $this->render('AppBundle:Account:register.html.twig', array('errorMessage' => $errorMessage, 'successMessage' => $successMessage, 'defaultValues' => $defaultValues));
 }
コード例 #17
0
 public function load(ObjectManager $manager)
 {
     $encoder = $this->container->get('security.password_encoder');
     $userAdmin = new User();
     $userAdmin->setEmail('*****@*****.**');
     $userAdmin->setEnabled(1);
     $userAdmin->setUsername('Paul Mesnilgrente');
     $password = $encoder->encodePassword($userAdmin, 'lB7Xq9WdOxCz7Xzod1FH');
     $userAdmin->setPassword($password);
     $userAdmin->setRoles(array('ROLE_SUPER_ADMIN'));
     $manager->persist($userAdmin);
     $manager->flush();
     $user1 = new User();
     $user1->setEmail('*****@*****.**');
     $user1->setEnabled(1);
     $user1->setUsername('Karol-anne Pelosato');
     $password = $encoder->encodePassword($user1, '2pMJVtuDtwkctwtf3fLQ');
     $user1->setPassword($password);
     $user1->setRoles(array('ROLE_USER'));
     $manager->persist($user1);
     $manager->flush();
     $user2 = new User();
     $user2->setEmail('*****@*****.**');
     $user2->setEnabled(1);
     $user2->setUsername('Fabien Mesnilgrente');
     $password = $encoder->encodePassword($user2, 'lv4Uem4OtFmfSYYDGX');
     $user2->setPassword($password);
     $user2->setRoles(array('ROLE_USER'));
     $manager->persist($user2);
     $manager->flush();
     $this->addReference('user-admin', $userAdmin);
     $this->addReference('user-karo', $user1);
     $this->addReference('user-fabien', $user2);
 }
コード例 #18
0
 public function load(ObjectManager $manager)
 {
     /** @var EncoderFactoryInterface */
     $factory = $this->container->get('security.encoder_factory');
     $john = new User();
     $john->setUsername('john');
     $john->setEmail('*****@*****.**');
     $john->setRoles(array('ROLE_USER'));
     $john->setEnabled(true);
     $encoder = $factory->getEncoder($john);
     $password = $encoder->encodePassword('john', $john->getSalt());
     $john->setPassword($password);
     $john->setApiToken('abcdefgh');
     $manager->persist($john);
     $sofia = new User();
     $sofia->setUsername('sofia');
     $sofia->setEmail('*****@*****.**');
     $sofia->setRoles(array('ROLE_USER'));
     $sofia->setEnabled(true);
     $encoder = $factory->getEncoder($sofia);
     $password = $encoder->encodePassword('sofia', $sofia->getSalt());
     $sofia->setPassword($password);
     $sofia->setApiToken('1234567');
     $manager->persist($sofia);
     $manager->flush();
 }
コード例 #19
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $joeUser = new User();
     $joeUser->setUsername('joe_user');
     $joeUser->setEmail('*****@*****.**');
     $encodedPassword = $passwordEncoder->encodePassword($joeUser, 'pa$$word');
     $joeUser->setPassword($encodedPassword);
     $joeUser->setEnabled(true);
     $manager->persist($joeUser);
     $this->setReference('user-joe_user', $joeUser);
     $johnAdmin = new User();
     $johnAdmin->setUsername('john_admin');
     $johnAdmin->setEmail('*****@*****.**');
     $johnAdmin->setRoles(array('ROLE_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($johnAdmin, 'pa$$word');
     $johnAdmin->setPassword($encodedPassword);
     $johnAdmin->setEnabled(true);
     $manager->persist($johnAdmin);
     $this->setReference('user-john_admin', $johnAdmin);
     $jackSuper = new User();
     $jackSuper->setUsername('jack_super');
     $jackSuper->setEmail('*****@*****.**');
     $jackSuper->setRoles(array('ROLE_SUPER_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($jackSuper, 'pa$$word');
     $jackSuper->setPassword($encodedPassword);
     $jackSuper->setEnabled(true);
     $manager->persist($jackSuper);
     $this->setReference('user-jack_super', $jackSuper);
     $manager->flush();
 }
コード例 #20
0
 public function getUser($authorizationCode, UserProviderInterface $userProvider)
 {
     $provider = $this->getFacebookOAuthProvider();
     try {
         // the credentials are really the access token
         $accessToken = $provider->getAccessToken('authorization_code', ['code' => $authorizationCode]);
     } catch (IdentityProviderException $ex) {
         $response = $e->getResponseBody();
         $errorCode = $response['error']['code'];
         $message = $response['error']['message'];
         //var_dump($response);
         //TODO throw a custom error to handle ???
     }
     $fbUser = $provider->getResourceOwner($accessToken);
     $email = $fbUser->getEmail();
     $em = $this->container->get('doctrine')->getManager();
     $user = $em->getRepository('AppBundle:User')->findOneBy(['email' => $email]);
     //If there is no user, we need to create one
     if (!$user) {
         $user = new User();
         $user->setUsername($email);
         $user->setEmail($email);
         //Set to unencoded password.
         //Since passwords are encode when checked, users should not be able to login using it
         $user->setPassword('FACEBOOK LOGIN');
         //Make sure that a user has at least the role of ROLE_USER when created
         $roles = $user->getRoles();
         $user->setRoles($roles);
     }
     $user->setFacebookId($fbUser->getId());
     $em->persist($user);
     $em->flush();
     return $user;
 }
コード例 #21
0
ファイル: AuthController.php プロジェクト: Quiss/Oon
 /**
  * @Route("/register", name="register")
  * @Template()
  */
 public function registerAction(Request $request)
 {
     if ($request->getMethod() == 'POST') {
         $manager = $this->getDoctrine()->getManager();
         $user = new User();
         $user->setUsername($request->request->get('username'));
         $user->setSalt(md5(time()));
         $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
         $password = $encoder->encodePassword($request->request->get('password'), $user->getSalt());
         $user->setPassword($password);
         $user->setRoles('ROLE_UNCONFIRMED');
         $user->setLastName($request->request->get('lastName'));
         $user->setFirstName($request->request->get('firstName'));
         $user->setSurName('');
         $user->setPhone($request->request->get('phone'));
         $user->setCompany($request->request->get('companyTitle'));
         $manager->persist($user);
         $manager->flush($user);
         $manager->refresh($user);
         $session = new Session();
         $session->getFlashBag()->add('success', 'Ваша заявка принята. Пожалуйста, ожидайте подтверждения регистрации на указанный электронный адрес');
         @$this->get('email.service')->send(array($user->getUsername()), array('AppBundle:Email:registerNotifyUser.html.twig'), 'Сообщение от navigator mediaFirst');
         @$this->get('email.service')->send(array('*****@*****.**', '*****@*****.**', '*****@*****.**'), array('AppBundle:Email:registerNotify.html.twig'), 'Сообщение от navigator mediaFirst');
         return $this->redirect($this->generateUrl('homepage'));
     }
     return array();
 }
コード例 #22
0
ファイル: LoadUserData.php プロジェクト: roman-movchan/quizz
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $userAdmin = new User();
     $userAdmin->setUsername('admin');
     $userAdmin->setPassword('test');
     $manager->persist($userAdmin);
     $manager->flush();
 }
コード例 #23
0
 protected function setUpPlayer()
 {
     $user = new User();
     $user->setId(1);
     $user->setUsername('ricardo75');
     $player = new Player($user, Game::FLIP_TYPE_HEADS);
     return $player;
 }
コード例 #24
0
ファイル: LoadUserData.php プロジェクト: elrodir/myrepo
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername('admin');
     $password = $this->container->get('security.password_encoder')->encodePassword($user, 'password');
     $user->setPassword($password);
     $manager->persist($user);
     $manager->flush();
 }
コード例 #25
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $dialog */
     $dialog = $this->getHelperSet()->get('question');
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $output->writeln("");
     $usernameQuestion = new Question(" Enter username [admin]: ", "admin");
     $username = $dialog->ask($input, $output, $usernameQuestion);
     $passwordQuestion = new Question(" Enter password: "******"");
         $errorMessages = ['Error!', 'Please enter not blank password!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         $password = $dialog->ask($input, $output, $passwordQuestion);
         $output->writeln("");
     }
     if (!$password) {
         $output->writeln("");
         $errorMessages = ['Error!', 'If password is blank then goodbye!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         $output->writeln("");
         return;
     }
     $output->writeln("");
     $output->writeln('<info>  Summary information:</>');
     $table = new Table($output);
     $table->setHeaders(['Username'])->setRows([[$username]]);
     $table->render();
     $output->writeln("");
     $question = new ConfirmationQuestion("it's ok? [y/N]: ", false);
     if (!$dialog->ask($input, $output, $question)) {
         $errorMessages = ['Goodbye!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         return;
     }
     /** @var EntityManager $em */
     $em = $this->getContainer()->get('doctrine')->getManager();
     /** @var UserPasswordEncoder $encoder */
     $encoder = $this->getContainer()->get('security.password_encoder');
     if ($em->getRepository('AppBundle:User')->findBy(['username' => $username])) {
         $errorMessages = ['User are exist with input email!!!!'];
         $formattedBlock = $formatter->formatBlock($errorMessages, 'error');
         $output->writeln($formattedBlock);
         return;
     }
     $user = new User();
     $user->setUsername($username)->setPassword($encoder->encodePassword($user, $password))->setRoles($user::ROLE_ADMIN_USER);
     $em->persist($user);
     $em->flush();
     $output->writeln('<bg=green>Well done! Admin was created.</>');
 }
コード例 #26
0
ファイル: ApiTestCase.php プロジェクト: juuuuuu/budget
 protected function createUser($username, $password = '******')
 {
     $user = new User();
     $user->setUsername($username);
     $user->setPassword($password);
     $this->getEntityManager()->persist($user);
     $this->getEntityManager()->flush();
     return $user;
 }
コード例 #27
0
ファイル: LoadUserData.php プロジェクト: pueppiblue/lapp
 public function load(ObjectManager $manager)
 {
     $user = new User();
     $user->setUsername('admin')->setPassword('admin')->setActive(true);
     $manager->persist($user);
     $user = new User();
     $user->setUsername('Bücherwurm84')->setPassword('readforlife')->setActive(true);
     $manager->persist($user);
     $manager->flush();
 }
コード例 #28
0
ファイル: UserData.php プロジェクト: staegi/symfony-rest-api
 /**
  * @param ObjectManager $manager
  *
  * @return $this
  */
 public function load(ObjectManager $manager)
 {
     $timeZone = new \DateTimeZone('Europe/Berlin');
     $admin = new User();
     $admin->setUsername('admin')->setEmail('*****@*****.**')->setSuperAdmin(true)->setEnabled(true)->setPassword('$2y$13$4mvcmdehjp2coco8sgkw8egeNvWHXplyy7ou0W0nJb0j8O33KciCy')->setLastLogin(new \DateTime('2016-01-04 12:13:14', $timeZone));
     $manager->persist($admin);
     $manager->flush();
     $this->addReference('admin-user', $admin);
     return $this;
 }
コード例 #29
0
 public function __construct()
 {
     $user = new User();
     $user->setId("1");
     $user->setUsername("test");
     $user->setEmail('*****@*****.**');
     $user->setPassword("pass");
     $user->setAvatarUrl("default_avatar.jpg");
     $this->user = $user;
 }
コード例 #30
0
ファイル: PageController.php プロジェクト: benblub/sf2_demo
 /**
  * @Route("/demo/examble", name="examble")
  */
 public function createAction()
 {
     $user = new User();
     $user->setUsername('Benjamin Knecht');
     $user->setEmail('*****@*****.**');
     $em = $this->getDoctrine()->getManager();
     $em->persist($user);
     $em->flush();
     return new Response('Created User id ' . $user->getId());
 }