Author Topic: How can I allow visitors to click photos in private categories?  (Read 4079 times)

0 Members and 1 Guest are viewing this topic.

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
How can I allow visitors to click photos in private categories?
« on: October 25, 2008, 06:13:09 PM »
I have been working on a new mod to allow users to create password protected categories. Visitors will be able to open a new password page and type in a password. If they type in a correct password the category and its photos will appear on the page.

I have this up and working but now and you can see a demo here: http://gallery.lovemansfield.co.uk/password.php, use video as a password

Now I have a problem I need help with.

The category is set to private  (auth_viewcat  =  5), and doesn’t show anywhere on the site except on the password page (if correct password is entered). This is correct and as it should be! However, when the category comes up on the password page, the photos in the category are unclickable. If I am signed in as an admin, I CAN click the photos and open them on the details page, but visitors and other members cannot.

I need to get to the code to allow visitors and members to click the photos on the password page so they open as normal on the details page? Where can I find this code as i have searched and can’t seem to find it?

All the best
Gary
lovemansfield.co.uk

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: How can I allow visitors to click photos in private categories?
« Reply #1 on: October 25, 2008, 09:23:49 PM »
The script that checks visitor's permissions is in includes/auth.php
What you need to do is store the accepted password in session and then authorize visitor using that password.
I don't know how your code is working, but assuming that the category password stored in the database in "cat_pass" field.
The user entered passwords stored in session (or even in the database for members if you decide go more advanced ;)) in "cat_pass" in the following format: cat_id,password|cat_id,password (each category separated with a "|" and each cat id separated from password with a comma)
And finally the authorization process:
in includes/auth.php find:
  foreach ($cat_cache as $key => $val) {
    if (
$val['auth_viewcat'] != AUTH_ALL) {

Replace it with:/*
category password
start
*/
  
global $site_sess;
  
$cat_pass = array();
  
$pass explode("|"$site_sess->get_session_var("cat_pass"));
  foreach(
$pass as $key)
  {
    
$val explode(","$key);
    if (
count($val) > 1)
      
$cat_pass[$val[0]] = $val[1];
  }
/*
category password
end
*/
  
foreach ($cat_cache as $key => $val) {
/*
category password
start
*/
    
if ($cat_cache[$key]['cat_pass'])
    {
      if(isset(
$cat_pass[$key]) && $cat_pass[$key] == $cat_cache[$key]['cat_pass'])
      {
        
$cat_cache[$key]['auth_viewcat'] = AUTH_ALL//password accepted
      
}
      else
      {
        
$cat_cache[$key]['auth_viewcat'] = AUTH_ADMIN//password denied
      
}
    }
/*
category password
end
*/
    
if ($val['auth_viewcat'] != AUTH_ALL) {


Using this method, you don't need set categories permission to private, all you need to do is set a password.
« Last Edit: October 25, 2008, 09:36:53 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: How can I allow visitors to click photos in private categories?
« Reply #2 on: October 26, 2008, 01:45:18 AM »
Hi V@no

Thank you for taking the time to look at my problem.

I have stored the password users enter in the password page in the database (sessions table in a field called new_password). It is entered in the correct row based on the users ip_address.

In Categories the password field is called cat_password (you were almost spot on).

I can't get the code you have added to work yet, but I think its something to do with how you think I've done the code on my password.php. As you can see above, I have used the database to store the passwords, both the catagory password and the session. Nothing too technical as I am a beginner really.

I am totally lost with this sentence...

...The user entered passwords stored in session (or even in the database for members if you decide go more advanced ) in "cat_pass" in the following format: cat_id,password|cat_id,password (each category separated with a "|" and each cat id separated from password with a comma)...

You can assume I haven't done this as I opted for the database version. Even visitors that are not signed in as a member can have their own password as its based on their session_ip address.

I've had a go at changing the permissions in the auth.php file but have failed for now.

Any ideas?
 
All the best
Gazza   :?

Offline Gazzagreen

  • Newbie
  • *
  • Posts: 25
  • trying to get things to go my way :)
    • View Profile
    • LoveMansfield.co.uk Social website
Re: How can I allow visitors to click photos in private categories?
« Reply #3 on: October 30, 2008, 10:21:10 AM »
Hi all

Looks like noone knows the answer to my problem. I'll try it a different way then. I was thinking of making it so that I allow anyone to view the category (that way people will be able to click on the photos and get a full size photo), but if there is a password present in that category, the code will look for a password for the viewer. If there isn't one then it will open a password page for the view to enter the password.

Once the password in the Sessions table for the viewer, he can then open the category and view the pictures. Should be easy! hehehee

All the best
Gazza

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: How can I allow visitors to click photos in private categories?
« Reply #4 on: November 03, 2008, 08:02:11 AM »
My "simple" solution turned out to be more complex that I thought...

I've posted it as a mod
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)