public function saveUser(Users $user, ObjectManager $manager) { $user->setSalt(md5(time())); // шифрует и устанавливает пароль для пользователя, // эти настройки совпадают с конфигурационными файлами $encoder = new MessageDigestPasswordEncoder('sha512', true, 10); $password = $encoder->encodePassword($user->getPassword(), $user->getSalt()); $user->setPassword($password); $manager->persist($user); $manager->flush(); }
/** * Método para cargar usuarios de prueba */ private function loadUsers(ObjectManager $manager, $username, $email, $password, $roles) { $date = new \DateTime(date('Y-m-d H:i:s')); $user = new Users(); $user->setSalt(md5(uniqid(null, true))); $encoder = $this->container->get('security.password_encoder'); $pass = $encoder->encodePassword($password, $user->getSalt()); $user->setUsername($username); $user->setEmail($email); $user->setPassword($pass); $user->setActive(1); $user->setRoles($roles); $user->setCreatedAt($date); $user->setModifiedAt($date); $user->setCreatedBy(1); $manager->persist($user); unset($user); $manager->flush(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $user = new Users(); $user->setFirstName('John'); $user->setLastName('Doe'); $user->setPhoneNumber(32141234); $user->setEmail('*****@*****.**'); $user->setUsername('admin'); $user->setSalt(md5(time())); $website = new Websites(); $website->setStatus('enabled'); $website->setName('Vk'); $website->setUrl('http://vk.com'); // шифрует и устанавливает пароль для пользователя, // эти настройки совпадают с конфигурационными файлами $encoder = new MessageDigestPasswordEncoder('sha512', true, 10); $password = $encoder->encodePassword('admin', $user->getSalt()); $user->setPassword($password); $manager->persist($user); $manager->persist($website); $manager->flush(); }
/** * @Route("/sign_up", name="sign_up") * @Method({"GET", "POST"}) * * @param Request $request * @return Response */ public function signUpAction(Request $request) { $generator = new ComputerPasswordGenerator(); $generator->setUppercase()->setLowercase()->setNumbers()->setSymbols(false)->setLength(6); $password = $generator->generatePassword(); $users = new Users(); $login = $request->get('first-name'); $email = $request->get('email'); $users->setFirstName($login); $users->setSecondName($request->get('second-name')); $users->setPatronymic($request->get('patronymic')); $users->setEmail($email); $users->setUseReason($request->get('use-reason')); $users->setPassword($password); $em = $this->getDoctrine()->getManager(); try { $em->persist($users); $em->flush(); } catch (\Exception $error) { } $this->mailSend(['login' => $email, 'password' => $password]); return $this->render('default/thanks.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'))); }