/** * Get authenticated user * * @param string $role Role * * @return mixed User for authentication */ public function getAuthenticationUser($role) { return 'ROLE_ADMIN' === $role ? $this->adminUserRepository->findOneBy(['email' => '*****@*****.**']) : $this->customerRepository->find(['email' => '*****@*****.**']); }
/** * Adds a user into de referral program table, given the Referrer Customer, * the invited email and the invited Name * * If current email is currently inserted in the table with enabled flag and * purgeInvalidLines is also set as true, Line will not be inserted. * * @param ReferralRuleInterface $referralRule ReferralRule * @param CustomerInterface $referrer Referrer * @param InvitationInterface $invitation Invitation * * @throws ReferralProgramEmailIsUserException * @throws ReferralProgramLineExistsException * * @return $this self Object */ protected function inviteLine(ReferralRuleInterface $referralRule, CustomerInterface $referrer, InvitationInterface $invitation) { $referralHash = $this->referralHashManager->getReferralHashByCustomer($referrer); /** * If purgeInvalidLines is enabled, we try to find if any ReferralLine * is enabled. If it is, we skip this email. */ if ($this->purgeDisabledLines) { $enabledReferralLine = $this->referralLineRepository->findOneBy(array('enabled' => true, 'invitedEmail' => $invitation->getEmail())); if ($enabledReferralLine instanceof ReferralLineInterface) { return $this; } } /** * @var ReferralLine $referralLine */ $referralLine = $this->referralLineRepository->findOneBy(array('invitedEmail' => $invitation->getEmail(), 'referralHash' => $referralHash)); if ($referralLine instanceof ReferralLine) { throw new ReferralProgramLineExistsException(); } /** @var $customer Customer */ $customer = $this->customerRepository->findOneByEmail($invitation->getEmail()); if ($customer instanceof Customer) { throw new ReferralProgramEmailIsUserException(); } /** * New referral line */ $referralLine = $this->referralLineFactory->create(); $referralLine->setReferralHash($referralHash)->setInvitedEmail($invitation->getEmail())->setInvitedName($invitation->getName())->setSource($invitation->getSource())->setReferralRule($referralRule)->setReferrerType($referralRule->getReferrerType())->setReferrerCoupon($referralRule->getReferrerCoupon())->setInvitedType($referralRule->getInvitedType())->setInvitedCoupon($referralRule->getInvitedCoupon()); /** * Persists and flushes new entity */ $this->manager->persist($referralLine); $this->manager->flush($referralLine); $referralLink = $this->referralRouteManager->generateControllerRoute($referralHash); /** * Invitation done event is raised */ $event = new ReferralProgramInvitationEvent($referralLine, $referralLink); $this->eventDispatcher->dispatch(ElcodiReferralProgramEvents::REFERRAL_PROGRAM_INVITATION, $event); return $this; }