function stopWatchingFromEmail($userid, $code, Request $request, Application $app) { $userRepo = new UserAccountRepository(); $user = $userRepo->loadByID($userid); if (!$user) { $app['monolog']->addError("Failed stop watching site from email - user not known"); die("NO"); // TODO } $userWatchesSiteStopRepo = new UserWatchesSiteStopRepository(); $userWatchesSiteStop = $userWatchesSiteStopRepo->loadByUserAccountIDAndSiteIDAndAccessKey($user->getId(), $app['currentSite']->getId(), $code); if (!$userWatchesSiteStop) { $app['monolog']->addError("Failed stop watching site from email - user " . $user->getId() . " - code wrong"); die("NO"); // TODO } $userWatchesSiteRepo = new UserWatchesSiteRepository(); $userWatchesSite = $userWatchesSiteRepo->loadByUserAndSite($user, $app['currentSite']); if (!$userWatchesSite || !$userWatchesSite->getIsWatching()) { $app['monolog']->addError("Failed stop watching site from email - user " . $user->getId() . " - not watching"); die("You don't watch this site"); // TODO } if ($request->request->get('action') == 'unwatch' && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $userWatchesSiteRepo->stopUserWatchingSite($user, $app['currentSite']); // redirect here because if we didn't the twig global and $app vars would be wrong (the old state) // this is an easy way to get round that. $app['flashmessages']->addMessage("You have stopped watching this."); return $app->redirect('/'); } return $app['twig']->render('site/index/stopWatchingFromEmail.html.twig', array('user' => $user)); }
protected function build($siteid, $slug, Request $request, Application $app) { $this->parameters = array('user' => null, 'eventCreated' => null, 'eventDupe' => null); $sr = new SiteRepository(); $this->parameters['site'] = $sr->loadById($siteid); if (!$this->parameters['site']) { $app->abort(404); } $repo = new NewEventDraftRepository(); $this->parameters['draft'] = $repo->loadBySlugForSite($slug, $this->parameters['site']); if (!$this->parameters['draft']) { $app->abort(404); } if ($this->parameters['draft']->getUserAccountId()) { $ur = new UserAccountRepository(); $this->parameters['user'] = $ur->loadByID($this->parameters['draft']->getUserAccountId()); } if ($this->parameters['draft']->getEventId()) { $er = new EventRepository(); $this->parameters['eventCreated'] = $er->loadByID($this->parameters['draft']->getEventId()); } if ($this->parameters['draft']->getWasExistingEventId()) { $er = new EventRepository(); $this->parameters['eventDupe'] = $er->loadByID($this->parameters['draft']->getWasExistingEventId()); } }
protected function build($id, Request $request, Application $app) { $this->parameters = array('user' => null); $csr = new ContactSupportRepository(); $this->parameters['contactsupport'] = $csr->loadById($id); if (!$this->parameters['contactsupport']) { $app->abort(404); } if ($this->parameters['contactsupport']->getUserAccountId()) { $ur = new UserAccountRepository(); $this->parameters['user'] = $ur->loadByID($this->parameters['contactsupport']->getUserAccountId()); } }
function test1() { $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $this->checkUserInTest1($userRepo->loadByID($user->getId())); $this->checkUserInTest1($userRepo->loadByUserName("test")); $this->checkUserInTest1($userRepo->loadByEmail("*****@*****.**")); $this->checkUserInTest1($userRepo->loadByUserNameOrEmail("test")); $this->checkUserInTest1($userRepo->loadByUserNameOrEmail("*****@*****.**")); }
function listUsersNotEditors(Application $app, Request $request) { $repo = new UserHasNoEditorPermissionsInSiteRepository(); if ($request->request->get('action') == "add" && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $ur = new UserAccountRepository(); $user = $ur->loadByUserName($request->request->get('username')); if ($user) { $repo->addUserToSite($user, $app['currentSite'], $app['currentUser']); return $app->redirect('/admin/usernoteditor/'); } } else { if ($request->request->get('action') == "remove" && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $ur = new UserAccountRepository(); $user = $ur->loadByID($request->request->get('id')); if ($user) { $repo->removeUserFromSite($user, $app['currentSite'], $app['currentUser']); return $app->redirect('/admin/usernoteditor/'); } } } $userAccountRepoBuilder = new UserAccountRepositoryBuilder(); $userAccountRepoBuilder->setUserHasNoEditorPermissionsInSite($app['currentSite']); return $app['twig']->render('site/admin/listUsersNotEditors.html.twig', array('users' => $userAccountRepoBuilder->fetchAll())); }
public static function run(Application $app, $verbose = false) { global $CONFIG; if ($verbose) { print "Starting " . date("c") . "\n"; } $userRepo = new UserAccountRepository(); $siteRepo = new SiteRepository(); $groupRepo = new GroupRepository(); $eventRepo = new EventRepository(); $userWatchesGroupRepository = new UserWatchesGroupRepository(); $userWatchesGroupStopRepository = new UserWatchesGroupStopRepository(); $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository(); $userNotificationRepo = new UserNotificationRepository(); $userHasNoEditorPermissionsInSiteRepo = new UserHasNoEditorPermissionsInSiteRepository(); $userPermissionsRepo = new UserPermissionsRepository($app['extensions']); /** @var usernotifications/UserWatchesGroupPromptNotificationType **/ $userNotificationType = $app['extensions']->getCoreExtension()->getUserNotificationType('UserWatchesGroupPrompt'); $b = new UserWatchesGroupRepositoryBuilder(); foreach ($b->fetchAll() as $userWatchesGroup) { $user = $userRepo->loadByID($userWatchesGroup->getUserAccountId()); $group = $groupRepo->loadById($userWatchesGroup->getGroupId()); $site = $siteRepo->loadById($group->getSiteID()); // This is not the most efficient as it involves DB access and the results might not be used. But it'll do for now. $userPermissions = $userPermissionsRepo->getPermissionsForUserInSite($user, $site, false, true); if ($verbose) { print date("c") . " User " . $user->getEmail() . " Site " . $site->getTitle() . " Group " . $group->getTitle() . "\n"; } // UserWatchesGroupRepositoryBuilder() should only return instances where site is not also watched if ($site->getIsClosedBySysAdmin()) { if ($verbose) { print " ... site is closed\n"; } } else { if ($group->getIsDeleted()) { if ($verbose) { print " ... group is deleted\n"; } } else { if ($userHasNoEditorPermissionsInSiteRepo->isUserInSite($user, $site)) { if ($verbose) { print " ... user does not have edit permissions allowed in site\n"; } } else { if (!$userPermissions->hasPermission("org.openacalendar", "CALENDAR_CHANGE")) { if ($verbose) { print " ... user does not have org.openacalendar/CALENDAR_CHANGE permission in site\n"; } // Technically UserWatchesSiteRepositoryBuilder() should only return getIsWatching() == true but lets double check } else { if ($userWatchesGroup->getIsWatching()) { if ($verbose) { print " ... searching for data\n"; } $lastEvent = $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId()); $data = $userWatchesGroup->getPromptEmailData($site, $lastEvent); if ($data['moreEventsNeeded']) { if ($verbose) { print " ... found data\n"; } ///// Notification Class $userNotification = $userNotificationType->getNewNotification($user, $site); $userNotification->setGroup($group); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { $userWatchesGroupStop = $userWatchesGroupStopRepository->getForUserAndGroup($user, $group); configureAppForSite($site); configureAppForUser($user); $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $unsubscribeURL = $CONFIG->getWebIndexDomainSecure() . '/you/emails/' . $user->getId() . '/' . $userAccountGeneralSecurityKey->getAccessKey(); $lastEventsBuilder = new EventRepositoryBuilder(); $lastEventsBuilder->setSite($site); $lastEventsBuilder->setGroup($group); $lastEventsBuilder->setOrderByStartAt(true); $lastEventsBuilder->setIncludeDeleted(false); $lastEventsBuilder->setIncludeImported(false); $lastEventsBuilder->setLimit($CONFIG->userWatchesGroupPromptEmailShowEvents); $lastEvents = $lastEventsBuilder->fetchAll(); $message = \Swift_Message::newInstance(); $message->setSubject("Any news about " . $group->getTitle() . "?"); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $app['twig']->render('email/userWatchesGroupPromptEmail.txt.twig', array('group' => $group, 'user' => $user, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL)); if ($CONFIG->isDebug) { file_put_contents('/tmp/userWatchesGroupPromptEmail.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/userWatchesGroupPromptEmail.html.twig', array('group' => $group, 'user' => $user, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL)); if ($CONFIG->isDebug) { file_put_contents('/tmp/userWatchesGroupPromptEmail.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); $headers = $message->getHeaders(); $headers->addTextHeader('List-Unsubscribe', $unsubscribeURL); if ($verbose) { print " ... sending\n"; } if (!$CONFIG->isDebug) { $app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } $userWatchesGroupRepository->markPromptEmailSent($userWatchesGroup, $data['checkTime']); } } } } } } } if ($verbose) { print "Finished " . date("c") . "\n"; } }
/** * DEPRECATED This should only be called once, to load into $app['currentUser']. So $USER_CURRENT & $USER_CURRENT_LOADED shouldn't be needed. * At some point in future, remove this function and put the logic into code that just writes to $app['currentUser'] only. * * @return UserAccountModel|null */ function userGetCurrent() { global $USER_CURRENT, $USER_CURRENT_LOADED, $WEBSESSION; if (!$USER_CURRENT_LOADED) { if ($WEBSESSION->has('userID') && $WEBSESSION->get('userID') > 0) { $uar = new UserAccountRepository(); $USER_CURRENT = $uar->loadByID($WEBSESSION->get('userID')); if ($USER_CURRENT && $USER_CURRENT->getIsClosedBySysAdmin()) { $USER_CURRENT = null; } } else { if (isset($_COOKIE['userID']) && isset($_COOKIE['userKey'])) { $uarmr = new UserAccountRememberMeRepository(); $uarm = $uarmr->loadByUserAccountIDAndAccessKey($_COOKIE['userID'], $_COOKIE['userKey']); if ($uarm) { $uar = new UserAccountRepository(); $USER_CURRENT = $uar->loadByID($uarm->getUserAccountId()); if ($USER_CURRENT && $USER_CURRENT->getIsClosedBySysAdmin()) { $USER_CURRENT = null; } if ($USER_CURRENT) { userLogIn($USER_CURRENT); } } } } $USER_CURRENT_LOADED = true; } return $USER_CURRENT; }
function index($siteid, $slug, Request $request, Application $app) { global $CONFIG; $this->build($siteid, $slug, $request, $app); $form = $app['form.factory']->create(new ActionForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $action = new ActionParser($data['action']); if ($action->getCommand() == 'delete' && !$this->parameters['curatedlist']->getIsDeleted()) { $clr = new CuratedListRepository(); $clr->delete($this->parameters['curatedlist'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug()); } else { if ($action->getCommand() == 'undelete' && $this->parameters['curatedlist']->getIsDeleted()) { $clr = new CuratedListRepository(); $clr->undelete($this->parameters['curatedlist'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug()); } else { if ($action->getCommand() == 'addeditor') { $userRepo = new UserAccountRepository(); $user = $userRepo->loadByID($action->getParam(0)); if ($user) { $clr = new CuratedListRepository(); $clr->addEditorToCuratedList($user, $this->parameters['curatedlist'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug()); } } else { if ($action->getCommand() == 'removeeditor') { $userRepo = new UserAccountRepository(); $user = $userRepo->loadByID($action->getParam(0)); if ($user) { $clr = new CuratedListRepository(); $clr->removeEditorFromCuratedList($user, $this->parameters['curatedlist'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/' . $this->parameters['curatedlist']->getSlug()); } } else { if ($action->getCommand() == 'addevent') { $eventRepository = new EventRepository(); $event = $eventRepository->loadBySlug($this->parameters['site'], $action->getParam(0)); if ($event) { $clr = new CuratedListRepository(); $clr->addEventtoCuratedList($event, $this->parameters['curatedlist'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $event->getSlug()); } } else { if ($action->getCommand() == 'removeevent') { $eventRepository = new EventRepository(); $event = $eventRepository->loadBySlug($this->parameters['site'], $action->getParam(0)); if ($event) { $clr = new CuratedListRepository(); $clr->removeEventFromCuratedList($event, $this->parameters['curatedlist'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/event/' . $event->getSlug()); } } else { if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeCuratedListPassword && $CONFIG->sysAdminExtraPurgeCuratedListPassword == $action->getParam(0)) { $clr = new CuratedListRepository(); $clr->purge($this->parameters['curatedlist']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/curatedlist/'); } } } } } } } } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('sysadmin/curatedlist/index.html.twig', $this->parameters); }
$apiapp = $appRepo->loadByAppTokenAndAppSecret($data['app_token'], $data['app_secret']); $app['apiAppLoadedBySecret'] = true; } else { $apiapp = $appRepo->loadByAppToken($data['app_token']); } if ($apiapp && !$apiapp->getIsClosedBySysAdmin()) { $app['apiApp'] = $apiapp; $app['userAgent']->setApi2ApplicationId($apiapp->getId()); // User Token $userTokenRepo = new API2ApplicationUserTokenRepository(); if ($data['user_token']) { $app['apiUserToken'] = $userTokenRepo->loadByAppAndUserTokenAndUserSecret($apiapp, $data['user_token'], $data['user_secret']); if ($app['apiUserToken']) { // User $userRepo = new UserAccountRepository(); $app['apiUser'] = $userRepo->loadByID($app['apiUserToken']->getUserId()); } } } // user permissons $userPermissionsRepo = new \repositories\UserPermissionsRepository($app['extensions']); // if app is not editor or token is not editor, remove edit permissions $removeEditPermissions = $app['apiApp'] && !$app['apiApp']->getIsEditor() || $app['apiUserToken'] && !$app['apiUserToken']->getIsEditor(); $app['currentUserPermissions'] = $userPermissionsRepo->getPermissionsForUserInSite($app['apiUser'], $app['currentSite'], $removeEditPermissions, true); // finally user actions $app['currentUserActions'] = new UserActionsSiteList($app['currentSite'], $app['currentUserPermissions']); }); $appUserRequired = function (Request $request) use($app) { if (!$app['apiUser']) { // TODO also if app closed die("ERROR");
protected function run() { global $CONFIG; $userRepo = new UserAccountRepository(); $siteRepo = new SiteRepository(); $eventRepo = new EventRepository(); $userWatchesSiteRepository = new UserWatchesSiteRepository(); $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository(); $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository(); $userNotificationRepo = new UserNotificationRepository(); /** @var usernotifications/UserWatchesSiteGroupPromptNotificationType **/ $userNotificationType = $this->app['extensions']->getCoreExtension()->getUserNotificationType('UserWatchesSiteGroupPrompt'); $b = new UserWatchesSiteRepositoryBuilder(); foreach ($b->fetchAll() as $userWatchesSite) { $user = $userRepo->loadByID($userWatchesSite->getUserAccountId()); $site = $siteRepo->loadById($userWatchesSite->getSiteId()); $siteRepo->loadLegacyFeaturesOnSite($site); // to avoid flooding user we only send one group email per run $anyGroupNotificationsSent = false; $this->logVerbose(" User " . $user->getEmail() . " Site " . $site->getTitle()); if ($site->getIsClosedBySysAdmin()) { $this->logVerbose(" ... site is closed"); // Technically UserWatchesSiteRepositoryBuilder() should only return getIsWatching() == true but lets double check } else { if ($userWatchesSite->getIsWatching()) { $groupRepoBuilder = new GroupRepositoryBuilder(); $groupRepoBuilder->setSite($site); $groupRepoBuilder->setIncludeDeleted(false); foreach ($groupRepoBuilder->fetchAll() as $group) { if (!$anyGroupNotificationsSent) { $this->logVerbose(" ... searching group " . $group->getSlug() . " for data"); $lastEvent = $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId()); $data = $userWatchesSite->getGroupPromptEmailData($site, $group, $lastEvent); if ($data['moreEventsNeeded']) { $this->logVerbose(" ... found data "); ///// Notification Class $userNotification = $userNotificationType->getNewNotification($user, $site); $userNotification->setGroup($group); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($user, $site); configureAppForSite($site); configureAppForUser($user); $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $unsubscribeURL = $CONFIG->getWebIndexDomainSecure() . '/you/emails/' . $user->getId() . '/' . $userAccountGeneralSecurityKey->getAccessKey(); $lastEventsBuilder = new EventRepositoryBuilder(); $lastEventsBuilder->setSite($site); $lastEventsBuilder->setGroup($group); $lastEventsBuilder->setOrderByStartAt(true); $lastEventsBuilder->setIncludeDeleted(false); $lastEventsBuilder->setIncludeImported(false); $lastEventsBuilder->setLimit($CONFIG->userWatchesSiteGroupPromptEmailShowEvents); $lastEvents = $lastEventsBuilder->fetchAll(); $message = \Swift_Message::newInstance(); $message->setSubject("Any news about " . $group->getTitle() . "?"); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $this->app['twig']->render('email/userWatchesSiteGroupPromptEmail.txt.twig', array('user' => $user, 'group' => $group, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL)); if ($CONFIG->isDebug) { file_put_contents('/tmp/userWatchesSiteGroupPromptEmail.txt', $messageText); } $message->setBody($messageText); $messageHTML = $this->app['twig']->render('email/userWatchesSiteGroupPromptEmail.html.twig', array('user' => $user, 'group' => $group, 'lastEvents' => $lastEvents, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'unsubscribeURL' => $unsubscribeURL)); if ($CONFIG->isDebug) { file_put_contents('/tmp/userWatchesSiteGroupPromptEmail.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); $headers = $message->getHeaders(); $headers->addTextHeader('List-Unsubscribe', $unsubscribeURL); $this->logVerbose(" ... sending"); if (!$CONFIG->isDebug) { $this->app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } $userWatchesSiteRepository->markGroupPromptEmailSent($userWatchesSite, $group, $data['checkTime']); $anyGroupNotificationsSent = true; } } } } } } return array('result' => 'ok'); }
public static function run(Application $app, $verbose = false) { global $CONFIG; if ($verbose) { print "Starting " . date("c") . "\n"; } $siteRepo = new SiteRepository(); $groupRepo = new GroupRepository(); $importURLRepo = new ImportURLRepository(); $userRepo = new UserAccountRepository(); $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository(); $userWatchesGroupStopRepository = new UserWatchesGroupStopRepository(); $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository(); $userNotificationRepo = new UserNotificationRepository(); /** @var usernotifications/UpcomingEventsUserNotificationType **/ $userNotificationType = $app['extensions']->getCoreExtension()->getUserNotificationType('ImportURLExpired'); $iurlBuilder = new ImportURLRepositoryBuilder(); foreach ($iurlBuilder->fetchAll() as $importURL) { $site = $siteRepo->loadById($importURL->getSiteID()); $group = $groupRepo->loadById($importURL->getGroupId()); if ($verbose) { print date("c") . " ImportURL " . $importURL->getId() . " " . $importURL->getTitle() . " Site " . $site->getTitle() . "\n"; } if ($site->getIsClosedBySysAdmin()) { if ($verbose) { print " - site closed by sys admin\n"; } } else { if (!$site->getIsFeatureImporter()) { if ($verbose) { print " - site feature disabled\n"; } } else { if (!$group) { if ($verbose) { print " - no group - this should be impossible\n"; } } else { if ($group->getIsDeleted()) { if ($verbose) { print " - group deleted\n"; } } else { if ($importURL->getExpiredAt()) { if ($verbose) { print " - expired\n"; } } else { if (!$importURL->getIsEnabled()) { if ($verbose) { print " - not enabled\n"; } } else { if ($importURL->isShouldExpireNow()) { if ($verbose) { print " - expiring\n"; } $importURLRepo->expire($importURL); configureAppForSite($site); $uwsb = new UserWatchesSiteRepositoryBuilder(); $uwsb->setSite($site); foreach ($uwsb->fetchAll() as $userWatchesSite) { $user = $userRepo->loadByID($userWatchesSite->getUserAccountId()); if ($userWatchesSite->getIsWatching()) { /// Notification Class $userNotification = $userNotificationType->getNewNotification($user, $site); $userNotification->setImportURL($importURL); $userNotification->setGroup($group); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { configureAppForUser($user); $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($user, $site); $message = \Swift_Message::newInstance(); $message->setSubject("Please confirm this is still valid: " . $importURL->getTitle()); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $app['twig']->render('email/importURLExpired.watchesSite.txt.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey())); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesSite.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/importURLExpired.watchesSite.html.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey())); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesSite.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } } } $uwgb = new UserWatchesGroupRepositoryBuilder(); $uwgb->setGroup($group); foreach ($uwgb->fetchAll() as $userWatchesGroup) { $user = $userRepo->loadByID($userWatchesGroup->getUserAccountId()); if ($userWatchesGroup->getIsWatching()) { /// Notification Class $userNotification = $userNotificationType->getNewNotification($user, $site); $userNotification->setImportURL($importURL); $userNotification->setGroup($group); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $userWatchesGroupStop = $userWatchesGroupStopRepository->getForUserAndGroup($user, $group); $message = \Swift_Message::newInstance(); $message->setSubject("Please confirm this is still valid: " . $importURL->getTitle()); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $app['twig']->render('email/importURLExpired.watchesGroup.txt.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'group' => $group)); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesGroup.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/importURLExpired.watchesGroup.html.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'group' => $group)); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesGroup.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } } } } else { $lastRunDate = $importURLRepo->getLastRunDateForImportURL($importURL); $nowDate = \TimeSource::getDateTime(); if (!$lastRunDate || $lastRunDate->getTimestamp() < $nowDate->getTimestamp() - $CONFIG->importURLSecondsBetweenImports) { if ($verbose) { print " - importing\n"; } $runner = new ImportURLRunner(); $runner->go($importURL); } else { if ($verbose) { print " - already done on " . $lastRunDate->format("c") . "\n"; } } } } } } } } } } if ($verbose) { print "Finished " . date("c") . "\n"; } }
function stopWatchingFromEmail($slug, $userid, $code, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Area does not exist."); } $userRepo = new UserAccountRepository(); $user = $userRepo->loadByID($userid); if (!$user) { $app['monolog']->addError("Failed stop watching area from email - no user "); die("NO"); // TODO } $userWatchesAreaStopRepo = new UserWatchesAreaStopRepository(); $userWatchesAreaStop = $userWatchesAreaStopRepo->loadByUserAccountIDAndAreaIDAndAccessKey($user->getId(), $this->parameters['area']->getId(), $code); if (!$userWatchesAreaStop) { $app['monolog']->addError("Failed stop watching area from email - user " . $user->getId() . " - code wrong"); die("NO"); // TODO } $userWatchesAreaRepo = new UserWatchesAreaRepository(); $userWatchesArea = $userWatchesAreaRepo->loadByUserAndArea($user, $this->parameters['area']); if (!$userWatchesArea || !$userWatchesArea->getIsWatching()) { $app['monolog']->addError("Failed stop watching area from email - user " . $user->getId() . " - not watching"); die("You don't watch this area"); // TODO } if ($request->request->get('action') == 'unwatch' && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $userWatchesAreaRepo->stopUserWatchingArea($user, $this->parameters['area']); // redirect here because if we didn't the twig global and $app vars would be wrong (the old state) // this is an easy way to get round that. $app['flashmessages']->addMessage("You have stopped watching this area."); return $app->redirect('/area/' . $this->parameters['area']->getSlugForURL()); } $this->parameters['user'] = $user; return $app['twig']->render('site/area/stopWatchingFromEmail.html.twig', $this->parameters); }
function emails($id, $code, Request $request, Application $app) { $userRepository = new UserAccountRepository(); if ($app['currentUser'] && $app['currentUser']->getId() == $id) { // We do this to save a DB Query $user = $app['currentUser']; } else { $user = $userRepository->loadByID($id); } if (!$user) { $app['monolog']->addError("Failed changing email - no account"); return $app['twig']->render('index/user/emails.fail.html.twig', array()); } $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository(); $userAccountGSK = $userAccountGeneralSecurityKeyRepository->loadByUserAccountIDAndAccessKey($id, $code); if (!$userAccountGSK) { $app['monolog']->addError("Failed changing email - account user " . $user->getId() . " - code wrong"); return $app['twig']->render('index/user/emails.fail.html.twig', array()); } $ourForm = new UserEmailsForm($app['extensions'], $user); $form = $app['form.factory']->create($ourForm, $user); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $userRepository->editEmailsOptions($user); $ourForm->savePreferences($form); $app['flashmessages']->addMessage("Options Changed."); return $app->redirect("/"); } } return $app['twig']->render('index/user/emails.html.twig', array('form' => $form->createView(), 'user' => $user)); }