Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frontainer
#1
Frontainer's current version: 1.0
 
What is Frontainer

Frontainer is a powerful frontend user management plugin based on ItemManager for GetSimple-CMS and perfect to generate password protected, private areas on the GetSimple website. Frontainer is a simple and useful tool for plugin developers, provides a good basis for further development of user management based scripts or e-commerce plugins, for instance.

Application example: [ SimpleForum theme ]

Frontainer Features
  1. Frontend login form
  2. Registration and the lost password form
  3. Fully customizable HTML, CSS
  4. Fully scalable and extendable functionality
  5. Multilingual (currently English language file included)
 

Requirements

To run Frontainer on your GetSimple website just needs a number of things:

    1. ItemManager 2.3+ plugin must be installed and configured
    2. Users category must have been created in ItemManager (see bellow: Creating ItemManager's Users Category)
    3. Configured mail server to send and receive emails from your GetSimple site

Installation

  1. First of, create following pages in admin, these pages are used by Frontainer for integrate corresponding functionality.
    1. Login
    2. Signup
    3. Accounts 
    4. Logout 
    5. Recovery 
    6. Activate
Please make sure that the resulting page slugs are exactly the same as page names: login, signup, accounts, etc.

  1. Install/activate Frontainer v. 1.0 from GitHub or Extend
  2. Go to Plugins > Frontainer settings and put there your eMail data (used by Frontainer to build the email-content for user authentification)

Creating ItemManager's Users category

  1. Let’s go to ItemManager’s tab > Categories and create there a category named Users:
  2. After that go to ItemManager’s Fields menu select Users category and click Reload, then create following fields for it:
    1. Name: email, Label: eMail (or your choice), Type: Text field
    2. Name: password, Label: Password (or your choice), Type: Password
    3. Name: recovery, Label: Recovery password (or your choice), Type: Hidden field
Preparing your theme for using Frontainer

Preparing your theme for using Frontainer is really easy. Open template.php file in your editor and add the following lines to the very beginning (first line).

Code:
<?php
if(!defined('IN_GS')) die();
if(!isset($_SESSION)){session_start();}
$fnavi = array(
    'login' => null,
    'signup' => null,
    'accounts' => null,
    'logout' => null,
    'recovery' => null
);
$fcontent = '';
if(function_exists('frontainer_get_content')) {
    $fcontent = frontainer_get_content();
    $fnavi['login'] = htmlspecialchars(get_section_url(LOGIN_SLUG));
    $fnavi['signup'] = htmlspecialchars(get_section_url(SIGNUP_SLUG));
    $fnavi['accounts'] = htmlspecialchars(get_section_url(ACCOUNTS_SLUG));
    $fnavi['logout'] = htmlspecialchars(get_section_url(LOGOUT_SLUG));
    $fnavi['recovery'] = htmlspecialchars(get_section_url(RECOVERY_SLUG));
}
?>

After that you’ll need to add a single line anywhere within the body of your template.php file for the output of Frontier’s contents:

Code:
<?php echo $fcontent; ?>
 
To access Frontainers sections and to switch between Frontainers pages you can use following navigation structure for example:

Code:
<ul class="nav navbar-nav">
    <li><a href="<?php get_site_url(); ?>forum/">Forum</a></li>
    <?php
    if(!isset($_SESSION['loggedin'])) {
        echo '<li ';
        if($id == $fnavi['login'] || $id == $fnavi['recovery'])
            echo 'class="active"';
        echo ' ><a href="'.$fnavi['login'].'">Login</a></li>';
        echo '<li ';
        if($id == $fnavi['signup'])
            echo 'class="active"';
        echo ' ><a href="'.$fnavi['signup'].'">Sign up</a></li>';
    } else {
        echo '<li ';
        if($id == $fnavi['accounts'])
            echo 'class="active"';
        echo ' ><a href="'.$fnavi['accounts'].'">Private</a></li>';
        echo '<li ';
        if($id == $fnavi['logout'])
            echo 'class="active"';
        echo ' ><a href="'.$fnavi['logout'].'">Logout</a></li>';
    }
    ?>
</ul>

And that is all you need to do to run Frontainer!

User's private area

After a successful login the user is redirected by default to www.your_site.com/accounts/ page in the users private section.
To modify this private area, just edit '/plugins/frontainer/loggedin.php' file within the 'build_user_area()' function and put there any content you like, after: //////////   Your can put your content here //////////// comment. You can delete all lines subsequent to that code


Using Frontainer session variables

To check whether the user is logged use code:

Code:
<?php
if(!empty($_SESSION['loggedin'])) {
// This is the theme section for logged in users only
}
?>

You can get the logged in users ID on this way:

Code:
<?php
$user_id = (!empty($_SESSION['userid']) ? (int) $_SESSION['userid'] : false);
?>

Have fun!
Reply
#2
Activating Frontainer gives


Fatal error: Can't use function return value in write context in /home/user/my-domain.com/plugins/frontainer.php on line 367


and white-screen my whole site ..
------------------------------------------------
php 5.4.42
GS version 3.3.2
Reply
#3
(2016-02-24, 07:20:45)Tzvook Wrote: Fatal error: Can't use function return value in write context in /home/user/my-domain.com/plugins/frontainer.php on line 367

PHP version?
Reply
#4
(2016-02-24, 07:25:28)Bigin Wrote:
(2016-02-24, 07:20:45)Tzvook Wrote: Fatal error: Can't use function return value in write context in /home/user/my-domain.com/plugins/frontainer.php on line 367

PHP version?

php 5.4.42

I'll upgrade php and try again in 10 min.
Reply
#5
(2016-02-24, 07:39:28)Tzvook Wrote:
(2016-02-24, 07:25:28)Bigin Wrote:
(2016-02-24, 07:20:45)Tzvook Wrote: Fatal error: Can't use function return value in write context in /home/user/my-domain.com/plugins/frontainer.php on line 367

PHP version?

php 5.4.42

I'll upgrade php and try again in 10 min.

on MAMP from PHP version 5.3 runs without any problems here
Reply
#6
(2016-02-24, 07:25:28)Bigin Wrote:
(2016-02-24, 07:20:45)Tzvook Wrote: Fatal error: Can't use function return value in write context in /home/user/my-domain.com/plugins/frontainer.php on line 367

PHP version?

10X Bigin
upgrading to php 5.6.10 did the trick
Reply
#7
(2016-02-24, 07:54:03)Tzvook Wrote:
(2016-02-24, 07:25:28)Bigin Wrote:
(2016-02-24, 07:20:45)Tzvook Wrote: Fatal error: Can't use function return value in write context in /home/user/my-domain.com/plugins/frontainer.php on line 367

PHP version?

10X Bigin
upgrading to php 5.6.10 did the trick

You are welcome! ;-)
Reply
#8
(2016-02-22, 23:48:10)Bigin Wrote: ...
Preparing your theme for using Frontainer

Preparing your theme for using Frontainer is really easy. Open template.php file in your editor and add the following lines to the very beginning (first line).

Code:
<?php
if(!defined('IN_GS')) die();
if(!isset($_SESSION)){session_start();}
// Frontainer call
$content = frontainer_get_content();
?>

After that you’ll need to add a single line anywhere within the body of your template.php file for the output of Frontier’s contents:

Code:
<?php echo $content; ?>
 
To access Frontainers sections and to switch between Frontainers pages you can use following navigation structure for example:

Code:
<ul class="nav navbar-nav">
   <li><a href="<?php get_site_url(); ?>forum/">Forum</a></li>
   <?php
   if(!isset($_SESSION['loggedin'])) {
       echo '<li ';
       if($id == LOGIN_SLUG || $id == RECOVERY_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(LOGIN_SLUG)).'">Login</a></li>';
       echo '<li ';
       if($id == SIGNUP_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(SIGNUP_SLUG)).'">Sign up</a></li>';
   } else {
       echo '<li ';
       if($id == ACCOUNTS_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(ACCOUNTS_SLUG)).'">Private</a></li>';
       echo '<li ';
       if($id == LOGOUT_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(LOGOUT_SLUG)).'">Logout</a></li>';
   }
?>
</ul>

And that is all you need to do to run Frontainer!

User's private area

After a successful login the user is redirected by default to www.your_site.com/accounts/ page in the users private section.
To modify this private area, just edit '/plugins/frontainer/loggedin.php' file within the 'build_user_area()' function and put there any content you like, after: //////////   Your can put your content here //////////// comment. You can delete all lines subsequent to that code


Using Frontainer session variables

To check whether the user is logged use code:

Code:
<?php
if(!empty($_SESSION['loggedin'])) {
// This is the theme section for logged in users only
}
?>

You can get the logged in users ID on this way:

Code:
<?php
$user_id = (!empty($_SESSION['userid']) ? (int) $_SESSION['userid'] : false);
?>

Have fun!

I have followed the outlined steps, but I fail to  really understand how I can apply a requirement to login for a given set of pages and subpages. I think the approach is to have a dedicated template for password protected content?
This is a modified template from the bootstrap3 theme. I have managed to make it show two different texts based on login status, but I still cannot show the actual content of the page with the "get_page_content();" that is normally used:

Code:
<?php
if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
if(!isset($_SESSION)){session_start();}
// Frontainer call
$content = frontainer_get_content();

/****************************************************
*
* @File:      templateprotected.php
* @Package:   GetSimple
* @Action:    Bootstrap3 for GetSimple CMS
*
*****************************************************/
?>
<?php include('header.inc.php'); ?>

     <div class="row">
       <div class="col-md-8">
         <h1><?php get_page_title(); ?></h1>
            <?php
                if(!empty($_SESSION['loggedin'])) {
                    // This is the theme section for logged in users only
                    get_page_content(); //This is the normally the way I call the content of the page, I cannot get it to work.
                    echo '<p>You are logged in</p>';
                    echo $content; //Does not seem to do anything
                }
                else {
                    echo '<p>You need to login to see this page</p>';
                }
            ?>
       </div>
       
       <div class="col-md-4">
          <?php get_component('sidenav'); ?>
       </div>
     </div>

<?php include('footer.inc.php'); ?>

I have managed to add frontainer to my navbar - and I have registered a user, I am able to login and logout and go to my account page.

Basically I just want a page and its subpages to require a password. But I do not want to re-enter the password for every resource I access on those pages so it makes sense to have a logged in session.

Any suggestions?
Best regards,
Reply
#9
Hello,
creating a password protected page by Frontainer is easier than you might think:
Let's say that your have a secret page with the slug "private" with some subpages and you would like to restrict access to for not-logged in users. So all you have to do is to add following code lines to the template.php file, right after the
"$content = frontainer_get_content()" function call:

PHP Code:
// get the current page slug
$slug get_page_slug(false);
// and the page parent slug
$parent get_parent(false);
if(
$slug == 'private' || $parent == 'private')
{
    
// The user is not logged in
    
if(empty($_SESSION['loggedin'])) {
        
// Redirect to the login page
        
header('Location: ' htmlspecialchars($SITEURL.'login/'));
        exit();
    }


If you don't really want to use the Frontainer's standard "account" page and after a successful login the user should be redirected to a private page you created, you could just add a redirect line to the Frontier’s loggedin.php file at the end of the "build_user_area()" function:

PHP Code:
header('Location: ' htmlspecialchars($manager->getSiteUrl().'/private/'));
exit(); 
Reply
#10
(2016-04-12, 07:55:41)DesruX Wrote: I have managed to make it show two different texts based on login status, but I still cannot show the actual content of the page with the "get_page_content();" that is normally used:

Yes because $content is a global variable also used by GetSimple. To get it working you could change the line:
PHP Code:
$content frontainer_get_content(); 
to
PHP Code:
$frontainersContent frontainer_get_content(); 
and
PHP Code:
<?php echo $content?>
to
PHP Code:
<?php echo $frontainersContent?>

That should do the trick.
Reply
#11
BTW: Simple user permissions (logged in, not-logged in) are just fine, but however, you may have even more fun and flexibility by adding a new user "roles" field to your Users category in ItemManager:

[Image: roles_field.png?dl=1]

This way you can show relevant content depending on the user role, for example:

PHP Code:
if($role->value == 'user') {
 
   echo 'Content for users only';
} elseif(
$role->value == 'admin') {
 
   echo 'Content for admins only';
} elseif(
$role->value == 'superuser') {
 
   echo 'Superusers content';
} else {
 
   echo 'User has no role selected';


Your complete code in template.php file world might then look like this:

PHP Code:
if(!empty($_SESSION['loggedin'])) {
 
   $manager = new IManager();
 
   $catClass $manager->getCategoryClass();
 
   $category $catClass->getCategory('name=Users');
 
   $itemClass $manager->getItemClass();
 
   $itemClass->limitedInit($category->get('id'), (int)$_SESSION['userid']);
 
   $user $itemClass->items[(int)$_SESSION['userid']];
 
   if(!$user) {die('User data not found');}
 
   $role $user->fields->roles;

 
   if($role->value == 'user') {
 
       echo 'Content for users only';
 
   } elseif($role->value == 'admin') {
 
       echo 'Content for admins only';
 
   } elseif($role->value == 'superuser') {
 
       echo 'Superusers content';
 
   } else {
 
       echo 'User has no role selected';
 
   }


Note: If users already exist, these users may fail to be synced to new "roles" field, you should re-save/update users in admin manually or by ItemManager API call:

PHP Code:
<?php
$manager 
= new IManager();
$catClass $manager->getCategoryClass();
$category $catClass->getCategory('name=Users');
$itemClass $manager->getItemClass();
$itemClass->init($category->get('id'));
foreach(
$itemClass->items as $user) {
 
   if($user->save()) {
 
       echo '<p>User name: <strong>'.htmlspecialchars($user->name).'</strong>  was successfully updated</p>';
 
   }

Reply
#12
(2016-04-12, 18:08:27)Bigin Wrote:
(2016-04-12, 07:55:41)DesruX Wrote: I have managed to make it show two different texts based on login status, but I still cannot show the actual content of the page with the "get_page_content();" that is normally used:

Yes because $content is a global variable also used by GetSimple. To get it working you could change the line:

PHP Code:
$content frontainer_get_content(); 
to

PHP Code:
$frontainersContent frontainer_get_content(); 
and

PHP Code:
<?php echo $content?>
to

PHP Code:
<?php echo $frontainersContent?>

That should do the trick.

Awsome! It worked like a charm. I now have a dedicated template: templateprotected.php that I can easily assign to pages in order to protect them.
Code:
<?php
if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
if(!isset($_SESSION)){session_start();}
// Frontainer call
$frontainersContent = frontainer_get_content();

/****************************************************
*
* @File:      templateprotected.php
* @Package:   GetSimple
* @Action:    Bootstrap3 for GetSimple CMS
*
*****************************************************/
?>
<?php include('header.inc.php'); ?>

     <div class="row">
       <div class="col-md-8">
         <h1><?php get_page_title(); ?></h1>
            <?php
                if(!empty($_SESSION['loggedin'])) {
                    // This is the theme section for logged in users only
                    get_page_content();
                    echo '<p>Du er logget ind</p>';
                    //echo $frontainersContent;
                }
                else {
                    echo '<p>Du skal logge ind for at se denne side</p>';
                   echo '<li ';
                       if($id == LOGIN_SLUG || $id == RECOVERY_SLUG)
                           echo 'class="active"';
                   echo ' ><a href="'.htmlspecialchars(get_section_url(LOGIN_SLUG)).'">Login</a></li>';
                }
            ?>
       </div>

       <div class="col-md-4">
          <?php get_component('sidenav'); ?>
       </div>
     </div>

<?php include('footer.inc.php'); ?>
When a user is not logged in then the page shows a message telling this page needs login and I have then taken and referenced the login_slug providing the link "Login" clicking that then returns the login page. When I login i get the accounts_slug. I can now click and access the original page.

However I would be great if I could directly show the login prompt and upon entering credentials going directly to the page I was at instead of getting the accounts page.

Any suggestions on this?

BTW I have made a da_DA language file, just need to validate it, then I will place it here if you want to include it in the plugin.
Reply
#13
(2016-04-12, 23:49:06)DesruX Wrote: However I would be great if I could directly show the login prompt and upon entering credentials going directly to the page I was at instead of getting the accounts page.

Any suggestions on this?

In this post you can see how to solve the problem:
http://get-simple.info/forums/showthread...3#pid55883
Reply
#14
(2016-04-12, 23:49:06)DesruX Wrote: BTW I have made a da_DA language file, just need to validate it, then I will place it here if you want to include it in the plugin.

Thank you very much for it!
Reply
#15
(2016-04-13, 00:20:00)Bigin Wrote:
(2016-04-12, 23:49:06)DesruX Wrote: BTW I have made a da_DA language file, just need to validate it, then I will place it here if you want to include it in the plugin.

Thank you very much for it!

Here is first pass, btw, would be nice if the website name could be included as a variable?:
Code:
<?php

$i18n = array (
      'title'    =>    'Frontainer'
    , 'description'    =>    'Frontend user management plugin (required ItemManager 2.2+)'
    , 'legend_form' => 'Login'
    , 'email_tv' => 'Email'
    , 'name_tv' => 'Brugernavn'
    , 'pass_tv' => 'Password'
    , 'submit_login' => 'Login'
    , 'forgot_pass' => 'Glemt password?'
    , 'forgot_pass_title' => 'Glemt password?'
    , 'err_login_empty_value' => 'Alle formularfelter skal være udfyldt!'
    , 'err_login_email_invalid' => 'Ugyldig email addresse!'
    , 'err_users_cat_notfound' => 'Kategorien Users blev ikke fundet!'
    , 'err_user_data' => 'Forkert authentifikations data'
    , 'welcome_header' => '[[user_name]] er nu logget ind!'
    , 'legend_signupform' => 'Opret bruger'
    , 'submit_signup' => 'Skab konto'
    , 'user_name' => 'Brugernavn'
    , 'err_user_data_exists' => 'Denne email er allerede registeret hos en anden bruger!'
    , 'err_maximum_users' => 'Max antal brugere nået.'
    , 'err_required_field' => 'Alle formularfelter skal være udfyldt!'
    , 'err_input_min_length' => 'Fejl i formularfelt, antal tegn: "[[fieldname]]" skal være på minimum [[count]] tegn!'
    , 'err_input_max_length' => 'Fejl i formularfelt, antal tegn: "[[fieldname]]" skal være under [[count]] tegn!'
    , 'err_input_incomplete' => 'Fejl i formularfelt: "[[fieldname]]" er ikke udfyldt korrekt!'
    , 'err_input_comparison' => 'Fejl i formularfelt: "[[fieldname]]" matcher ikke!'
    , 'err_input_format' => 'Fejl: Ugyldigt format i "[[fieldname]]"!'
    , 'err_saving_user' => 'Fejl: I at gemme brugernavn!'
    , 'successfully_signup' => 'Brugernavn registeret!'
    , 'link_text' => 'Efter at have gennemført aktivering, tryk på linket for at logge ind på din konto:'
    , 'link_activated' => 'Tryk på linket for at logge ind på din konto:'
    , 'successfully_signup_msg' => 'Du vil modtage en email med aktiverings kode for at bekræfte din konto.'
    , 'account_created' => 'Din konto er oprettet!'
    , 'account_activated' => 'Din konto er aktiveret!'
    , 'err_cannot_sent' => 'Beskeden kunne ikke sendes!'
    , 'activation_email' => "Hej [[name]], \r\n\r\nDin konto til [[website-title]] er nu oprettet, men mangler at blive aktiveret.\r\nFor at aktivere din email adresse skal du trykke på nedenstående link:\r\n\r\nAktiverings link: [[link_address]]"
    , 'activation_email_subject' => 'Email verifikation'
    , 'already_registered' => 'Allerede registeret?'
    , 'err_user_disabled' => 'Din konto er midlertidigt deaktiveret eller ikke aktiveret endnu!'
    , 'err_data_incomplete' => 'Aktiverings data er ukomplet!'
    , 'err_account_activated' => 'Din konto er allerede aktiveret!'
    , 'err_activating_user' => 'Fejl i aktivering!'
    , 'submit_recovery' => 'Indsend'
    , 'legend_recovery' => 'Nulstil password'
    , 'err_recovery_value' => 'Intast venligst en gyldig email addresse!'
    , 'password_reset_subject' => 'Anmodning om nulstilling af password sent'
    , 'reset_password_email' => "Hej [[name]],\r\n\r\nDer er anmodet om nulstilling af passwordet til [[website-title]] for brugerkontien tilknyttet email adressen [[email]]\r\nFor at nustille password, følg nedenstående link:\r\n\r\n[[link_address]]\r\n\r\nHvis du ikke har lavet denne anmodning, kan du ignorere denne email."
    , 'err_email_recovery' => 'Det var ikke muligt at finde en konto med den information.'
    , 'recovery_email_sent' => 'Check din email'
    , 'link_recovery' => 'Der er sent en email. Tryk på linket i emailen for at nulstille dit password.'
    , 'err_recovery_data' => 'Fejl: Ugyldig genskabelses data!'
    , 'err_recovery_notrequested' => 'Du har ikke anmodet genskabelses data'
    , 'err_time_expired' => 'Din genskabelses nøgle er udløbet; anmod om en ny!'
    , 'err_recovery_key_notmatch' => 'Genskabelses nøglen matcher ikke!'
    , 'legend_resetform' => 'Password nulstillet'
    , 'reset_pass_tv' => 'Nyt password'
    , 'reset_confirm_tv' => 'Bekræft password'
    , 'submit_reset' => 'Nulstil password'
    , 'reset_pass_notmatch' => 'Password og bekræftelses password matcher ikke.'
    , 'successfully_reset' => 'Dine konto instillinger er opdateret!'
    , 'settings_header' => 'Frontainer Instillinger'
    , 'email_from' => 'Fra Email'
    , 'email_from_info' => 'Email addressen frontainer sender emails fra'
    , 'email_to' => 'Svar-til Email'
    , 'email_to_info' => 'Email addressen som bruges til svar'
    , 'settings_sitename' => 'Hjemmeside navn'
    , 'successfully_saved_settings' => '<div class="updated">Instillingerne er blevet gemt.</div>'
    , 'settings_savebutton' => 'Gem'
);
Reply
#16
(2016-04-13, 00:17:33)Bigin Wrote:
(2016-04-12, 23:49:06)DesruX Wrote: However I would be great if I could directly show the login prompt and upon entering credentials going directly to the page I was at instead of getting the accounts page.

Any suggestions on this?

In this post you can see how to solve the problem:
http://get-simple.info/forums/showthread...3#pid55883

Thanks for pointing me in the right direction, I will try to follow that guide!
BTW, is there anyway use the username instead of the email address for login? For the majority of the use-cases it will be a shared login, changed once in a while. I tried to understand where the checks for the prompt are defined. Guess it is in the templates for the login slug?

BR
Reply
#17
(2016-04-13, 00:36:22)DesruX Wrote: BTW, is there anyway use the username instead of the email address for login? For the majority of the use-cases it will be a shared login, changed once in a while. I tried to understand where the checks for the prompt are defined. Guess it is in the templates for the login slug?
BR

This option is not built-in, but you can simple replace some $data['email'] with $data['name'] under plugins/frontainer/usersignup.class.php and change the email-input in your plugins/frontainer/tpl/login.signup.im.tpl file to text-field. After that you can replace some "eMail's" by "Username" in your language file.

You can download the modified files also here: http://ehret-studio.com/assets/documents...hanges.zip
Just replace your originals (do not forget backup existing original files), the language file is't present.
Reply
#18
(2016-04-12, 17:41:37)Bigin Wrote: Hello,
creating a password protected page by Frontainer is easier than you might think:
Let's say that your have a secret page with the slug "private" with some subpages and you would like to restrict access to for not-logged in users. So all you have to do is to add following code lines to the template.php file, right after the
"$content = frontainer_get_content()" function call:



PHP Code:
// get the current page slug
$slug get_page_slug(false);
// and the page parent slug
$parent get_parent(false);
if(
$slug == 'private' || $parent == 'private')
{
 
// The user is not logged in
 
if(empty($_SESSION['loggedin'])) {
 
// Redirect to the login page
 
header('Location: ' htmlspecialchars($SITEURL.'login/'));
 exit();
 }


If you don't really want to use the Frontainer's standard "account" page and after a successful login the user should be redirected to a private page you created, you could just add a redirect line to the Frontier’s loggedin.php file at the end of the "build_user_area()" function:



PHP Code:
header('Location: ' htmlspecialchars($manager->getSiteUrl().'/private/'));
exit(); 

Great thanks, that works! Regarding the last part in the loggedin.php I was thinking that instead of hardcoding a landing page in the loggedin.php I could pass it a page url variable of the page I was trying to access before the login redirect.

I placed this in the beginning of my template.php:
Code:
<?php
if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
if(!isset($_SESSION)){session_start();}
// Frontainer call
$frontainersContent = frontainer_get_content();

// get the current page slug
$slug = get_page_slug(false);
// and the page parent slug
$parent = get_parent(false);
// get the page url
$pageurl = get_page_url($echo=true);

if($slug == 'for-beboere' || $parent == 'for-beboere'){
// The user is not logged in
if(empty($_SESSION['loggedin'])) {
// Redirect to the login page
header('Location: ' . htmlspecialchars($SITEURL.'user-account/login/'));
exit();
}
}

And then I tried to add this to the loggedin.php:

Code:
//////////   Your can put your content here ////////////

//header('Location: ' . htmlspecialchars($manager->getSiteUrl().'/for-beboere/'));
header('Location: ' . htmlspecialchars($manager->$pageurl));
exit();
But I get a site 500 error, so I am guessing that the variable is not passed on when the loggedin.php is parsed. I suspect there is a way to do it, any suggestions?

PS: Thanks for taking the time to provide a new variant of the plugin using account name instead of email for login!

BR
Reply
#19
PHP Code:
$pageurl get_page_url(true); 

You'll need to pass the "$pageurl" variable to the build_user_area() function, but this will not work, because you are in "private" page. You'll lose variable under "login", since your redirects flow is as follows:
Code:
         
            redirect             submit                 redirect
[ private ] ---------> [ login ] ----------> [ accounts ] ------> [ private ]


The simplest thing you can do is to store your redirection url in a session, then call it under build_user_area() function.

in private-page:
Code:
$_SESSION['referer'] = get_page_url(true);

in build_user_area() (accounts-page):
Code:
header('Location: ' . htmlspecialchars($_SESSION['referer']));
Reply
#20
(2016-04-12, 17:41:37)Bigin Wrote: Hello,
creating a password protected page by Frontainer is easier than you might think:
Let's say that your have a secret page with the slug "private" with some subpages and you would like to restrict access to for not-logged in users. So all you have to do is to add following code lines to the template.php file, right after the
"$content = frontainer_get_content()" function call:


PHP Code:
// get the current page slug
$slug get_page_slug(false);
// and the page parent slug
$parent get_parent(false);
if(
$slug == 'private' || $parent == 'private')
{
    
// The user is not logged in
    
if(empty($_SESSION['loggedin'])) {
        
// Redirect to the login page
        
header('Location: ' htmlspecialchars($SITEURL.'login/'));
        exit();
    }


If you don't really want to use the Frontainer's standard "account" page and after a successful login the user should be redirected to a private page you created, you could just add a redirect line to the Frontier’s loggedin.php file at the end of the "build_user_area()" function:


PHP Code:
header('Location: ' htmlspecialchars($manager->getSiteUrl().'/private/'));
exit(); 

(2016-04-13, 05:25:05)Bigin Wrote: That will not work:

(2016-04-13, 04:24:49)DesruX Wrote:
PHP Code:
$pageurl get_page_url($echo=true); 

rather use:

PHP Code:
$pageurl get_page_url(true); 

You'll need to pass the "$pageurl" variable to the build_user_area() function, but this will not work because you are under "private". You'll lose variable under "login", since your redirects flow is as follows:

Code:
         
            redirect             submit                 redirect
[ private ] ---------> [ login ] ----------> [ accounts ] ------> [ private ]


The simplest thing you can do is to store your redirection url in a session, then call it under build_user_area() function.

in private page:

Code:
$_SESSION['referer'] = get_page_url(true);

in build_user_area():

Code:
header('Location: ' . htmlspecialchars($_SESSION['referer']));

Yes - heh I had actually just managed to change my attempt in the template to the following when an email ticked in with your update to the forumSmile :
Code:
$_SESSION["requestedpageurl"] = get_page_url($echo=true);
 And use:
Code:
    header('Location: ' . htmlspecialchars($_SESSION["requestedpageurl"]));
In the loggedin.php. And it works! Should I unset the variable at some point or should that be okay as it is?

regarding "get_page_url($echo=true)" I was also unsure after looking at http://get-simple.info/wiki/themes:template_tags.
Reply
#21
(2016-04-13, 05:32:45)DesruX Wrote: regarding get_page_url($echo=true) I was also unsure after looking at http://get-simple.info/wiki/themes:template_tags.

That works too, but it's ugly and I was for a moment shocked and I have my post edited after creation, but it was already too late ;-)

You can unset session before redirect if you want, but using session in my opinion more a quick fix then a really clean technical solution.
Reply
#22
Great!

I actually have a completely other issue, I cannot get frontainer to use the da_DA (or should it be da_DK) language file that I added. I think it is a general problem I have, as I have the problem with at least one more plugin. The admin panel works fine with the language changing based on my admin users language settings.

I have tried to follow the guides from i18n on updating my template (Bootstrap 3) but I have failed in finding the missing element.
I have set my default language for pages to "da". I most likely will only have one language for now so I have not changed page names.

Any pointers, known issues?

Best regards,
Reply
#23
Hello,
Hmm... Frontainer's multilingual function current supports only admin area.

However, it's easy to change, by hardcoding the language strings into the template files under plugins/frontainer/tpl/. Then you can use I18n's global variable "$language" to determine which templates requires loading.

The language placeholder in Frontainer's template files always begin with "lang_", example: [[lang_legend_loginform]].
To make it multilingual, just create a new folders "da", "it", etc under "plugins/frontainer/tpl/" directory, copy and paste all template files in your folders and change hardcoded strings into corresponding languages.

Open "plugins/frontainer.php" file and delete the line at the top of the file:
Code:
define('FR_TEMPLATE_DIR', GSPLUGINPATH.'/frontainer/tpl/');


Modify first line of the "frontainer_get_content()" function by adding $language (in same file):

Code:
global $fronainer_file, $fc, $language;


Next, add following lines for the same function:

Code:
// templates directory
if($language != I18N_DEFAULT_LANGUAGE)
    define('FR_TEMPLATE_DIR', GSPLUGINPATH.'/frontainer/tpl/'.substr($language, 0, 2).'/');
else
    define('FR_TEMPLATE_DIR', GSPLUGINPATH.'/frontainer/tpl/');


Then, search for "frontainer_setup()" function in the same file and add this line at the top of it:

Code:
defined('FR_TEMPLATE_DIR') or define('FR_TEMPLATE_DIR', GSPLUGINPATH.'/frontainer/tpl/');

that is all
Reply
#24
Or you can even use language files if you prefer:

Code:
if($language != I18N_DEFAULT_LANGUAGE) {
   i18n_merge($fronainer_file, substr($language, 0, 2));
}
Reply
#25
Hi,

i'm using Frontainer tu manage my users.

i need to display Users informations about 1 user and for that i do :

Code:
$imanager = imanager();
$user = $imanager->getItem('slug=Users', $userid );
Code:
foreach ($user->fields as $data) {

   if (isset($data->value)) {

       echo '
           <tr>
               <th>' . $data->label . '</th>
               <td>' . $data->value . '</td>
           </tr>
       ';

   }

}

But with this solution datas are displaying without filtering on position and i don't know how to retrieve datas filtering on position.

If you have any idea.
Reply




Users browsing this thread: 1 Guest(s)