Example #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $java = new Jobtitle();
     $php = new Jobtitle();
     $sql = new Jobtitle();
     $java->setName('Java Expert');
     $php->setName('PHP Expert');
     $sql->setName('Sql Expert');
     $manager->persist($java);
     $manager->persist($php);
     $manager->persist($sql);
     $userManager = $this->container->get('into_people_database.user_manager');
     $organization = $this->getReference('organization');
     $active = $this->getReference('active');
     $supervisor = $userManager->createUser();
     $supervisor->setJobtitle($java);
     $supervisor->setEmail('*****@*****.**');
     $supervisor->setUsername('*****@*****.**');
     $supervisor->setPlainPassword('test');
     $supervisor->setEnabled(true);
     $supervisor->setOrganization($organization);
     $supervisor->addRole('ROLE_SUPERVISOR');
     $supervisor->setFirstname('Jos');
     $supervisor->setLastname('Vermeulen');
     $supervisor->setLanguage($this->getReference('english'));
     $supervisor->setUsernameCanonical('*****@*****.**');
     $supervisor->setEmailCanonical('*****@*****.**');
     $supervisor->setUserstatus($active);
     $userManager->updateUser($supervisor);
     $hr = $userManager->createUser();
     $hr->setJobtitle($php);
     $hr->setEmail('*****@*****.**');
     $hr->setUsername('*****@*****.**');
     $hr->setPlainPassword('test');
     $hr->setUsernameCanonical('*****@*****.**');
     $hr->setEmailCanonical('*****@*****.**');
     $hr->setEnabled(true);
     $hr->addRole('ROLE_HR');
     $hr->setOrganization($organization);
     $hr->setFirstname('Mata');
     $hr->setLastname('Stalacorp');
     $hr->setLanguage($this->getReference('english'));
     $hr->setUserstatus($active);
     $userManager->updateUser($hr, true);
     $userManager->updateUser($hr);
     // Create user and set details
     $user = $userManager->createUser();
     $user->setJobtitle($sql);
     $user->setUsername('admin');
     $user->setEmail('*****@*****.**');
     $user->setPlainPassword('admin');
     $user->addRole('ROLE_USER');
     $user->setEnabled(true);
     $user->setFirstname('Queenie');
     $user->setLastname('Dirckx');
     $user->setLanguage($this->getReference('english'));
     $user->setOrganization($organization);
     $user->setUsernameCanonical('admin');
     $user->setEmailCanonical('*****@*****.**');
     $user->setSupervisor($supervisor);
     $user->setUserstatus($active);
     $userManager->updateUser($user);
 }
Example #2
0
 public function profileAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $user = $this->getUser();
     $encoder_service = $this->get('security.encoder_factory');
     $encoder = $encoder_service->getEncoder($user);
     $entities = $em->getRepository('IntoPeopleDatabaseBundle:Jobtitle')->findAll();
     $jobtitles = array_map(create_function('$o', 'return $o->getName();'), $entities);
     $form = $this->createFormBuilder($user)->add('jobtitle', 'text', array('mapped' => false, 'attr' => array('class' => 'typeahead')))->add('oldpassword', 'password', array('mapped' => false, 'required' => false))->add('newpassword', 'repeated', array('type' => 'password', 'mapped' => false, 'invalid_message' => $this->get('translator')->trans('passwordmatch'), 'options' => array('attr' => array('class' => 'password-field')), 'required' => false, 'first_options' => array('label' => 'Set new Password'), 'second_options' => array('label' => 'Repeat new Password')))->add('language', 'entity', array('class' => 'IntoPeopleDatabaseBundle:Language'))->add('Save', 'submit')->getForm();
     $form['jobtitle']->setData($user->getJobtitle()->getName());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $userManager = $this->get('fos_user.user_manager');
         $oldpassword = $form->get('oldpassword')->getData();
         $newpassword = $form->get('newpassword')->getData();
         if ($oldpassword != null & $newpassword != null) {
             $encoded_pass = $encoder->encodePassword($oldpassword, $user->getSalt());
             if ($user->getPassword() == $encoded_pass) {
                 $user->setPlainPassword($newpassword);
                 $userManager->updateUser($user);
             }
         }
         $jobtitle = $em->getRepository('IntoPeopleDatabaseBundle:Jobtitle')->findOneByName($form->get('jobtitle')->getData());
         if ($jobtitle == null) {
             $jobtitle = new Jobtitle();
             $jobtitle->setName($form->get('jobtitle')->getData());
             $em->persist($jobtitle);
         }
         $user->setJobtitle($jobtitle);
         // Notification message after Core Quality has been created
         //
         $tr = $this->get('translator');
         $message = $tr->trans('notification.user.profile');
         $this->addFlash('success', $message);
         $em->flush();
     }
     return $this->render('IntoPeopleDatabaseBundle:User:profile.html.twig', array('form' => $form->createView(), 'jobtitles' => $jobtitles));
 }