/** * Form builder * * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('sexe', ChoiceType::class, array('label' => 'User.sexe.label', 'choices_as_values' => true, 'choices' => User::choiceSexe(), 'attr' => array('choice_label_trans' => true))); $builder->add('firstName', TextType::class, array('label' => 'User.firstName.label', 'required' => false)); $builder->add('lastName', TextType::class, array('label' => 'User.lastName.label', 'required' => false)); $builder->add('birthday', DateType::class, array('label' => 'User.birthday.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'required' => false)); $builder->add('streetNum', IntegerType::class, array('label' => 'User.streetNum.label', 'scale' => 0, 'required' => false)); $builder->add('address', TextareaType::class, array('label' => 'User.address.label', 'required' => false)); $builder->add('address2', TextareaType::class, array('label' => 'User.address2.label', 'required' => false)); $builder->add('town', TextType::class, array('label' => 'User.town.label', 'required' => false)); $builder->add('zipCode', TextType::class, array('label' => 'User.zipCode.label', 'required' => false)); $builder->add('country', CountryType::class, array('label' => 'User.country.label', 'required' => false, 'placeholder' => 'Options.choose', 'empty_data' => null)); $builder->add('phone', TextType::class, array('label' => 'User.phone.label', 'required' => false)); $builder->add('mobile', TextType::class, array('label' => 'User.mobile.label', 'required' => false)); }
/** * * @return Trace */ private function initTrace() { $trace = new Trace(); $tokenStorage = $this->container->get('security.token_storage'); $authChecker = $this->container->get('security.authorization_checker'); $this->user = $tokenStorage->getToken()->getUser(); if ($this->user != null && $this->user instanceof User) { $trace->setUserId($this->user->getId()); if ($authChecker->isGranted('ROLE_SUPERADMIN', $this->user)) { $trace->setUserType(Trace::UT_SUPERADMIN); } elseif ($authChecker->isGranted('ROLE_ADMIN', $this->user)) { $trace->setUserType(Trace::UT_ADMIN); } else { $trace->setUserType(Trace::UT_CLIENT); } $trace->setUserFullname($this->user->getFullName()); } else { $trace->setUserType(Trace::UT_ANONYMOUS); $trace->setUserFullname('????????'); } return $trace; }
/** * Form builder * * @param FormBuilderInterface $builder * @param array $options * * @return null */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('username', TextType::class, array('label' => 'User.username.label')); $builder->add('email', EmailType::class, array('label' => 'User.email.label')); $builder->add('lockout', ChoiceType::class, array('label' => 'User.lockout.label', 'choices_as_values' => true, 'choices' => User::choiceLockout(), 'attr' => array('choice_label_trans' => true))); $builder->add('preferedLang', EntityType::class, array('label' => 'User.preferedLang.label', 'class' => 'AcfDataBundle:Lang', 'query_builder' => function (LangRepository $lr) { return $lr->createQueryBuilder('l')->orderBy('l.locale', 'ASC'); }, 'choice_label' => 'fullLocale', 'multiple' => false, 'by_reference' => true, 'required' => false, 'placeholder' => 'Options.choose', 'empty_data' => null)); $builder->add('sexe', ChoiceType::class, array('label' => 'User.sexe.label', 'choices_as_values' => true, 'choices' => User::choiceSexe(), 'attr' => array('choice_label_trans' => true))); $builder->add('firstName', TextType::class, array('label' => 'User.firstName.label', 'required' => false)); $builder->add('lastName', TextType::class, array('label' => 'User.lastName.label', 'required' => false)); $builder->add('birthday', DateType::class, array('label' => 'User.birthday.label', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'required' => false)); $builder->add('streetNum', IntegerType::class, array('label' => 'User.streetNum.label', 'scale' => 0, 'required' => false)); $builder->add('address', TextareaType::class, array('label' => 'User.address.label', 'required' => false)); $builder->add('address2', TextareaType::class, array('label' => 'User.address2.label', 'required' => false)); $builder->add('town', TextType::class, array('label' => 'User.town.label', 'required' => false)); $builder->add('zipCode', TextType::class, array('label' => 'User.zipCode.label', 'required' => false)); $builder->add('country', CountryType::class, array('label' => 'User.country.label', 'required' => false, 'placeholder' => 'Options.choose', 'empty_data' => null)); $builder->add('phone', TextType::class, array('label' => 'User.phone.label', 'required' => false)); $builder->add('mobile', TextType::class, array('label' => 'User.mobile.label', 'required' => false)); $builder->add('userRoles', EntityType::class, array('label' => 'User.userRoles.label', 'class' => 'AcfDataBundle:Role', 'query_builder' => function (RoleRepository $rr) { return $rr->createQueryBuilder('r')->orderBy('r.name', 'ASC'); }, 'choice_label' => 'name', 'multiple' => true, 'by_reference' => true, 'required' => true, 'attr' => array('choice_label_trans' => true))); }
/** * Get Query for All Entities * * @param User $user * * @return \Doctrine\ORM\Query */ public function getAllByUserQuery(User $user) { $qb = $this->createQueryBuilder('cu')->join('cu.user', 'c')->where('u.id = :id')->orderBy('cu.dtCrea', 'ASC')->setParameter('id', $user->getId()); $query = $qb->getQuery(); return $query; }
/** * Get Query for All Entities * * @param User $user * * @return \Doctrine\ORM\Query */ public function getAllByUserQuery(User $user) { $qb = $this->createQueryBuilder('i')->join('i.user', 'u')->where('u.id = :id')->andWhere('i.status = :status')->orderBy('i.dtCrea', 'DESC')->setParameter('id', $user->getId())->setParameter('status', OnlineInvoice::ST_OK); $query = $qb->getQuery(); return $query; }
/** * Form builder * * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('lockout', ChoiceType::class, array('label' => 'User.lockout.label', 'choices_as_values' => true, 'choices' => User::choiceLockout(), 'attr' => array('choice_label_trans' => true))); }
/** * Check user in list * * @param User $user * * @return boolean */ public function isUserInAgenda(User $user) { foreach ($this->users as $agendaUser) { if ($agendaUser->getId() == $user->getId()) { return true; } } return false; }
/** * Get Query for All Entities * * @param User $entity * * @return \Doctrine\ORM\Query */ public function getAllByUserQuery(User $entity) { return $this->createQueryBuilder('t')->where('t.actionEntity = :entityType')->andWhere('t.actionId = :aId')->orderBy('t.dtCrea', 'ASC')->addOrderBy('t.actionType', 'ASC')->addOrderBy('t.actionEntity', 'ASC')->setParameter('entityType', Trace::AE_USER)->setParameter('aId', $entity->getId())->getQuery(); }
protected function traceEntity(User $cloneUser, User $user) { $curUser = $this->getSecurityTokenStorage()->getToken()->getUser(); $trace = new Trace(); $trace->setActionId($user->getId()); $trace->setActionType(Trace::AT_UPDATE); $trace->setUserId($curUser->getId()); $trace->setUserFullname($curUser->getFullName()); if (!$this->hasRole('ROLE_SUPERADMIN')) { if (!$this->hasRole('ROLE_ADMIN')) { $trace->setUserType(Trace::UT_CLIENT); } else { $trace->setUserType(Trace::UT_ADMIN); } } else { $trace->setUserType(Trace::UT_SUPERADMIN); } $tableBegin = ': <br><table class="table table-bordered table-condensed table-hover table-striped">'; $tableBegin .= '<thead><tr><th class="text-left">' . $this->translate('Entity.field') . '</th>'; $tableBegin .= '<th class="text-left">' . $this->translate('Entity.oldVal') . '</th>'; $tableBegin .= '<th class="text-left">' . $this->translate('Entity.newVal') . '</th></tr></thead><tbody>'; $tableEnd = '</tbody></table>'; $trace->setActionEntity(Trace::AE_USER); $msg = ''; if ($cloneUser->getSexe() != $user->getSexe()) { $msg .= '<tr><td>' . $this->translate('User.sexe.label') . '</td><td>'; if ($cloneUser->getSexe() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $this->translate('User.sexe.' . $cloneUser->getSexe()); } $msg .= '</td><td>'; if ($user->getSexe() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $this->translate('User.sexe.' . $user->getSexe()); } $msg .= '</td></tr>'; } if ($cloneUser->getFirstName() != $user->getFirstName()) { $msg .= '<tr><td>' . $this->translate('User.firstName.label') . '</td><td>'; if ($cloneUser->getFirstName() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getFirstName(); } $msg .= '</td><td>'; if ($user->getFirstName() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getFirstName(); } $msg .= '</td></tr>'; } if ($cloneUser->getLastName() != $user->getLastName()) { $msg .= '<tr><td>' . $this->translate('User.lastName.label') . '</td><td>'; if ($cloneUser->getLastName() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getLastName(); } $msg .= '</td><td>'; if ($user->getUsername() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getLastName(); } $msg .= '</td></tr>'; } if ($cloneUser->getBirthday() != $user->getBirthday()) { $msg .= '<tr><td>' . $this->translate('User.birthday.label') . '</td><td>'; if ($cloneUser->getBirthday() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getBirthday()->format('Y-m-d'); } $msg .= '</td><td>'; if ($user->getBirthday() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getBirthday()->format('Y-m-d'); } $msg .= '</td></tr>'; } if ($cloneUser->getStreetNum() != $user->getStreetNum()) { $msg .= '<tr><td>' . $this->translate('User.streetNum.label') . '</td><td>'; if ($cloneUser->getStreetNum() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getStreetNum(); } $msg .= '</td><td>'; if ($user->getStreetNum() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getStreetNum(); } $msg .= '</td></tr>'; } if ($cloneUser->getAddress() != $user->getAddress()) { $msg .= '<tr><td>' . $this->translate('User.address.label') . '</td><td>'; if ($cloneUser->getAddress() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getAddress(); } $msg .= '</td><td>'; if ($user->getAddress() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getAddress(); } $msg .= '</td></tr>'; } if ($cloneUser->getAddress2() != $user->getAddress2()) { $msg .= '<tr><td>' . $this->translate('User.address2.label') . '</td><td>'; if ($cloneUser->getAddress2() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getAddress2(); } $msg .= '</td><td>'; if ($user->getAddress2() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getAddress2(); } $msg .= '</td></tr>'; } if ($cloneUser->getTown() != $user->getTown()) { $msg .= '<tr><td>' . $this->translate('User.town.label') . '</td><td>'; if ($cloneUser->getTown() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getTown(); } $msg .= '</td><td>'; if ($user->getTown() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getTown(); } $msg .= '</td></tr>'; } if ($cloneUser->getZipCode() != $user->getZipCode()) { $msg .= '<tr><td>' . $this->translate('User.zipCode.label') . '</td><td>'; if ($cloneUser->getZipCode() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getZipCode(); } $msg .= '</td><td>'; if ($user->getZipCode() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getZipCode(); } $msg .= '</td></tr>'; } if ($cloneUser->getCountry() != $user->getCountry()) { $msg .= '<tr><td>' . $this->translate('User.country.label') . '</td><td>'; if ($cloneUser->getCountry() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getCountry(); } $msg .= '</td><td>'; if ($user->getCountry() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getCountry(); } $msg .= '</td></tr>'; } if ($cloneUser->getPhone() != $user->getPhone()) { $msg .= '<tr><td>' . $this->translate('User.phone.label') . '</td><td>'; if ($cloneUser->getPhone() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getPhone(); } $msg .= '</td><td>'; if ($user->getPhone() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getPhone(); } $msg .= '</td></tr>'; } if ($cloneUser->getMobile() != $user->getMobile()) { $msg .= '<tr><td>' . $this->translate('User.mobile.label') . '</td><td>'; if ($cloneUser->getMobile() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getMobile(); } $msg .= '</td><td>'; if ($user->getMobile() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getMobile(); } $msg .= '</td></tr>'; } if ($cloneUser->getPreferedLang() != $user->getPreferedLang()) { $msg .= '<tr><td>' . $this->translate('User.preferedLang.label') . '</td><td>'; if ($cloneUser->getPreferedLang() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getPreferedLang()->getName(); } $msg .= '</td><td>'; if ($user->getPreferedLang() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getPreferedLang()->getName(); } $msg .= '</td></tr>'; } if ($cloneUser->getEmail() != $user->getEmail()) { $msg .= '<tr><td>' . $this->translate('User.email.label') . '</td><td>'; if ($cloneUser->getEmail() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $cloneUser->getEmail(); } $msg .= '</td><td>'; if ($user->getEmail() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $user->getEmail(); } $msg .= '</td></tr>'; } if ($cloneUser->getLockout() != $user->getLockout()) { $msg .= '<tr><td>' . $this->translate('User.sexe.label') . '</td><td>'; if ($cloneUser->getLockout() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $this->translate('User.lockout.' . $cloneUser->getLockout()); } $msg .= '</td><td>'; if ($user->getLockout() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= $this->translate('User.lockout.' . $user->getLockout()); } $msg .= '</td></tr>'; } if ($cloneUser->getClearPassword() != $user->getClearPassword()) { $msg .= '<tr><td>' . $this->translate('User.password.label') . '</td><td>'; for ($i = 0; $i < \strlen($cloneUser->getClearPassword()); $i++) { $msg .= '*'; } $msg .= '</td><td>'; for ($i = 0; $i < \strlen($user->getClearPassword()); $i++) { $msg .= '*'; } $msg .= '</td></tr>'; } if ($cloneUser->getAvatar() != $user->getAvatar()) { $msg .= '<tr><td>' . $this->translate('User.avatar.label') . '</td><td>'; if ($cloneUser->getAvatar() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<img class="img-responsive img-thumbnail" alt="" src="/res/avatars/' . $cloneUser->getAvatar() . '">'; } $msg .= '</td><td>'; if ($user->getAvatar() == null) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<img class="img-responsive img-thumbnail" alt="" src="/res/avatars/' . $user->getAvatar() . '">'; } $msg .= '</td></tr>'; } if (\count(\array_diff($user->getUserRoles()->toArray(), $cloneUser->getUserRoles()->toArray())) != 0 || \count(\array_diff($cloneUser->getUserRoles()->toArray(), $user->getUserRoles()->toArray())) != 0) { $msg .= '<tr><td>' . $this->translate('User.userRoles.label') . '</td><td>'; if (\count($cloneUser->getUserRoles()) == 0) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<ul>'; foreach ($cloneUser->getUserRoles() as $role) { $msg .= '<li>' . $role->getName() . '</li>'; } $msg .= '<ul>'; } $msg .= '</td><td>'; if (\count($user->getUserRoles()) == 0) { $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>'; } else { $msg .= '<ul>'; foreach ($user->getUserRoles() as $role) { $msg .= '<li>' . $role->getName() . '</li>'; } $msg .= '<ul>'; } $msg .= '</td></tr>'; } if ($msg != '') { $msg = $tableBegin . $msg . $tableEnd; $trace->setMsg($this->translate('User.traceEdit', array('%user%' => $user->getFullName())) . $msg); $trace->setDtCrea(new \DateTime('now')); $em = $this->getEntityManager(); $em->persist($trace); $em->flush(); } }
/** * Add user * * @param User $user * * @return Role $this */ public function addUser(User $user) { $this->users[] = $user; $user->addUserRole($this); return $this; }
/** * genNewPassword Action * * @param guid $id * @param string $code * * @return RedirectResponse|Response */ public function genNewPasswordAction($id, $code) { if ($this->hasRole('IS_AUTHENTICATED_FULLY')) { return $this->redirect($this->generateUrl('_security_profile')); } $em = $this->getEntityManager(); try { $user = null; $user = $em->getRepository('AcfDataBundle:User')->find($id); if (null != $user) { $now = new \DateTime('now'); if (null == $user->getRecoveryExpiration() || $user->getRecoveryExpiration() < $now) { $this->flashMsgSession('error', $this->translate('_security.genNewPassword.errorparams2')); } elseif ($user->getRecoveryCode() != $code) { $this->flashMsgSession('error', $this->translate('_security.genNewPassword.errorparams3')); } else { $user->setSalt(md5(uniqid(null, true))); $user->setClearPassword(User::generateRandomChar(8, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')); $user->setRecoveryExpiration(null); $user->setRecoveryCode(null); $em->persist($user); $em->flush(); $mvars = array(); $mvars['user'] = $user; $from = $this->getParameter('mail_from'); $fromName = $this->getParameter('mail_from_name'); $subject = $this->translate('_mail.genNewPassword.subject', array(), 'messages'); $message = \Swift_Message::newInstance(); $message->setFrom($from, $fromName); $message->setTo($user->getEmail(), $user->getFullname()); $message->setSubject($subject); $mvars['logo'] = $message->embed(\Swift_Image::fromPath($this->getParameter('kernel.root_dir') . '/../web/bundles/acfres/images/logo_acf.jpg')); $message->setBody($this->renderView('AcfSecurityBundle:Mail:genNewPassword.html.twig', $mvars), 'text/html'); $this->sendmail($message); $this->flashMsgSession('success', $this->translate('_security.genNewPassword.ok')); } } else { $this->flashMsgSession('error', $this->translate('_security.genNewPassword.errorparams1')); } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->error($e->getMessage()); $this->flashMsgSession('error', $this->translate('_security.genNewPassword.errorparams4')); } return $this->redirect($this->generateUrl('_security_login')); }