Login On External Page Login On External Page
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Login On External Page

Started by Titan85, June 15, 2006, 03:43:17 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Titan85

I have been trying to fugure out how to put a login box to the gallery on an external page (ex: the site homepage) and have had no luck. Is there a way to do this? I searched the forums but only found something about search forms on external pages.

Sami

#1
Yes , you can do this , you shuold just pass (post) username & password to cpg index.php login.php file here is an realy simple example of the box

<table width="180" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td bgcolor="#000000"><table width="100%" border="0" cellspacing="0" cellpadding="4">
      <tr>
        <td bgcolor="#FFFFFF"> <b>!</b> </td>
        <td width="100%"><font color="#CCCCCC"> C.P.G. Log In </font></td>
      </tr>
    </table></td>
  </tr>
  <tr>
     <form action="login.php" method="post" name="loginbox">
      <td width="100%" bgcolor="#CCCCCC" colspan="2"><p>Username:<br />
<input type="text" class="textinput" name="username" style="width: 95%" tabindex="1" />
Password:<br />
<input type="password" class="textinput" name="password" style="width: 95%" tabindex="2" />
Remember me:
<input name="remember_me" type="checkbox" class="checkbox" value="1" tabindex="3" /><br/>
<input name="submitted" type="submit" class="button" value="login" tabindex="4" />
</td>
    </form>
  </tr>
</table>

you should change the path of action properties of form to your path.

update: index.php=>login.php
‍I don't answer to PM with support question
Please post your issue to related board

Titan85

Quote from: bmossavari on June 15, 2006, 09:41:49 AM
Yes , you can do this , you shuold just pass (post) username & password to cpg index.php file here is an realy simple example of the box

<table width="180" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td bgcolor="#000000"><table width="100%" border="0" cellspacing="0" cellpadding="4">
      <tr>
        <td bgcolor="#FFFFFF"> <b>!</b> </td>
        <td width="100%"><font color="#CCCCCC"> C.P.G. Log In </font></td>
      </tr>
    </table></td>
  </tr>
  <tr>
     <form action="login.php" method="post" name="loginbox">
      <td width="100%" bgcolor="#CCCCCC" colspan="2"><p>Username:<br />
<input type="text" class="textinput" name="username" style="width: 95%" tabindex="1" />
Password:<br />
<input type="password" class="textinput" name="password" style="width: 95%" tabindex="2" />
Remember me:
<input name="remember_me" type="checkbox" class="checkbox" value="1" tabindex="3" /><br/>
<input name="submitted" type="submit" class="button" value="login" tabindex="4" />
</td>
    </form>
  </tr>
</table>

you should change the path of action properties of form to your path.
Thanks, got it all working  ;D

majay

#3
Hi,

Is there a way to hide the login form once the user is logged in? And say something like "Logged in as *username*", for instance?

I wanted to try the mod described here http://forum.coppermine-gallery.net/index.php?topic=17861.0
but it seems incompatible with CPG1.4.8. I tried one or two things that didn't work, but I'm afraid of messing up the entire code. I'm also not too keen on downloading Stramm's Mod pack, as I don't need all the mods available and as I have modified some of my CPG files. If there was a way around it, that would be great!

Thanks!

Sami

#4
- you can't ,If you were on External page
- if you want it on main page of gallery then you should
1.add this to your theme.php

function loginForm() {
  $loginFormHtml = <<<EOT
  <!-- Start standard table -->

<table align="center" width="600" cellspacing="1" cellpadding="0" class="maintable">
        <tr>
                <td class="tableh1" colspan="2"><h2>Enter your username and password to login</h2></td>
        </tr>
                 
                 
                  <tr>
                    <form action="login.php" method="post" name="loginbox">
                        <td class="tableb" width="40%">Username</td>
                        <td class="tableb" width="60%"><input type="text" class="textinput" name="username" style="width: 100%"></td>
                  </tr>
                  <tr>
                          <td class="tableb">Password</td>
                        <td class="tableb"><input type="password" class="textinput" name="password" style="width: 100%"></td>
                  </tr>
                  <tr>
                    <td colspan="2" align="center" class="tableb">Remember me <input name="remember_me" type="checkbox" class="checkbox" value="1"></td>

                  </tr>
                  <tr>
                    <td align="center" class="tablef"><a href="forgot_passwd.php" class="topmenu">I forgot my password</a></td>
                    <td align="left" class="tablef"><input name="submitted" type="submit" class="button" value="Login"></td>
                    </form>
                  </tr>
</table>
<!-- End standard table -->
EOT;
  return $loginFormHtml;
}


2. and then if you don't have a pageheader() function , copy it from themes/sample/theme.php
3. and  add your {LOGIN_FORM} to $template_vars, the function should be look like this

function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

        $charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
        header("Content-Type: text/html; charset=$charset");
    user_save_profile();

if(!USER_ID){
    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $charset,
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{LOGIN_FORM}' => loginForm() ,
        );
} else {
         $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{LOGIN_FORM}' => "",
         );
    }
    echo template_eval($template_header, $template_vars);
}

4.and then edit your template.html and put {LOGIN_FORM} where you want the form to be apear (it must be before {gallery},if you want to put it after {gallery} then you should change pagefooter() function instead of pageheader() )

Also there is a plugin (By Stramm) here
http://forum.coppermine-gallery.net/index.php?topic=33349.0
check it
‍I don't answer to PM with support question
Please post your issue to related board

majay

Thank you bmossavari. I tried the plugin but it didn't work. And I've tried adding the code you gave me in theme.php and template.html but yet no login form appears on the main gallery page.

This is what my theme.php looks like (I cut the irrelevant parts out to save space). Is there an EOT; bit missing somewhere? Or should I have copied the function pageheader() part at the beginning of the file rather than at the end?


define('THEME_HAS_NO_SYS_MENU_BUTTONS', 1);
define('THEME_HAS_NO_SUB_MENU_BUTTONS', 1);
define('THEME_IS_XHTML10_TRANSITIONAL',1);  // Remove this if you edit this template until
                                            // you have validated it. See docs/theme.htm.

// HTML template for sys menu
[...]
// HTML template for sub menu
[...]
// HTML template for gallery admin menu
[...]

function loginForm() {
  $loginFormHtml = <<<EOT
  <!-- Start standard table -->

<table align="center" width="600" cellspacing="1" cellpadding="0" class="maintable">
        <tr>
                <td class="tableh1" colspan="2"><h2>Enter your username and password to login</h2></td>
        </tr>
                 
                 
                  <tr>
                    <form action="login.php" method="post" name="loginbox">
                        <td class="tableb" width="40%">Username</td>
                        <td class="tableb" width="60%"><input type="text" class="textinput" name="username" style="width: 100%"></td>
                  </tr>
                  <tr>
                          <td class="tableb">Password</td>
                        <td class="tableb"><input type="password" class="textinput" name="password" style="width: 100%"></td>
                  </tr>
                  <tr>
                    <td colspan="2" align="center" class="tableb">Remember me <input name="remember_me" type="checkbox" class="checkbox" value="1"></td>

                  </tr>
                  <tr>
                    <td align="center" class="tablef"><a href="forgot_passwd.php" class="topmenu">I forgot my password</a></td>
                    <td align="left" class="tablef"><input name="submitted" type="submit" class="button" value="Login"></td>
                    </form>
                  </tr>
</table>
<!-- End standard table -->
EOT;
  return $loginFormHtml;
}

function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
    user_save_profile();

if(!USER_ID){
    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{LOGIN_FORM}' => loginForm() ,
        );
} else {
         $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{LOGIN_FORM}' => "",
         );
    }
    echo template_eval($template_header, $template_vars);
}



I've noticed that when I restore my theme.php to normal, the {LOGIN_FORM} tag appears above the admin menu, whereas when the function loginForm()  and function pageheader() parts are included, the tag doesn't appear at all.

Sami

#6
- link to your site please
okey your theme.php is looking fine (update note) , did you put {LOGIN_FORM} under template.html before {GALLERY}?
and if you know , you sholud log out to see the form ;)


Update :
I update pageheader() function on previuse answer , this is not related to your issue but please use new pageheader() for your future compatibility
‍I don't answer to PM with support question
Please post your issue to related board

majay

#7
Quote from: bmossavari on July 03, 2006, 10:02:36 AM
you sholud log out to see the form ;)


That didn't even occur to me, thanks a lot it works fine :)
However, when logged in would it be possible to add just a line that says "You are logged in as *username*" or "Welcome back", or anything to that effect? Or should I have a look at Stramm's plugin code for that?

Update: I tried to add some of Stramm's loginform plugin code, like this:
function loginForm() {
if (!USER_ID) {
  $loginFormHtml = <<<EOT
<form action="login.php" method="post" name="loginbox" style="margin:0px">
   <table class="mjjshots" align="center" border="0" width="440" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="80" align="center">
                       <b>Username :</b>
                    </td>
                    <td width="120" align="left">
                      <input type="text" class="textinput" name="username" style="width: 100px" />
                    </td>
                    <td width="240">
                  <a href="forgot_passwd.php">Lost Password</a>|<a href="register.php">Register</a>|<label for="remember_me">Remember me</label>
        <input name="remember_me" type="checkbox" class="checkbox" value="1" />
                    </td>
                </tr>
                <tr>
                    <td width="80" align="center">
                      <b>Password :</b>
                    </td>
                    <td width="120" align="left">
                       <input type="password" class="textinput" name="password" style="width: 100px" />
                    </td>
                    <td width="240">
                      <input name="submitted" type="submit" class="button" value="Login" />
                    </td>
                </tr>
            </table>
    </form>
EOT;
   } else {
$loginFormHtml = "<div align=\"center\" class=\"smallfont\">Welcome back <strong>".(USER_NAME)."</strong><br />";
}
  return $loginFormHtml;
}


And nothing appears when logged in. I'm definitely missing something here, but I wanted to give it a go.

Sami

personaly I didn't try stramm plugin but if you want a note for log in users then you should add that note to 2nd {LOGIN_FORM} under theme.php (the one after "else") your 2nd {LOGIN_FORM} should be like this after

'{LOGIN_FORM}' => 'Hello '.USER_ID,
‍I don't answer to PM with support question
Please post your issue to related board

majay

Thank you! That worked (I just changed User_id to User_name), the only thing is I don't see how to customise the style of it.

So based on what functions already existed, I tried adding a second function, for when people are logged in, called function loggedin() , like this:
function loginForm() {
  $loginFormHtml = <<<EOT
  <form action="login.php" method="post" name="loginbox" style="margin:0px">
   <table class="class" align="center" border="0" width="440" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="80" align="center">
                       <b>Username :</b>
                    </td>
                    <td width="120" align="left">
                      <input type="text" class="textinput" name="username" style="width: 100px" />
                    </td>
                    <td width="240">
                  <a href="forgot_passwd.php">Lost Password</a>|<a href="register.php">Register</a>|<label for="remember_me">Remember me</label>
        <input name="remember_me" type="checkbox" class="checkbox" value="1" />
                    </td>
                </tr>
                <tr>
                    <td width="80" align="center">
                      <b>Password :</b>
                    </td>
                    <td width="120" align="left">
                       <input type="password" class="textinput" name="password" style="width: 100px" />
                    </td>
                    <td width="240">
                      <input name="submitted" type="submit" class="button" value="Login" />
                    </td>
                </tr>
            </table>
    </form>
EOT;
  return $loginFormHtml;
}

function loggedin() {
  $loggedinHtml = <<<EOT
   <table class="class" border="0" width="360" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="120">
                       Welcome {USER_NAME}
                    </td>
                    <td width="240">
                  <a href="logout.php">Log me out</a>
                    </td>
                </tr>
            </table>
EOT;
  return $loggedinHtml;
}

function pageheader($section, $meta = '')
{
    global $CONFIG, $THEME_DIR;
    global $template_header, $lang_charset, $lang_text_dir;

    $custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);

    header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
    user_save_profile();

if(!USER_ID){
    $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{LOGIN_FORM}' => loginForm() ,
        );
} else {
         $template_vars = array('{LANG_DIR}' => $lang_text_dir,
        '{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
        '{CHARSET}' => $CONFIG['charset'] == 'language file' ? $lang_charset : $CONFIG['charset'],
        '{META}' => $meta,
        '{GAL_NAME}' => $CONFIG['gallery_name'],
        '{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
        '{SYS_MENU}' => theme_main_menu('sys_menu'),
        '{SUB_MENU}' => theme_main_menu('sub_menu'),
        '{ADMIN_MENU}' => theme_admin_mode_menu(),
        '{CUSTOM_HEADER}' => $custom_header,
        '{LOGIN_FORM}' => loggedin() ,
         );
    }
    echo template_eval($template_header, $template_vars);
}
     ?>


It works the way I wanted it to, except for the {USER_NAME} tag that I must have got wrong, as it won't display the actual username.

Sami

use this loggedin() instead of yours:

function loggedin() {
  $loggedinHtml = '<table class="class" border="0" width="360" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="120">
                       Welcome '.USER_NAME.'
                    </td>
                    <td width="240">
                  <a href="logout.php">Log me out</a>
                    </td>
                </tr>
            </table>';
  return $loggedinHtml;
}
‍I don't answer to PM with support question
Please post your issue to related board

majay

Wow, awesome, works like a charm, thanks!!!