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']);
 }
Пример #2
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;
 }