WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: hanp on February 16, 2010, 12:43:43 PM

Title: login redirect to private page
Post by: hanp on February 16, 2010, 12:43:43 PM
Searching the www I found the flw. page with a solution for a login and a redirect to a private page:

http://www.escpro.de/esc/posts/benutzer-auf-private-seite-weiterleiten-132.php (http://www.escpro.de/esc/posts/benutzer-auf-private-seite-weiterleiten-132.php)

flw. I made a try to translate it to English

Users redirect to private page


Who would like to offer its users in WebsiteBaker an individual or group-page, Can as explained as follows redirect its users directly to his personal page( instead of the first beeing forwarded to the default WebsiteBaker home page.


For registration, we use the normal WebsiteBaker login mask, with a redirect to a hidden intermediate page (in this example wbuser.php)

This for example could look like this: (The page wbuser.php we set on the visibility: hidden)

<?php if(FRONTEND_LOGIN AND !$admin->is_authenticated()) {
                    $page = 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
                    ?>
<form name="login" action="<?php echo LOGIN_URL; ?>?redirect=<?php echo WB_URL; echo'/pages/'; echo 'wbuser.php';?>" method="post">
<fieldset class="topbox">
<legend><?php echo $TEXT['LOGIN']; ?></legend>
<fieldset class="topbox">
<div class="topboxbody">
<label for="username"><?php echo $TEXT['USERNAME']; ?>:</label>
<input type="text" name="username" id="username" class="text" />
<label for="password"><?php echo $TEXT['PASSWORD']; ?>:</label>
<input type="password" name="password" id="password" class="text" />
<input type="submit" name="submit" value="<?php echo $TEXT['LOGIN']; ?>" class="submit" /><br />
<a href="<?php echo FORGOT_URL; ?>"><?php echo $TEXT['FORGOT_DETAILS']; ?></a><br />
</div>
</fieldset>
</form>

What does this login in the template? As we have previously don't have a username, we redirect the user after te login to the page "mydomain.de/pages/wbuser.php.

Redirect the user to his personal page!

Now that the user is located on wbuser.php  we know his username and we can use it.
Now of course we also need to adapt this page the way the user is forwarded  to his personal page.
This we will obtain creating  a Code section on the wbuser.php page and introduce the following code:

echo'<meta http-equiv="refresh" content="5; url=';
echo WB_URL; echo'/pages/'; echo $admin->get_display_name(); echo '.php';
echo'">';


The user will now be redirected,  after waiting 5 seconds ("content"= 5) , to the page with his username.
In the example: www.mydomain.de / pages / myusername.php

To the  personal page, we can use different redirect types .
For example: over a php location or a redirect over a Meta function.

Group Login

Who wants to redirect the user  to a grouppage can use the variable $ group_name and redirect  the user from group "family" to the page "family".

Example WebsiteBaker Login redirect for groups:

echo'<meta http-equiv="refresh" content="5; url=';
echo WB_URL; echo'/pages/'; echo $admin->get_group_name(); echo '.php';
echo'">';

Alternative for redirection over  Location:

<?php
header('location: www.meine.domain.de/pages/username.php');
exit;
?>

As I am a nerd in PHP coding is ther someone who could help to translate the flw part to code so it can be used in a code page

<?php if(FRONTEND_LOGIN AND !$admin->is_authenticated()) {
                    $page = 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
                    ?>
<form name="login" action="<?php echo LOGIN_URL; ?>?redirect=<?php echo WB_URL; echo'/pages/'; echo 'wbuser.php';?>" method="post">
<fieldset class="topbox">
<legend><?php echo $TEXT['LOGIN']; ?></legend>
<fieldset class="topbox">
<div class="topboxbody">
<label for="username"><?php echo $TEXT['USERNAME']; ?>:</label>
<input type="text" name="username" id="username" class="text" />
<label for="password"><?php echo $TEXT['PASSWORD']; ?>:</label>
<input type="password" name="password" id="password" class="text" />
<input type="submit" name="submit" value="<?php echo $TEXT['LOGIN']; ?>" class="submit" /><br />
<a href="<?php echo FORGOT_URL; ?>"><?php echo $TEXT['FORGOT_DETAILS']; ?></a><br />
</div>
</fieldset>
</form>
Title: Re: login redirect to private page
Post by: crnogorac081 on February 16, 2010, 02:06:57 PM
cool, looks nice, I will test this..

thanks for sharing !
Title: Re: login redirect to private page
Post by: pcwacht on February 16, 2010, 02:55:27 PM
Code: [Select]
<?php 
if(FRONTEND_LOGIN AND !$admin->is_authenticated()) {
   
$page = &#39;http://&#39; .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo &#39;<form name="login" action="&#39;.LOGIN_URL.&#39;?redirect=&#39;.WB_URL.&#39;/pages/wbuser.php" method="post">&#39;;
echo &#39;  <fieldset class="topbox"><legend>&#39;.$TEXT[&#39;LOGIN&#39;].&#39;></legend>&#39;;
echo &#39;  <fieldset class="topbox">&#39;;
echo &#39;    <div class="topboxbody">&#39;;
echo &#39;      <label for="username">&#39;.$TEXT[&#39;USERNAME&#39;].&#39;:</label>&#39;;
echo &#39;      <input type="text" name="username" id="username" class="text" />&#39;;
echo &#39;      <label for="password">&#39;.$TEXT[&#39;PASSWORD&#39;].&#39;:</label>&#39;;
echo &#39;      <input type="password" name="password" id="password" class="text" />&#39;;
echo &#39;      <input type="submit" name="submit" value="&#39;.$TEXT[&#39;LOGIN&#39;].&#39;" class="submit" /><br />&#39;;
echo &#39;      <a href="&#39;.FORGOT_URL.&#39;">&#39;.$TEXT[&#39;FORGOT_DETAILS&#39;].&#39;></a><br />&#39;;
echo &#39;    </div>&#39;;
echo &#39;  </fieldset>&#39;;
echo &#39;</form>&#39;;
?>


Didn't test this buit I'm sure it will help you get started.
Remark, a closing fieldset is missing in your source and in my code ;)

John
Title: Re: login redirect to private page
Post by: hanp on February 16, 2010, 07:02:53 PM
Gracias for your reply
When I copy this to the "code area" of a normal page it doesn't work


Code: [Select]
<?php 
if(FRONTEND_LOGIN AND !$admin->is_authenticated()) {
   
$page = &#39;http://&#39; .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo &#39;<form name="login" action="&#39;.LOGIN_URL.&#39;?redirect=&#39;.WB_URL.&#39;/pages/wbuser.php" method="post">&#39;;
echo &#39;  <fieldset class="topbox"><legend>&#39;.$TEXT[&#39;LOGIN&#39;].&#39;></legend>&#39;;
echo &#39;  <fieldset class="topbox">&#39;;
echo &#39;    <div class="topboxbody">&#39;;
echo &#39;      <label for="username">&#39;.$TEXT[&#39;USERNAME&#39;].&#39;:</label>&#39;;
echo &#39;      <input type="text" name="username" id="username" class="text" />&#39;;
echo &#39;      <label for="password">&#39;.$TEXT[&#39;PASSWORD&#39;].&#39;:</label>&#39;;
echo &#39;      <input type="password" name="password" id="password" class="text" />&#39;;
echo &#39;      <input type="submit" name="submit" value="&#39;.$TEXT[&#39;LOGIN&#39;].&#39;" class="submit" /><br />&#39;;
echo &#39;      <a href="&#39;.FORGOT_URL.&#39;">&#39;.$TEXT[&#39;FORGOT_DETAILS&#39;].&#39;></a><br />&#39;;
echo &#39;    </div>&#39;;
echo &#39;  </fieldset>&#39;;
echo &#39;</form>&#39;;
?>


Didn't test this buit I'm sure it will help you get started.
Remark, a closing fieldset is missing in your source and in my code ;)

John
Title: Re: login redirect to private page
Post by: seagull on February 16, 2010, 08:57:38 PM
The '}" is missing at the end of the code en remember with this code if you are logged in as admin it does not show.

Jan


Quote
<?php
if(FRONTEND_LOGIN AND !$admin->is_authenticated()) {
   $page = 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo '<form name="login" action="'.LOGIN_URL.'?redirect='.WB_URL.'/pages/wbuser.php" method="post">';
echo '  <fieldset class="topbox"><legend>'.$TEXT['LOGIN'].'></legend>';
echo '  <fieldset class="topbox">';
echo '    <div class="topboxbody">';
echo '      <label for="username">'.$TEXT['USERNAME'].':</label>';
echo '      <input type="text" name="username" id="username" class="text" />';
echo '      <label for="password">'.$TEXT['PASSWORD'].':</label>';
echo '      <input type="password" name="password" id="password" class="text" />';
echo '      <input type="submit" name="submit" value="'.$TEXT['LOGIN'].'" class="submit" /><br />';
echo '      <a href="'.FORGOT_URL.'">'.$TEXT['FORGOT_DETAILS'].'></a><br />';
echo '    </div>';
echo '  </fieldset>';
echo '</form>';
}
?>
Title: Re: login redirect to private page
Post by: foonji on March 25, 2010, 10:17:12 AM
Did anyone get this working?
Title: Re: login redirect to private page
Post by: KP on April 06, 2012, 07:01:28 PM
I'd be very interested to know about this as well. any new developments? does this work as is?

I'm a graphic designer and not a developer, so any help would be appreciated.

thanks,
kevin
Title: Re: login redirect to private page
Post by: lausianne on April 26, 2012, 10:07:16 AM
Works fine. In login_form.php I simply exchanged the original form line
Code: [Select]
<form action="<?php echo WB_URL.'/account/login.php'?>" method="post">by
Code: [Select]
<?php 
if(FRONTEND_LOGIN AND !$admin->is_authenticated()) {
   
$page 'http://' .$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo '<form name="login" action="'.LOGIN_URL.'?redirect='.WB_URL.'/pages/wbuser.php" method="post">';
} else {
echo '<form action="'.WB_URL.'/account/login.php>" method="post">';
}
?>
And then it did not work, still directing to home, because of this:
Code: [Select]
<p style="display:none;"><input type="hidden" name="redirect" value="<?php echo $thisApp->redirect_url;?>" /></p>Needed to be replaced by this:
Code: [Select]
<p style="display:none;"><input type="hidden" name="redirect" value="<?php echo WB_URL.'/pages/wbuser.php'?>" /></p>Done. Replace wbuser.php by a page of your choice.

Cheers, Ralf.

pm. Seagulls code also worked right away, but I wanted to keep the original design.
ppm. If you don't find the file to change, it's in the folder "account", of course 8-)