ok(__('You should soon receive an email with further instructions.')); } else { error('login-email-unknown', __('The email is not registered yet.')); } }); /* * endpoint for re-sending the activation link to a user */ $app->post('/account/resend-activation', function () use($app) { $user = DatawrapperSession::getUser(); $token = $user->getActivateToken(); if (!empty($token)) { // check how often the activation email has been send // we don't want to send it too often in order to prevent // mail spam coming from our server $r = ActionQuery::create()->filterByUser($user)->filterByKey('resend-activation')->find(); if (count($r) > 2) { error('avoid-spam', str_replace('%support_email%', $GLOBALS['dw_config']['email']['support'], __('You already resent the activation mail three times, now. Please <a href="mailto:%support_email%">contact an administrator</a> to proceed with your account activation.'))); return false; } // remember that we send the email Action::logAction($user, 'resend-activation', $token); // send email with activation key $domain = $GLOBALS['dw_config']['domain']; $protocol = get_current_protocol(); $activationLink = $protocol . '://' . $domain . '/account/activate/' . $token; include ROOT_PATH . 'lib/templates/activation-email.php'; dw_send_support_email($user->getEmail(), __('Datawrapper: Please activate your email address'), $activation_mail, array('name' => $user->guessName(), 'activation_link' => $activationLink)); ok(__('The activation email has been send to your email address, again.')); } else { error('token-empty', __('You\'re account is probably already activated.'));
} } if ($app->request()->get('token')) { // look for action with this token $t = ActionQuery::create()->filterByUser($user)->filterByKey('email-change-request')->orderByActionTime('desc')->findOne(); if (!empty($t)) { // check if token is valid $params = json_decode($t->getDetails(), true); if (!empty($params['token']) && $params['token'] == $app->request()->get('token')) { // token matches $user->setEmail($params['new-email']); $user->save(); $page['new_email_confirmed'] = true; // clear token to prevent future changes $params['token'] = ''; $t->setDetails(json_encode($params)); $t->save(); } } } if ($user->getRole() == 'pending') { $t = ActionQuery::create()->filterByUser($user)->filterByKey('resend-activation')->orderByActionTime('desc')->findOne(); if (empty($t)) { $t = $user->getCreatedAt('U'); } else { $t = $t->getActionTime('U'); } $page['activation_email_date'] = strftime('%x', $t); } $app->render('settings.twig', $page); });
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(ActionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = ActionQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Returns the number of related Action objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Action objects. * @throws PropelException */ public function countActions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collActionsPartial && !$this->isNew(); if (null === $this->collActions || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collActions) { return 0; } if ($partial && !$criteria) { return count($this->getActions()); } $query = ActionQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByUser($this)->count($con); } return count($this->collActions); }