Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Login On External Page  (Read 6908 times)

0 Members and 2 Guests are viewing this topic.

Titan85

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Login On External Page
« on: June 15, 2006, 03:43:17 am »

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.
« Last Edit: June 16, 2006, 10:43:06 am by GauGau »
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Login On External Page
« Reply #1 on: June 15, 2006, 09:41:49 am »

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
Code: [Select]
<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
« Last Edit: June 15, 2006, 05:05:17 pm by bmossavari »
Logged
‍I don't answer to PM with support question
Please post your issue to related board

Titan85

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Login On External Page
« Reply #2 on: June 15, 2006, 04:33:47 pm »

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
Code: [Select]
<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
Logged

majay

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Login On External Page
« Reply #3 on: July 03, 2006, 02:58:05 am »

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!
« Last Edit: July 03, 2006, 03:11:22 am by Morgane »
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Login On External Page
« Reply #4 on: July 03, 2006, 05:48:29 am »

- 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
Code: [Select]
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
Code: [Select]
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
« Last Edit: July 03, 2006, 10:09:19 am by bmossavari »
Logged
‍I don't answer to PM with support question
Please post your issue to related board

majay

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Login On External Page
« Reply #5 on: July 03, 2006, 09:54:01 am »

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?

Code: [Select]
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.
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Login On External Page
« Reply #6 on: July 03, 2006, 10:02:36 am »

- 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
« Last Edit: July 03, 2006, 10:14:29 am by bmossavari »
Logged
‍I don't answer to PM with support question
Please post your issue to related board

majay

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Login On External Page
« Reply #7 on: July 03, 2006, 02:57:52 pm »

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:
Code: [Select]
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.
« Last Edit: July 03, 2006, 04:15:10 pm by Morgane »
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Login On External Page
« Reply #8 on: July 03, 2006, 04:18:01 pm »

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
Code: [Select]
'{LOGIN_FORM}' => 'Hello '.USER_ID,
Logged
‍I don't answer to PM with support question
Please post your issue to related board

majay

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Login On External Page
« Reply #9 on: July 03, 2006, 05:21:31 pm »

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:
Code: [Select]
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.
Logged

Sami

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 3686
  • BMossavari
    • My Project
Re: Login On External Page
« Reply #10 on: July 03, 2006, 05:56:07 pm »

use this loggedin() instead of yours:
Code: [Select]
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;
}
Logged
‍I don't answer to PM with support question
Please post your issue to related board

majay

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Login On External Page
« Reply #11 on: July 03, 2006, 08:51:13 pm »

Wow, awesome, works like a charm, thanks!!!
Logged
Pages: [1]   Go Up
 

Page created in 0.029 seconds with 20 queries.