public function testUnsubscribeTokenEncryptDecrypt()
 {
     $uid = 26;
     $u = new User();
     $u->setId($uid);
     $token = CryptUtility::getUnsubscribeToken($u, UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES, $this->key);
     $details = CryptUtility::decryptUnsubscibeToken($token, $this->key);
     $this->assertEquals($uid, $details['userId']);
     $this->assertEquals(UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES, $details['prefId']);
 }
 public function testTemplatesAreBeingRendered()
 {
     $t = $this->container->get('templating');
     $u = new User();
     $u->setName('Dummy User');
     $u->setEmail('*****@*****.**');
     $courses = array();
     $course = array('id' => 5, 'name' => 'Dummy Course', 'shortDesc' => 'Dummy Course', 'initiative' => array('name' => 'Independent', 'code' => 'Independent'), 'slug' => 'fake_slug', 'nextOffering' => array('displayDate' => '2014-05-05', 'url' => 'http://example.com'), 'institutions' => array());
     $courses[] = array('interested' => false, 'id' => 5, 'course' => $course);
     $counts = array('offeringCount' => array('recent' => '50', 'selfpaced' => '100'));
     $html = $t->renderResponse('ClassCentralMOOCTrackerBundle:Reminder:multiple.courses.inlined.html', array('courses' => $courses, 'baseUrl' => $this->container->getParameter('baseurl'), 'user' => $u, 'jobType' => CourseStartReminderJob::JOB_TYPE_1_DAY_BEFORE, 'counts' => $counts, 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($u, UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES, $this->container->getParameter('secret'))))->getContent();
     $this->assertNotEmpty($html);
     $html = $t->renderResponse('ClassCentralMOOCTrackerBundle:Reminder:single.course.inlined.html', array('course' => $course, 'baseUrl' => $this->container->getParameter('baseurl'), 'interested' => false, 'user' => $u, 'counts' => $counts, 'jobType' => CourseStartReminderJob::JOB_TYPE_1_DAY_BEFORE, 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($u, UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES, $this->container->getParameter('secret'))))->getContent();
     $this->assertNotEmpty($html);
 }
 /**
  * Must return an object of type SchedulerJobStatus
  * @param $args
  * @return SchedulerJobStatus
  */
 public function perform($args)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $userId = $this->getJob()->getUserId();
     $user = $em->getRepository('ClassCentralSiteBundle:User')->findOneBy(array('id' => $userId));
     $cache = $this->getContainer()->get('cache');
     // Get counts for self paced and recently started courses
     $navController = new NavigationController();
     $counts = $navController->getNavigationCounts($this->getContainer());
     $rs = $this->getContainer()->get('review');
     /**
      * Send notifications only for user courses
      */
     if (isset($args[UserCourse::LIST_TYPE_INTERESTED])) {
         $courseIds = $args[UserCourse::LIST_TYPE_INTERESTED];
         $numCourses = count($courseIds);
         if ($numCourses == 1) {
             $courseId = $courseIds[0];
             $course = $em->getRepository('ClassCentralSiteBundle:Course')->find($courseId);
             $subject = $course->getName() . ' - New session added';
         } else {
             // Multiple courses
             $subject = "Course Notification: New sessions added for {$numCourses} courses";
         }
         // Build a list of courses for which notifications are being sent for
         $courses = array();
         foreach ($courseIds as $cid) {
             $course = $em->getRepository('ClassCentralSiteBundle:Course')->find($cid);
             $courseArray = $em->getRepository('ClassCentralSiteBundle:Course')->getCourseArray($course);
             $courseArray['rating'] = $rs->getRatings($course->getId());
             $courseArray['ratingStars'] = ReviewUtility::getRatingStars($courseArray['rating']);
             $rArray = $rs->getReviewsArray($course->getId());
             $courseArray['reviewsCount'] = $rArray['count'];
             $courses[] = array('interested' => true, 'id' => $cid, 'course' => $courseArray);
         }
         $templating = $this->getContainer()->get('templating');
         $html = $templating->renderResponse('ClassCentralMOOCTrackerBundle:NewSession:newSession.inlined.html', array('results' => $courses, 'baseUrl' => $this->getContainer()->getParameter('baseurl'), 'user' => $user, 'loginToken' => $this->getContainer()->get('user_service')->getLoginToken($user), 'numCourses' => $numCourses, 'showDesc' => $numCourses <= 10, 'coursesHidden' => $numCourses > 40, 'counts' => $counts, 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($user, UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES, $this->getContainer()->getParameter('secret')), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => 'mt_new_sessions_reminder', 'source' => Mailgun::UTM_SOURCE_PRODUCT)))->getContent();
         $campaignId = self::MAILGUN_MT_NEW_SESSION;
         return $this->sendEmail($subject, $html, $user, $campaignId, $numCourses);
     } else {
         // Don't send an email
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, "No courses found for user {$userId}");
     }
 }
 /**
  * Build out the html
  * @param User $user
  * @param $template
  * @param $campaignId
  * @return mixed
  */
 private function getAnnouncementHTML(User $user, $template, $campaignId)
 {
     $templating = $this->getContainer()->get('templating');
     $html = $templating->renderResponse('ClassCentralMOOCTrackerBundle:Announcement:' . $template, array('user' => $user, 'loginToken' => $this->getContainer()->get('user_service')->getLoginToken($user), 'baseUrl' => $this->getContainer()->getParameter('baseurl'), 'jobType' => $this->getJob()->getJobType(), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => $campaignId, 'source' => Mailgun::UTM_SOURCE_PRODUCT), 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($user, UserPreference::USER_PREFERENCE_FOLLOW_UP_EMAILs, $this->getContainer()->getParameter('secret'))))->getContent();
     return $html;
 }
Пример #5
0
 /**
  * Updates the subscription for the user encoded in the token
  * @param $token
  * @param $subValue
  */
 private function updateSubscriptionFromToken($token, $subValue)
 {
     $em = $this->getDoctrine()->getManager();
     $userService = $this->get('user_service');
     $details = CryptUtility::decryptUnsubscibeToken($token, $this->container->getParameter('secret'));
     $user = $em->getRepository('ClassCentralSiteBundle:User')->find($details['userId']);
     $prefId = $details['prefId'];
     // Unsubscribe the user
     $userService->updatePreference($user, $prefId, $subValue);
     return $prefId;
 }
 private function getMultipleCouresEmail($courses, User $user, $counts)
 {
     $templating = $this->getContainer()->get('templating');
     $html = $templating->renderResponse('ClassCentralMOOCTrackerBundle:Reminder:multiple.courses.inlined.html', array('courses' => $courses, 'baseUrl' => $this->getContainer()->getParameter('baseurl'), 'user' => $user, 'jobType' => $this->getJob()->getJobType(), 'loginToken' => $this->getContainer()->get('user_service')->getLoginToken($user), 'counts' => $counts, 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($user, UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES, $this->getContainer()->getParameter('secret')), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => 'mt_course_start_reminder', 'source' => Mailgun::UTM_SOURCE_PRODUCT)))->getContent();
     return $html;
 }
 public function getHTML(UserEntity $user, $courses, $campaignId)
 {
     $templating = $this->getContainer()->get('templating');
     $html = $templating->renderResponse('ClassCentralMOOCTrackerBundle:NewCourses:newcourses.inlined.html', array('user' => $user, 'courses' => $courses, 'recommendationsPageUnlocked' => count($user->getFollows()) >= 10, 'loginToken' => $this->getContainer()->get('user_service')->getLoginToken($user), 'baseUrl' => $this->getContainer()->getParameter('baseurl'), 'jobType' => $this->getJob()->getJobType(), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => $campaignId, 'source' => Mailgun::UTM_SOURCE_PRODUCT), 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($user, UserPreference::USER_PREFERENCE_PERSONALIZED_COURSE_RECOMMENDATIONS, $this->getContainer()->getParameter('secret'))))->getContent();
     return $html;
 }
Пример #8
0
 /**
  * Must return an object of type SchedulerJobStatus
  * @param $args
  * @return SchedulerJobStatus
  */
 public function perform($args)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $userId = $this->getJob()->getUserId();
     $user = $em->getRepository('ClassCentralSiteBundle:User')->findOneBy(array('id' => $userId));
     $cache = $this->getContainer()->get('cache');
     $jobType = $this->getJob()->getJobType();
     $esCourses = $this->getContainer()->get('es_courses');
     if (!$user) {
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, "User with id {$userId} not found");
     }
     // Sets a campaign id
     $campaignId = '';
     // Get all the search terms for the user
     $searchTerms = $this->getSearchTerms($user);
     $session = array();
     $session[] = 'upcoming';
     if ($jobType == self::JOB_TYPE_NEW_COURSES) {
         // upcoming, recentlyAdded
         $session[] = 'recentlyadded';
         // Lowercase because of how elastic search tokenizes it
         $campaignId = self::MAILGUN_MT_SEARCH_NEW_COURSES;
     } elseif ($jobType == self::JOB_TYPE_RECENT_COURSES) {
         // recent, upcoming
         $session[] = 'recent';
         $campaignId = self::MAILGUN_MT_SEARCH_RECENT_COURSES;
     }
     $courses = array();
     $count = 0;
     foreach ($searchTerms as $q) {
         $results = $esCourses->search($q, $session);
         $total = $results['results']['hits']['total'];
         if ($total > 0) {
             $c = array();
             foreach ($results['results']['hits']['hits'] as $result) {
                 $c[] = $result['_source'];
             }
             $courses[] = array('query' => $q, 'courses' => $c, 'count' => $total);
             $count += $total;
         }
     }
     if ($count == 0) {
         // No need to send an email
         return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "No courses for User with id {$userId} were found for job {$jobType}");
     }
     $coursesText = 'courses';
     if ($count == 1) {
         $coursesText = 'course';
     }
     // Courses found. Get the template and send the email
     if ($jobType == self::JOB_TYPE_NEW_COURSES) {
         $subject = "Search Notification: {$count} new {$coursesText} found";
     } elseif ($jobType == self::JOB_TYPE_RECENT_COURSES) {
         $subject = "Search Notification: {$count} {$coursesText} starting soon";
     }
     $templating = $this->getContainer()->get('templating');
     $html = $templating->renderResponse('ClassCentralMOOCTrackerBundle:Search:search.inlined.html', array('results' => $courses, 'baseUrl' => $this->getContainer()->getParameter('baseurl'), 'user' => $user, 'jobType' => $jobType, 'numCourses' => $count, 'loginToken' => $this->getContainer()->get('user_service')->getLoginToken($user), 'showDesc' => $count <= 10, 'coursesHidden' => $count > 40, 'counts' => $this->getCounts(), 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($user, UserPreference::USER_PREFERENCE_MOOC_TRACKER_SEARCH_TERM, $this->getContainer()->getParameter('secret')), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => 'mt_search_notification', 'source' => Mailgun::UTM_SOURCE_PRODUCT)))->getContent();
     return $this->sendEmail($subject, $html, $user, $campaignId, $count);
 }
 private function getFollowUpEmail(User $user, $courses, $reviews)
 {
     $templating = $this->getContainer()->get('templating');
     $html = $templating->renderResponse('ClassCentralMOOCTrackerBundle:User:newuser.followup.inlined.html', array('user' => $user, 'loginToken' => $this->getContainer()->get('user_service')->getLoginToken($user), 'baseUrl' => $this->getContainer()->getParameter('baseurl'), 'jobType' => $this->getJob()->getJobType(), 'courses' => $courses, 'reviews' => $reviews, 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => 'new_user_followup', 'source' => Mailgun::UTM_SOURCE_PRODUCT), 'unsubscribeToken' => CryptUtility::getUnsubscribeToken($user, UserPreference::USER_PREFERENCE_FOLLOW_UP_EMAILs, $this->getContainer()->getParameter('secret'))))->getContent();
     return $html;
 }