Frontend loging in phpwcms

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
pyhavaim
Posts: 9
Joined: Thu 5. Aug 2004, 23:35
Location: Estonia

Frontend loging in phpwcms

Post by pyhavaim »

Since it seems to me that it takes ages to wait for frontend logging in phpwcms, I did it by myself, it is working and I hope this helps developers also to relase properly coded frontend logging :wink:
So lets get to the point.

1) modify index.php
uncomment on line 34

Code: Select all

 session_start();
2) make new php file and name it authorize.php and add following code in it. (ps this code is borrowed from login.php :oops: )

Code: Select all

<?php
if(isset($_POST['form_aktion']) && $_POST['form_aktion'] == 'login') {

	$login_passed = 0;
	$wcs_user = slweg(trim($_POST['form_loginname']));
	$wcs_pass = slweg(trim($_POST['form_password']));
	
	$sql_query =	"SELECT * FROM ".DB_PREPEND."phpwcms_user WHERE usr_login='".
					aporeplace($wcs_user)."' AND (usr_pass=PASSWORD('".
					aporeplace($wcs_pass)."') OR usr_pass='".
					aporeplace(md5($wcs_pass))."') AND usr_aktiv=1;";

	if($result = mysql_query($sql_query)) {
		if($row = mysql_fetch_array($result)) {
			$_SESSION["wcs_user"]			= $wcs_user;
			$_SESSION["wcs_pass"]			= $wcs_pass;
			$_SESSION["wcs_user_name"] 		= ($row["usr_name"]) ? $row["usr_name"] : $wcs_user;
			$_SESSION["wcs_user_id"]		= $row["usr_id"];
			$_SESSION["wcs_user_aktiv"]		= $row["usr_aktiv"];
			$_SESSION["wcs_user_rechte"]	= $row["usr_rechte"];
			$_SESSION["wcs_user_email"]		= $row["usr_email"];
			$_SESSION["wcs_user_avatar"]	= $row["usr_avatar"];
			$_SESSION["wcs_user_logtime"]	= time();
			$_SESSION["wcs_user_admin"]		= $row["usr_admin"];
			$_SESSION["wcs_user_thumb"]		= 1;
			if($row["usr_lang"]) {
				$_SESSION["wcs_user_lang"]	= $row["usr_lang"];
			}						
			$_SESSION["structure"]	= unserialize($row["usr_var_structure"]);
			$_SESSION["klapp"]		= unserialize($row["usr_var_privatefile"]);
			$_SESSION["pklapp"]		= unserialize($row["usr_var_publicfile"]);
			
			$login_passed = 1;	
			$_SESSION["frontend_user_in"]=true;	//changed this one
		}
		mysql_free_result($result);
	}	
}
?>


Then I made a custom form and named it frm_Login.php (also borrowed from login.php, just removed things I fought I don't need:? )

Code: Select all

<table border="0" cellpadding="0" cellspacing="0">
      <form name="login_formular" method="post" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>" autocomplete="off">
        <tr><td width="389" class="title"><?php echo $GLOBALS["template_default"]["login_text"]; ?></td></tr>
		<?php 
		if($err) {
			echo '<tr><td><img src="img/leer.gif" width="1" height="10"></td></tr>';
			echo '<tr><td class="error"><strong>'.$GLOBALS["template_default"]["login_error"].'</strong></td></tr>';
		}
		
		?>
        <tr><td><img src="img/leer.gif" width="1" height="12"></td></tr>
        <tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_username"] ?>:</td></tr>
        <tr><td><input name="form_loginname" type="text" id="form_loginname" class="f11b" style="width:250px;" size="30" maxlength="30" value="<?php echo html_specialchars($wcs_user); ?>"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
        <tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_userpass"] ?>:</td></tr>
        <tr><td><input name="form_password" type="password" id="form_password" class="f11b" style="width:250px;" size="30" maxlength="20"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="18"></td></tr>
        <tr><td><input name="Submit" type="submit" class="button10" value="<?php echo $GLOBALS["template_default"]["login_button"] ?>"><input name="form_aktion" type="hidden" id="form_aktion" value="login"></td></tr>
      </form>
    </table>
also I added some lines into include\inc_conf\conf.template_default.inc.php

Code: Select all

// login form template
$template_default["login_text"]				= "Please Log in";
$template_default["login_error"]			="Wrong password";
$template_default["login_username"]			="Username";
$template_default["login_userpass"]			="Password";
$template_default["login_button"]			="Login";
and now the critical part !!!
I had to change include\inc_front\content_func.inc.php
Find out code like

Code: Select all

$content["all"] = str_replace('{CONTENT}', $content["main"], $content["all"]);
and add there code which is cheking from site structure frontend menu status: is this visible for users logged on only.

Code: Select all

$cat=$content["cat_id"];
if($content["struct"][$cat]["acat_regonly"]==1)
{
//echo "Private area!!!";
	include_once("authorize.php");
	if(!$_SESSION["frontend_user_in"]) {
		
		//show log in form, instead of page content";
		$content["main"]="{PHP:frm_Login.php}";
	}
}
$content["all"] = str_replace('{CONTENT}', $content["main"], $content["all"]);
now there is a small shortage: when you are'nt logged in meny does not show this item. So basically you have to add manually some link to some yours private page.

well I hope this helped someone :?
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Pyhavaim,

For your second post, that is pretty impressive. i have definitely bookmarked it. I think a lot are awaiting Oliver's 1.2 release, which will likely have a frontend strategy...and knowing him..it will be well thought out. But for the time being... I salute your efforts.....You have good grasp of the PHP side of wcms.....

Cheers,
jsw_nz(john)
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Hi pyhavaim,

hi John,

I made all the addings and changings, uploaded it and nothing happens, nothing different to see?
:shock:

I placed the authorize.php, frm_Login.php into root of wcms installation.

Where is the form to login?
Can you give me a hint? Would be very kind.
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
Pappnase

Post by Pappnase »

hallo tom

wenn ich das richtig sehe musst du diese seite irgendwo einbinden!

Code: Select all

<table border="0" cellpadding="0" cellspacing="0">
      <form name="login_formular" method="post" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>" autocomplete="off">
        <tr><td width="389" class="title"><?php echo $GLOBALS["template_default"]["login_text"]; ?></td></tr>
      <?php
      if($err) {
         echo '<tr><td><img src="img/leer.gif" width="1" height="10"></td></tr>';
         echo '<tr><td class="error"><strong>'.$GLOBALS["template_default"]["login_error"].'</strong></td></tr>';
      }
      
      ?>
        <tr><td><img src="img/leer.gif" width="1" height="12"></td></tr>
        <tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_username"] ?>:</td></tr>
        <tr><td><input name="form_loginname" type="text" id="form_loginname" class="f11b" style="width:250px;" size="30" maxlength="30" value="<?php echo html_specialchars($wcs_user); ?>"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
        <tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_userpass"] ?>:</td></tr>
        <tr><td><input name="form_password" type="password" id="form_password" class="f11b" style="width:250px;" size="30" maxlength="20"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="18"></td></tr>
        <tr><td><input name="Submit" type="submit" class="button10" value="<?php echo $GLOBALS["template_default"]["login_button"] ?>"><input name="form_aktion" type="hidden" id="form_aktion" value="login"></td></tr>
      </form>
    </table> 
vielleicht als html contentpart!?
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

hi pappnase,

i also tried this, never works.
everytime i get a parse errro by using a "<" inside the code.

Don't know why and how...

But I think you need it saved separetly, because this code:

Code: Select all

$cat=$content["cat_id"];
if($content["struct"][$cat]["acat_regonly"]==1)
{
//echo "Private area!!!";
   include_once("authorize.php");
   if(!$_SESSION["frontend_user_in"]) {
      
      //show log in form, instead of page content";
      $content["main"]="{PHP:frm_Login.php}";
   }
}
$content["all"] = str_replace('{CONTENT}', $content["main"], $content["all"]); 
See it? opens php external...
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
duergner
Posts: 139
Joined: Fri 14. May 2004, 12:10

Post by duergner »

This hack does not enable the only for logged in users visable pages in the menu AFAI can say by reviewing it.

So you would have to link to these page by yourself.
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

hi duergner,

can you give me a briefly short detailled description?

I made a new structure level called "login", put an artikel inside and added contentpart Add external content and wrote http://www.domain.de/frm_Login.php.

I just copied the code as displayed into a blank page, but still got error with unexpected ">" in code.


Parse error: parse error, unexpected '<' in /www/htdocs/xxxx/frm_Login.php on line 4

My other question is: From which entries does the code get the correct members? have they at first been set up anyware.

I would like to be happy to had a complety instruction, so I hope the Editor will see and help soon :-)
Last edited by cyrano on Mon 11. Oct 2004, 13:08, edited 1 time in total.
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

ok, I still get the login form displayed.

where are users stored?
Have I make users as Backend users and then use this accounts to login?

How to set them now to a private area?
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
duergner
Posts: 139
Joined: Fri 14. May 2004, 12:10

Post by duergner »

cyrano wrote:where are users stored?
Have I make users as Backend users and then use this accounts to login?
Seems so when looking in the code. But I can't say from the first look how he will deny backend login for these users.
cyrano wrote:How to set them now to a private area?
I my opinion you have to create a private article/structure place articles inside there. After that add a link to that article/structure from somewhere of the public site. Wen one now clicks on that link he will automatically be redirected to the login form and afterwards to the desired article.
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Hi duergner,

thank you for writing again.

Jepp now i have made a structure level and put an article inside and it redirects right to the login - jeah!

and when typing for e.g. the admins name I will redirected to the article - yeah again :-)

But I got an error like:

Code: Select all

<br /><b>Fatal error</b>:  Call to undefined function:  html_specialchars() in <b>/www/htdocs/xxxx/frm_Login.php</b> on line <b>13</b><br /><!-- stopprint --></div></td><td valign=
I still use the code shown above, but see in a editor, that the argument for the php htmlencoding is not highlighted well.


so I see one text input field again containing inside this error message...

Code: Select all

<table border="0" cellpadding="0" cellspacing="0">
      <form name="login_formular" method="post" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>" autocomplete="off">
        <tr><td width="389" class="title"><?php echo $GLOBALS["template_default"]["login_text"]; ?></td></tr>
      <?php
      if($err) {
         echo '<tr><td><img src="img/leer.gif" width="1" height="10"></td></tr>';
         echo '<tr><td class="error"><strong>'.$GLOBALS["template_default"]["login_error"].'</strong></td></tr>';
      }
     ?>
        <tr><td><img src="img/leer.gif" width="1" height="12"></td></tr>
        <tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_username"] ?>:</td></tr>
        <tr><td><input name="form_loginname" type="text" id="form_loginname" class="f11b" style="width:250px;" size="30" maxlength="30" value="<?php echo html_specialchars($wcs_user); ?>"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
        <tr><td class="v10"><?php echo $GLOBALS["template_default"]["login_userpass"] ?>:</td></tr>
        <tr><td><input name="form_password" type="password" id="form_password" class="f11b" style="width:250px;" size="30" maxlength="20"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="3"></td></tr>
        <tr><td><img src="img/leer.gif" width="1" height="18"></td></tr>
        <tr><td><input name="Submit" type="submit" class="button10" value="<?php echo $GLOBALS["template_default"]["login_button"] ?>"><input name="form_aktion" type="hidden" id="form_aktion" value="login"></td></tr>
      </form>
    </table>
Does someone can have a look on this with better php knowledge?

Thanks in advance
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Now Working

Post by cyrano »

Hi to all,

now it works, also with the htmlcharacters..It was a structure level eror ( better made by me :oops: ).

so I now still get into pages after logging.

Thank you to all for leading my brain :-)
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
ragi
Posts: 44
Joined: Wed 22. Sep 2004, 09:31
Contact:

Post by ragi »

Hi cyrano

How did you solve the problem?

thanks
ragi
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

hi ragi,

all code mentioned at first works fine.

I had to make first a structure level, e.g. "logged_content", set the "frontend menu status:" to "hide", also not activate "visible" and "public", saved this.
Make a article within the structure level "logged_content", e.g. call them "login" and placea contentpart "external content" where placing the complete URL to the file "frm_Login.php" ->http://www.yourdomain.com/frm_Login.php".

The files "frm_Login.php" and "authorize" must be placed in the root of your wcms installation!

Made a link to the Login with [ID logged_content] Login [/ID]. on an article which is public.
If you click now on the link "Login" you will be redirected to the Login (the file".

To get logged in you have to setup a new user in Admin-> "user administration". give no admin abilities, but make sure, that user can log in.

Then save all and you will be able to log in.

well described?
Otherwise ask again please.
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
ragi
Posts: 44
Joined: Wed 22. Sep 2004, 09:31
Contact:

Post by ragi »

Hi cyrano

Thanks for your well description.
Now it work all fine.

I´ll try the next days, if i can do it for the user so that they couldn´t login in the backend panel.

I´ll post it here if I can do it

ragi
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

hi ragi,

thank you for your reply.

nice that it works well.

o yes, this would be great to cut them using the backend.

I'am looking forward to your posting :-)
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
Post Reply