public function project($event) { $userDocument = new User(); $userDocument->setId("{$event->userId()}"); $userDocument->setPoints(0); $this->manager->persist($userDocument); $this->manager->commit(); }
/** * @return SenderInterface */ private function getSenderForUser(User $user) { if ($user->getNotificateVia() === User::NOTIFICATION_VIA_EMAIL) { return $this->mailSender; } elseif ($user->getNotificateVia() === User::NOTIFICATION_VIA_TELEGRAM) { return $this->telegramSender; } throw new \LogicException('Неизвестный способ оповещения'); }
public function sendNotification(User $user, $text, $subject) { $message = $this->swiftMailer->createMessage(); $message->setBody($text); $message->setCharset('utf-8'); $message->addFrom($this->fromEmail, $this->fromEmailSender); $message->addTo($user->getEmail()); $message->setSubject($subject); $message->setContentType('text/html'); $this->swiftMailer->send($message); $this->logger->info('Отправлено письмо пользователю ' . $user->getEmail(), ['text' => $text, 'subject' => $subject]); }
public function load(DocumentManager $manager) { $userAdmin = new User(); $userAdmin->setUsername('admin'); $userAdmin->setSalt(md5(uniqid())); $plainPassword = '******'; $encoder = $this->container->get('security.password_encoder'); $password = $encoder->encodePassword($userAdmin, $plainPassword); $userAdmin->setPassword($password); $userAdmin->setRoles(array("ROLE_ADMIN")); $manager->persist($userAdmin); $manager->flush(); }
private function unsubscribeNewShows($siteKey) { if (!isset($this->sites[$siteKey])) { return 'Сайт не найден'; } if (!$this->user->isSubscribedNewShows($siteKey)) { return 'Вы не подписаны на новые сериалы на этом сайте'; } else { $this->user->removeSubscribedNewShowsOnSite($siteKey); $this->dm->flush(); return 'Вы отписались от уведомлений о новых сериалах'; } }
/** * @Post("/register") * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function registerAction(Request $request) { $email = $request->request->get('email'); $password = $request->request->get('password'); $creditCard = ['name' => $request->request->get('cc-name'), 'number' => $request->request->get('cc-number'), 'cvc' => $request->request->get('cc-cvc'), 'month' => $request->request->get('cc-month'), 'year' => $request->request->get('cc-year')]; if (!$email || !$password) { throw new \Symfony\Component\Validator\Exception\InvalidArgumentException('Email and password required'); } if (!$this->get('credit_card_validator')->validate($creditCard)) { throw new \Symfony\Component\Validator\Exception\InvalidArgumentException('Invalid Credit Card given'); } $dm = $this->get('doctrine.odm.mongodb.document_manager'); $user = $dm->getRepository('AppBundle:User')->findOneBy(['email' => $email]); if ($user) { throw new \Symfony\Component\Validator\Exception\InvalidArgumentException('User already exists'); } $user = new User(); $user->setEmail($email); $user->setPassword($password); $user->setCreditCard($creditCard); $dm->persist($user); $dm->flush(); return true; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $users = array(1 => array('name' => 'John Doe', 'email' => '*****@*****.**', 'friends' => array(), 'requests' => array()), 2 => array('name' => 'Sara Doe', 'email' => '*****@*****.**', 'friends' => array(), 'requests' => array(1)), 3 => array('name' => 'James Doe', 'email' => '*****@*****.**', 'friends' => array(), 'requests' => array(1, 2)), 4 => array('name' => 'Jane Smith', 'email' => '*****@*****.**', 'friends' => array(), 'requests' => array(3)), 5 => array('name' => 'Anonymous', 'email' => '*****@*****.**', 'friends' => array(), 'requests' => array(4))); foreach ($users as $id => $userData) { $user = new User(); $user->setName($userData['name']); $user->setEmail($userData['email']); foreach ($userData['friends'] as $friendId) { $user->addFriend($this->getReference('user_' . $friendId)); } foreach ($userData['requests'] as $requestId) { $user->addRequest($this->getReference('user_' . $requestId)); } $manager->persist($user); $this->addReference('user_' . $id, $user); } $manager->flush(); }
/** * @param UserDocument $friend * @param integer $n * * @return array */ public function getFriendsFriends($friend, $n) { if ($n > 0) { $friendsFriends = $friend->getFriends(); foreach ($friendsFriends as $friendsFriend) { $this->friendsFriends[] = $friendsFriend->getEmail(); $this->getFriendsFriends($friendsFriend, $n - 1); } } return array_unique($this->friendsFriends); }
/** * Creates a new user document and persist it * @param ObjectManager $manager object manager * @param string|null $email email to create user with * @return User */ private function _createUser(ObjectManager $manager, $email = null) { $user = new User(); $email = $email ?: sprintf('*****@*****.**', uniqid()); $user->setEmail($email); $user->setPassword(self::TEST_PASS); $encoder = $this->_container->get('security.password_encoder'); $encryptedPassword = $encoder->encodePassword($user, self::TEST_PASS); $user->setPassword($encryptedPassword); $manager->persist($user); return $user; }
public function sendNotification(User $user, $text, $subject) { $this->botApi->sendMessage($user->getTelegramId(), $text); $this->logger->info('Отправлено сообщение telegram пользователю ' . $user->getEmail(), ['text' => $text]); }
/** * Route to add friends (which also accepts friend requests) * * @param User $friend User to link current user with * * @return null * * @ApiDoc( * resource=false, * description="Creates a friendship request of current user to desired one", * statusCodes={ * 401 = "Unauthorized - log in first", * 204 = "Successfully requested", * 409 = "User already added as friend" * } * ) * @Annotations\Link(requirements={"friend"="\w{24}"}) */ public function linkAction(User $friend) { $currentUser = $this->getUser(); if (!$currentUser instanceof User) { throw new UnauthorizedHttpException('Probably you are not authorized'); } $currentUserId = $currentUser->getId(); $friendId = $friend->getId(); if ($currentUser->hasFriend($friendId)) { $conflictMessage = sprintf('user %s is already your friend', $friendId); throw new ConflictHttpException($conflictMessage); } // Add a friend (subscription) and make friendship request $currentUser->addFriend($friendId); $friend->addRequest($currentUserId); // Accept removes request if exists any $currentUser->removeRequest($friendId); // Persist changes to DB $documentManager = $this->get('doctrine.odm.mongodb.document_manager'); $documentManager->flush(); }
private function firstLogin($inputData) { // Initiate curl $ch = curl_init(); // Disable SSL verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Will return the response, if false it print the response curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, AndroidGrantExtension::FACEBOOK_API_URL . 'access_token=' . $inputData['facebook_token']); $me = json_decode(curl_exec($ch)); if (isset($me->error)) { throw new OAuth2ServerException(OAuth2::HTTP_BAD_REQUEST, OAuth2::ERROR_INVALID_REQUEST, 'Invalid Facebook OAuth access token'); } if ($inputData['facebook_id'] != $me->id) { throw new OAuth2ServerException(OAuth2::HTTP_BAD_REQUEST, OAuth2::ERROR_INVALID_REQUEST, 'Facebook OAuth access token don\'t match facebook_id'); } $user = $this->repository->findOneBy(array('facebookId' => $me->id)); if ($user === null) { $user = new User(); $user->setFacebookId($me->id); $user->setFirstName($me->first_name); $user->setLastName($me->last_name); $user->setGender($me->gender); if (!empty($me->birthday)) { $exploded = explode('/', $me->birthday); $date = new \DateTime(); $date->setDate($exploded[2], $exploded[0], $exploded[1]); $user->setBirthday($date); } if (!empty($me->hometown)) { $user->setHometown($me->hometown->name); } $user->setEmail($me->email); $user->setUsername('guest-' . substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 6)); $user->setAutoUsername(true); $user->setPlainPassword(substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 7)); $user->setAutoPassword(true); $user->setEnabled(true); $this->om->persist($user); $this->om->flush(); } return array('data' => $user); }
/** * @param User $user * @param $date * @param $lineNumber * @param $from * @param $to * @param $lineDeparture * @param int $continuation * @return Ticket|null */ public function buyTicket(User $user, $date, $lineNumber, $from, $to, $lineDeparture, $continuation = 0) { // Get Trip $trip = $this->documentManager->getRepository('AppBundle:Trip')->findOneBy(['date' => $date, 'lineNumber' => (int) $lineNumber, 'departure' => (int) $lineDeparture]); // If doesn't exists if (!$trip) { // Check lineNumber | from | to | lineDeparture if (!($line = $this->trainInformation->verifyLine($lineNumber, $from, $to, $lineDeparture))) { throw new BadRequestHttpException('Invalid trip.'); } // Create Trip $trip = new Trip($lineNumber, $line['stations'], $date, $lineDeparture, $this->trainInformation->getCapacity()); } // Get Train capacity if ($trip->getAvailableCapacity($from, $to) == 0) { throw new BadRequestHttpException('Trip is full.'); } if ($continuation == 1 && !$this->creditCardValidator->validate($user->getCreditCard())) { throw new BadRequestHttpException('Credit Card failed.'); } // Create Ticket $ticket = new Ticket($user, $trip, $from, $to); // Update Trip $trip->addTicketBought($from, $to); // Persist $this->documentManager->persist($ticket); $this->documentManager->persist($trip); $this->documentManager->flush(); return $ticket; }
/** * @param User $friend * * @return bool */ public function isFriend($friend) { /* @var User $userFriend */ foreach ($this->getFriends() as $userFriend) { if ($userFriend->getId() == $friend->getId()) { return true; } } return false; }