Pages (2): 1 2   
Member
Member
viavianci   2008-07-22, 00:32
#1

Hello,

I have integrated ZenPhoto for a client and am having a problem with a feature I'm trying to implement. The client is a photographer, as well as the normal galleries, he has password protected galleries for his clients.

He has a link on his homepage "Client Login", I'd like to link that to a form, take the username and password from the form:-

-Using the username, direct the user to his client gallery
-Use the username and password to log the user in so that he doesn't need to fill in the form that appears when you're not logged in (seeing as that would mean asking for the details twice!)

Is there anyway of doing this?

Member
Member
sbillard   2008-07-22, 00:39
#2

You can create a zenphoto cookie from his usercode and password. The zenphoto login is handled circa line 37 in auth_zp.php. There you will see how the cookie is created when one logs into zenphoto. You will have to create zenphoto admin users with the same user/password for this to work.

Member
Member
viavianci   2008-07-22, 15:38
#3

Hello, I'm not the most advanced PHP user - is there any documentation that explains how the cookies are created?

Member
Member
sbillard   2008-07-22, 16:46
#4

There is documentation on setcookie in the PHP documents: http://us2.php.net/manual/en/function.setcookie.php. The above reference will show you what zenphoto does.

Member
Member
viavianci   2008-07-22, 17:42
#5

Thanks for your help, that was most helpful sbillard - I was able to add the feature I wanted.

Member
Member
viavianci   2008-07-22, 19:25
#6

Hi there,

Actually I've just realised that my solution isn't working yet. My code is as follows:

SBillard - do you have idea what I could do to make this work?

Member
Member
sbillard   2008-07-22, 22:08
#7

With an installation in the folder 'zenphoto' the cookie path needs to be zenphoto/

so setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "zenphoto/");

Member
Member
viavianci   2008-07-22, 22:50
#8

Hi, I actually sorted the problem by copying the file to /zenphoto and using zp_setcookie.

Could you please let me know how I can verify the username and password entered by the client is correct before I create the cookie!

I know the answer is in auth_zp.php file - but I'm having difficulty locating it!

Thanks in advance!

Member
Member
sbillard   2008-07-22, 23:34
#9

`if (checkAuthorization(md5($post_user . $post_pass))) {

zp_setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, $cookiepath);

} else {

zp_setcookie("zenphoto_auth", "", time()-368000, $cookiepath);

}`

Member
Member
viavianci   2008-07-23, 13:11
#10

Hello,

Can I ask what is the difference between: checkAuthorization & checkLogon?

The checkAuthorization does work, but the cookie is not being set (I get the enter username + password form). My code:

Member
Member
viavianci   2008-07-23, 13:34
#11

Hello,

Just to add,

If I login using my login form, the authentication part works fine, it redirects me to the gallery but the cookie is not set as I get the username and password form.

If I try to login again through my form, it works! It's just the first time that it doesnt work - do you know why this could be?

Member
Member
sbillard   2008-07-23, 20:25
#12

Cookies cannot be set after you have generated output. If you echo "wrong username / password" shows up in anything but a blank page then you have already sent headers so your cookie is not saved. This processing must be done before any headers, etc. are sent. So you would have to have some error variable set so that later you can display your error message.

In answer to your original question, checkLogon() checks a user/password for authentication. checkAuthorization() matches a stored authorization such as a cookie.

Member
Member
viavianci   2008-07-26, 13:17
#13

Hi there, I still have the same problem:

If I visit the plain HTML site, click on my login form, submit the correct user details --> I get the user + password form from Zen, the cookie appears not to be set.

If I then click on the same login link and try again, I get logged in and the cookie is set.

My code is as follows - I feel I'm really close to the solution so I hope you can help me wrap things up!

Member
Member
sbillard   2008-07-26, 16:26
#14

Please try this with the current nightly build. I did find a problem where session information was getting set empty somehow. I have changed the authorization process to ignore empty session autorization codes so it should fetch the cookie properly.

Member
Member
viavianci   2008-07-28, 18:36
#15

Hello - the current nightly build (27th July) didn't fix this problem either. Any other suggestions?

Member
Member
sbillard   2008-07-28, 19:06
#16

You need to figure out if your cookies are getting sent. If so, make sure the endocing in the cookie matches the auth in the administrators table.

Member
Member
viavianci   2008-07-28, 19:14
#17

Hi there,

I modified the code slightly:
`

if(checkLogon($post_user, $post_pass))

{

setcookie("zenphoto_auth", md5($post_user . $post_pass), time()+5184000, "/");

$_zp_loggedin = checkAuthorization(zp_getCookie('zenphoto_auth'));

if ($_zp_loggedin) {

    header('Location: http://www.mysite.com/script/' . $post_user);

}

}

`
This results in a blank screen which means the cookie is not being set on the first attempt but does get set on subsequent attempts - I don't understand why this happens!

Member
Member
sbillard   2008-07-28, 23:38
#18

I have figured it out. Basically, the cookie does not cross web boundries. I have created a hack that will do what you wish. http://www.zenphoto.org/2008/07/zenphoto-single-login/

Member
Member
viavianci   2008-07-29, 16:45
#19

The hack works perfectly, thanks for all your help over the last few days. I'll try and find your email address to send you the URL to the finished site.

p.s. http://www.zenphoto.org/2008/07/zenphoto-single-login/ < I had some problems copying and pasting the code, there's some formatting errors on the page

Administrator
Administrator
acrylian   2008-07-29, 16:51
#20

Sorry about the formatting problems, it always can be problematic pasting code from the site (and the forum). We will attach that as a file download later.

Pages (2): 1 2   
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.