Пример #1
0
 /**
  * Execute the extra.
  */
 public function execute()
 {
     // get activation key
     $key = $this->URL->getParameter(0);
     // load template
     $this->loadTemplate();
     // do we have an activation key?
     if (isset($key)) {
         // get profile id
         $profileId = FrontendProfilesModel::getIdBySetting('activation_key', $key);
         // have id?
         if ($profileId != null) {
             // update status
             FrontendProfilesModel::update($profileId, array('status' => 'active'));
             // delete activation key
             FrontendProfilesModel::deleteSetting($profileId, 'activation_key');
             // login profile
             FrontendProfilesAuthentication::login($profileId);
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_activate', array('id' => $profileId));
             // show success message
             $this->tpl->assign('activationSuccess', true);
         } else {
             // failure
             $this->redirect(FrontendNavigation::getURL(404));
         }
     } else {
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
Пример #2
0
 /**
  * Parse
  */
 private function parse()
 {
     $this->tpl->assign('isLoggedIn', FrontendProfilesAuthentication::isLoggedIn());
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         $profile = FrontendProfilesAuthentication::getProfile();
         $this->tpl->assign('profile', $profile->toArray());
     }
 }
Пример #3
0
 /**
  * Execute the extra
  */
 public function execute()
 {
     parent::execute();
     $this->loadTemplate();
     // Check if we're logged in, else redirect to the login form.
     if (!FrontendProfilesAuthentication::isLoggedIn()) {
         $queryString = $this->URL->getQueryString();
         throw new RedirectException('Redirect', new RedirectResponse(Navigation::getURLForBlock('Profiles', 'Login') . '?queryString=' . $queryString));
     }
 }
Пример #4
0
 /**
  * Execute the extra.
  */
 public function execute()
 {
     // logout
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         FrontendProfilesAuthentication::logout();
     }
     // trigger event
     FrontendModel::triggerEvent('Profiles', 'after_logout');
     // redirect
     $this->redirect(SITE_URL);
 }
Пример #5
0
 /**
  * Parse
  */
 private function parse()
 {
     // assign if logged in
     $this->tpl->assign('isLoggedIn', FrontendProfilesAuthentication::isLoggedIn());
     // is logged in
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         // get the profile
         $profile = FrontendProfilesAuthentication::getProfile();
         // assign logged in profile
         $this->tpl->assign('profile', $profile->toArray());
     }
 }
Пример #6
0
 /**
  * Execute the extra
  */
 public function execute()
 {
     // profile not logged in
     if (!FrontendProfilesAuthentication::isLoggedIn()) {
         parent::execute();
         $this->loadTemplate();
         $this->loadForm();
         $this->validateForm();
         $this->parse();
     } else {
         // profile logged in
         $this->redirect(FrontendNavigation::getURL(404));
     }
 }
Пример #7
0
 /**
  * Execute the extra.
  */
 public function execute()
 {
     // only for guests
     if (!FrontendProfilesAuthentication::isLoggedIn()) {
         parent::execute();
         $this->loadTemplate();
         $this->loadForm();
         $this->validateForm();
         $this->parse();
     } else {
         // already logged in, redirect to settings
         $this->redirect(FrontendNavigation::getURLForBlock('Profiles', 'Settings'));
     }
 }
Пример #8
0
 /**
  * Execute the extra.
  */
 public function execute()
 {
     // only logged in profiles can seer their dashboard
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         // call the parent
         parent::execute();
         /*
          * You could use this as some kind of dashboard where you can show an activity
          * stream, some statistics, ...
          */
         $this->loadTemplate();
     } else {
         // profile not logged in
         $this->redirect(FrontendNavigation::getURLForBlock('Profiles', 'Login') . '?queryString=' . FrontendNavigation::getURLForBlock('Profiles'), 307);
     }
 }
Пример #9
0
 /**
  * Get profile data.
  */
 private function getData()
 {
     // get profile
     $this->profile = FrontendProfilesAuthentication::getProfile();
 }
Пример #10
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtPassword = $this->frm->getField('password');
         $txtEmail = $this->frm->getField('email');
         // password filled in?
         if ($txtPassword->isFilled(FL::getError('PasswordIsRequired'))) {
             // password correct?
             if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                 // set error
                 $txtPassword->addError(FL::getError('InvalidPassword'));
             }
             // email filled in?
             if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
                 // valid email?
                 if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                     // email already exists?
                     if (FrontendProfilesModel::existsByEmail($txtEmail->getValue(), $this->profile->getId())) {
                         // set error
                         $txtEmail->setError(FL::getError('EmailExists'));
                     }
                 }
             }
         }
         // no errors
         if ($this->frm->isCorrect()) {
             // update email
             FrontendProfilesModel::update($this->profile->getId(), array('email' => $txtEmail->getValue()));
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_change_email', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ChangeEmail') . '?sent=true');
         } else {
             $this->tpl->assign('updateEmailHasFormError', true);
         }
     }
 }
Пример #11
0
 /**
  * Loads the actual components on the page
  */
 public function load()
 {
     // set tracking cookie
     Model::getVisitorId();
     // create header instance
     $this->header = new Header($this->getKernel());
     // get page content from pageId of the requested URL
     $this->record = $this->getPageContent(Navigation::getPageId(implode('/', $this->URL->getPages())));
     if (empty($this->record)) {
         $this->record = Model::getPage(404);
     }
     // authentication
     if (BackendModel::isModuleInstalled('Profiles') && isset($this->record['data']['auth_required'])) {
         $data = $this->record['data'];
         // is auth required and is profile logged in
         if ($data['auth_required']) {
             if (!FrontendAuthenticationModel::isLoggedIn()) {
                 // redirect to login page
                 $queryString = $this->URL->getQueryString();
                 throw new RedirectException('Redirect', new RedirectResponse(Navigation::getURLForBlock('Profiles', 'Login') . '?queryString=' . $queryString));
             }
             // specific groups for auth?
             if (!empty($data['auth_groups'])) {
                 $inGroup = false;
                 foreach ($data['auth_groups'] as $group) {
                     if (FrontendAuthenticationModel::getProfile()->isInGroup($group)) {
                         $inGroup = true;
                     }
                 }
                 if (!$inGroup) {
                     $this->record = Model::getPage(404);
                 }
             }
         }
     }
     // we need to set the correct id
     $this->pageId = (int) $this->record['id'];
     // set headers if this is a 404 page
     if ($this->pageId == 404) {
         $this->statusCode = 404;
         if (extension_loaded('newrelic')) {
             newrelic_name_transaction('404');
         }
     }
     // create breadcrumb instance
     $this->breadcrumb = new Breadcrumb($this->getKernel());
     // new footer instance
     $this->footer = new Footer($this->getKernel());
     // process page
     $this->processPage();
     // execute all extras linked to the page
     $this->processExtras();
     // store statistics
     $this->storeStatistics();
     // trigger event
     Model::triggerEvent('Core', 'after_page_processed', array('id' => $this->getId(), 'record' => $this->getRecord(), 'statusCode' => $this->getStatusCode(), 'sessionId' => \SpoonSession::getSessionId(), 'visitorId' => Model::getVisitorId(), 'SESSION' => $_SESSION, 'COOKIE' => $_COOKIE, 'GET' => $_GET, 'POST' => $_POST, 'SERVER' => $_SERVER));
 }
Пример #12
0
 /**
  * Get navigation HTML
  *
  * @param string $type         The type of navigation the HTML should be build for.
  * @param int    $parentId     The parentID to start of.
  * @param int    $depth        The maximum depth to parse.
  * @param array  $excludeIds   PageIDs to be excluded.
  * @param string $template     The template that will be used.
  * @param int    $depthCounter A counter that will hold the current depth.
  *
  * @return string
  * @throws Exception
  */
 public static function getNavigationHTML($type = 'page', $parentId = 0, $depth = null, $excludeIds = array(), $template = '/Core/Layout/Templates/Navigation.html.twig', $depthCounter = 1)
 {
     // get navigation
     $navigation = self::getNavigation();
     // merge the exclude ids with the previously set exclude ids
     $excludeIds = array_merge((array) $excludeIds, self::$excludedPageIds);
     // meta-navigation is requested but meta isn't enabled
     if ($type == 'meta' && (!Model::get('fork.settings')->get('Pages', 'meta_navigation', true) || !isset($navigation['meta']))) {
         return '';
     }
     // validate
     if (!isset($navigation[$type])) {
         throw new Exception('This type (' . $type . ') isn\'t a valid navigation type. Possible values are: page, footer, meta.');
     }
     if (!isset($navigation[$type][$parentId])) {
         throw new Exception('The parent (' . $parentId . ') doesn\'t exists.');
     }
     // special construction to merge home with its immediate children
     $mergedHome = false;
     while (true) {
         // loop elements
         foreach ($navigation[$type][$parentId] as $id => $page) {
             // home is a special item, it should live on the same depth
             if ($page['page_id'] == 1 && !$mergedHome) {
                 // extra checks otherwise exceptions will wbe triggered.
                 if (!isset($navigation[$type][$parentId]) || !is_array($navigation[$type][$parentId])) {
                     $navigation[$type][$parentId] = array();
                 }
                 if (!isset($navigation[$type][$page['page_id']]) || !is_array($navigation[$type][$page['page_id']])) {
                     $navigation[$type][$page['page_id']] = array();
                 }
                 // add children
                 $navigation[$type][$parentId] = array_merge($navigation[$type][$parentId], $navigation[$type][$page['page_id']]);
                 // mark as merged
                 $mergedHome = true;
                 // restart loop
                 continue 2;
             }
             // not hidden and not an action
             if ($page['hidden'] || $page['tree_type'] == 'direct_action') {
                 unset($navigation[$type][$parentId][$id]);
                 continue;
             }
             // authentication
             if (isset($page['data'])) {
                 // unserialize data
                 $page['data'] = unserialize($page['data']);
                 // if auth_required isset and is true
                 if (isset($page['data']['auth_required']) && $page['data']['auth_required']) {
                     // is profile logged? unset
                     if (!FrontendAuthentication::isLoggedIn()) {
                         unset($navigation[$type][$parentId][$id]);
                         continue;
                     }
                     // check if group auth is set
                     if (!empty($page['data']['auth_groups'])) {
                         $inGroup = false;
                         // loop group and set value true if one is found
                         foreach ($page['data']['auth_groups'] as $group) {
                             if (FrontendAuthentication::getProfile()->isInGroup($group)) {
                                 $inGroup = true;
                             }
                         }
                         // unset page if not in any of the groups
                         if (!$inGroup) {
                             unset($navigation[$type][$parentId][$id]);
                         }
                     }
                 }
             }
             // some ids should be excluded
             if (in_array($page['page_id'], (array) $excludeIds)) {
                 unset($navigation[$type][$parentId][$id]);
                 continue;
             }
             // if the item is in the selected page it should get an selected class
             if (in_array($page['page_id'], self::$selectedPageIds)) {
                 $navigation[$type][$parentId][$id]['selected'] = true;
             } else {
                 $navigation[$type][$parentId][$id]['selected'] = false;
             }
             // add nofollow attribute if needed
             if ($page['no_follow']) {
                 $navigation[$type][$parentId][$id]['nofollow'] = true;
             } else {
                 $navigation[$type][$parentId][$id]['nofollow'] = false;
             }
             // meta and footer subpages have the "page" type
             if ($type == 'meta' || $type == 'footer') {
                 $subType = 'page';
             } else {
                 $subType = $type;
             }
             // fetch children if needed
             if (isset($navigation[$subType][$page['page_id']]) && $page['page_id'] != 1 && ($depth == null || $depthCounter + 1 <= $depth)) {
                 $navigation[$type][$parentId][$id]['children'] = self::getNavigationHTML($subType, $page['page_id'], $depth, $excludeIds, $template, $depthCounter + 1);
             } else {
                 $navigation[$type][$parentId][$id]['children'] = false;
             }
             // add parent id
             $navigation[$type][$parentId][$id]['parent_id'] = $parentId;
             // add depth
             $navigation[$type][$parentId][$id]['depth'] = $depthCounter;
             // set link
             $navigation[$type][$parentId][$id]['link'] = static::getURL($page['page_id']);
             // is this an internal redirect?
             if (isset($page['redirect_page_id']) && $page['redirect_page_id'] != '') {
                 $navigation[$type][$parentId][$id]['link'] = static::getURL((int) $page['redirect_page_id']);
             }
             // is this an external redirect?
             if (isset($page['redirect_url']) && $page['redirect_url'] != '') {
                 $navigation[$type][$parentId][$id]['link'] = $page['redirect_url'];
             }
         }
         // break the loop (it is only used for the special construction with home)
         break;
     }
     // return parsed content
     return Model::get('templating')->render($template, array('navigation' => $navigation[$type][$parentId]));
 }
Пример #13
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtPassword = $this->frm->getField('password');
         // field is filled in?
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // valid
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdBySetting('forgot_password_key', $this->URL->getParameter(0));
             // remove key (we can only update the password once with this key)
             FrontendProfilesModel::deleteSetting($profileId, 'forgot_password_key');
             // update password
             FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue());
             // login (check again because we might have logged in in the meanwhile)
             if (!FrontendProfilesAuthentication::isLoggedIn()) {
                 FrontendProfilesAuthentication::login($profileId);
             }
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_reset_password', array('id' => $profileId));
             // redirect
             $this->redirect(FrontendNavigation::getURLForBlock('Profiles', 'ResetPassword') . '/' . $this->URL->getParameter(0) . '?sent=true');
         } else {
             $this->tpl->assign('forgotPasswordHasError', true);
         }
     }
 }
Пример #14
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtEmail = $this->frm->getField('email');
         $txtPassword = $this->frm->getField('password');
         $chkRemember = $this->frm->getField('remember');
         // required fields
         $txtEmail->isFilled(FL::getError('EmailIsRequired'));
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // both fields filled in
         if ($txtEmail->isFilled() && $txtPassword->isFilled()) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // get the status for the given login
                 $loginStatus = FrontendProfilesAuthentication::getLoginStatus($txtEmail->getValue(), $txtPassword->getValue());
                 // valid login?
                 if ($loginStatus !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                     // get the error string to use
                     $errorString = sprintf(FL::getError('Profiles' . \SpoonFilter::toCamelCase($loginStatus) . 'Login'), FrontendNavigation::getURLForBlock('Profiles', 'ResendActivation'));
                     // add the error to stack
                     $this->frm->addError($errorString);
                     // add the error to the template variables
                     $this->tpl->assign('loginError', $errorString);
                 }
             }
         }
         // valid login
         if ($this->frm->isCorrect()) {
             // get profile id
             $profileId = FrontendProfilesModel::getIdByEmail($txtEmail->getValue());
             // login
             FrontendProfilesAuthentication::login($profileId, $chkRemember->getChecked());
             // update salt and password for Dieter's security features
             FrontendProfilesAuthentication::updatePassword($profileId, $txtPassword->getValue());
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_logged_in', array('id' => $profileId));
             // query string
             $queryString = urldecode(\SpoonFilter::getGetValue('queryString', null, SITE_URL));
             // redirect
             $this->redirect($queryString);
         }
     }
 }
Пример #15
0
 /**
  * Parse the general profiles info into the template.
  */
 public static function parse()
 {
     // get the template
     $tpl = FrontendModel::getContainer()->get('template');
     // logged in
     if (FrontendProfilesAuthentication::isLoggedIn()) {
         // get profile
         $profile = FrontendProfilesAuthentication::getProfile();
         // display name set?
         if ($profile->getDisplayName() != '') {
             $tpl->assign('profileDisplayName', $profile->getDisplayName());
         } else {
             // no display name -> use email
             $tpl->assign('profileDisplayName', $profile->getEmail());
         }
         // show logged in
         $tpl->assign('isLoggedIn', true);
     }
     // ignore these urls in the query string
     $ignoreUrls = array(FrontendNavigation::getURLForBlock('Profiles', 'Login'), FrontendNavigation::getURLForBlock('Profiles', 'Register'), FrontendNavigation::getURLForBlock('Profiles', 'ForgotPassword'));
     // query string
     $queryString = isset($_GET['queryString']) ? SITE_URL . '/' . urldecode($_GET['queryString']) : SELF;
     // check all ignore urls
     foreach ($ignoreUrls as $url) {
         // query string contains a boeboe url
         if (stripos($queryString, $url) !== false) {
             $queryString = '';
             break;
         }
     }
     // no need to add this if its empty
     $queryString = $queryString != '' ? '?queryString=' . urlencode($queryString) : '';
     // useful urls
     $tpl->assign('loginUrl', FrontendNavigation::getURLForBlock('Profiles', 'Login') . $queryString);
     $tpl->assign('registerUrl', FrontendNavigation::getURLForBlock('Profiles', 'Register'));
     $tpl->assign('forgotPasswordUrl', FrontendNavigation::getURLForBlock('Profiles', 'ForgotPassword'));
 }
Пример #16
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtOldPassword = $this->frm->getField('old_password');
         $txtNewPassword = $this->frm->getField('new_password');
         // old password filled in?
         if ($txtOldPassword->isFilled(FL::getError('PasswordIsRequired'))) {
             // old password correct?
             if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtOldPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                 // set error
                 $txtOldPassword->addError(FL::getError('InvalidPassword'));
             }
             // new password filled in?
             $txtNewPassword->isFilled(FL::getError('PasswordIsRequired'));
             // passwords match?
             if ($this->frm->getField('new_password')->getValue() !== $this->frm->getField('verify_new_password')->getValue()) {
                 $this->frm->getField('verify_new_password')->addError(FL::err('PasswordsDontMatch'));
             }
         }
         // no errors
         if ($this->frm->isCorrect()) {
             // update password
             FrontendProfilesAuthentication::updatePassword($this->profile->getId(), $txtNewPassword->getValue());
             // trigger event
             FrontendModel::triggerEvent('Profiles', 'after_change_password', array('id' => $this->profile->getId()));
             // redirect
             $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ChangePassword') . '?sent=true');
         } else {
             $this->tpl->assign('updatePasswordHasFormError', true);
         }
     }
 }
Пример #17
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted
     if ($this->frm->isSubmitted()) {
         // get fields
         $txtDisplayName = $this->frm->getField('display_name');
         $txtEmail = $this->frm->getField('email');
         $txtPassword = $this->frm->getField('password');
         // check email
         if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
             // valid email?
             if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                 // email already exists?
                 if (FrontendProfilesModel::existsByEmail($txtEmail->getValue())) {
                     // set error
                     $txtEmail->setError(FL::getError('EmailExists'));
                 }
             }
         }
         // check password
         $txtPassword->isFilled(FL::getError('PasswordIsRequired'));
         // no errors
         if ($this->frm->isCorrect()) {
             // init values
             $settings = array();
             $values = array();
             // generate salt
             $settings['salt'] = FrontendProfilesModel::getRandomString();
             $settings['language'] = FRONTEND_LANGUAGE;
             // values
             $values['email'] = $txtEmail->getValue();
             $values['password'] = FrontendProfilesModel::getEncryptedString($txtPassword->getValue(), $settings['salt']);
             $values['status'] = 'inactive';
             $values['display_name'] = $txtDisplayName->getValue();
             $values['registered_on'] = FrontendModel::getUTCDate();
             $values['last_login'] = FrontendModel::getUTCDate(null, 0);
             /*
              * Add a profile.
              * We use a try-catch statement to catch errors when more users sign up simultaneously.
              */
             try {
                 // insert profile
                 $profileId = FrontendProfilesModel::insert($values);
                 // use the profile id as url until we have an actual url
                 FrontendProfilesModel::update($profileId, array('url' => FrontendProfilesModel::getUrl($values['display_name'])));
                 // trigger event
                 FrontendModel::triggerEvent('Profiles', 'after_register', array('id' => $profileId));
                 // generate activation key
                 $settings['activation_key'] = FrontendProfilesModel::getEncryptedString($profileId . microtime(), $settings['salt']);
                 // set settings
                 FrontendProfilesModel::setSettings($profileId, $settings);
                 // login
                 FrontendProfilesAuthentication::login($profileId);
                 // activation URL
                 $mailValues['activationUrl'] = SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'Activate') . '/' . $settings['activation_key'];
                 // send email
                 $from = $this->get('fork.settings')->get('Core', 'mailer_from');
                 $replyTo = $this->get('fork.settings')->get('Core', 'mailer_reply_to');
                 $message = \Common\Mailer\Message::newInstance(FL::getMessage('RegisterSubject'))->setFrom(array($from['email'] => $from['name']))->setTo(array($txtEmail->getValue() => ''))->setReplyTo(array($replyTo['email'] => $replyTo['name']))->parseHtml(FRONTEND_MODULES_PATH . '/Profiles/Layout/Templates/Mails/Register.tpl', $mailValues, true);
                 $this->get('mailer')->send($message);
                 // redirect
                 $this->redirect(SITE_URL . '/' . $this->URL->getQueryString() . '?sent=true');
             } catch (\Exception $e) {
                 // when debugging we need to see the exceptions
                 if ($this->getContainer()->getParameter('kernel.debug')) {
                     throw $e;
                 }
                 // show error
                 $this->tpl->assign('registerHasFormError', true);
             }
         } else {
             $this->tpl->assign('registerHasFormError', true);
         }
     }
 }