Automatic login

drigam

Joined: 2003-04-24
Posts: 2
Posted: Thu, 2003-04-24 15:47

I am trying to automatically login my users to the gallery, preferably through URL execution of albums.php or login.php. I can't seem to pass along a generic login through ?uname=asdf&gallerypassword=asdf

I would prefer the users not have to login or click anything to login.

Any help or hints or links are greatly appreciated!

Thanks.

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Thu, 2003-04-24 17:38

***THIS SOLUTION WILL NOT WORK WITH 1.4.1 *****

A link that will automatically log you in looks something like this
http://your.address.com/gallery/login.php?uname=user&gallerypassword=secret&submit=Login
replacing the obvious with the correct username and password.

But that will leave you on the login page. So edit login.php, to redirect you to albums if you have logged in correctly. Remove the if ($submit){ . . . } and insert this, near the top of the file (existing require and <html> left in to show you where to put it.

<?php require($GALLERY_BASEDIR . "init.php"); 
// Security check.
$uname = removeTags($uname);
if ($submit) {
        if ($uname && $gallerypassword) {
                $tmpUser = $gallery->userDB->getUserByUsername($uname);
                if ($tmpUser && $tmpUser->isCorrectPassword($gallerypassword)) {
                        $gallery->session->username = $uname;
                        header("Location: albums.php");
                } else {
                        $invalid = 1;
                        $gallerypassword = null;
                }
        } else {
                $error = 1;
        }
}
?>
<html> 

So if you get the right URL as above, it will take you to the main page, logged in as whatever user you want.

 
drigam

Joined: 2003-04-24
Posts: 2
Posted: Thu, 2003-04-24 18:26

Thank you very much!

It works exactly as I hoped. I really appreciate your help!

:smile:

 
DonaldNewlands

Joined: 2003-02-17
Posts: 9
Posted: Wed, 2003-04-30 18:28

Hi,

I need to have the login dialog come up automatically only on pages with permissions set. With this hack does the login always come up or only where needed?

Thanks!

-Donald

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Thu, 2003-05-01 08:50
Quote:
I need to have the login dialog come up automatically only on pages with permissions set. With this hack does the login always come up or only where needed?

Sorry Donald,

You'd have to redesign the core of gallery to do that. Gallery only will show what you're allowed to see. You won't even see a link to something you need to log in to see.

 
stirstick

Joined: 2003-11-17
Posts: 2
Posted: Mon, 2003-11-17 15:05

okay, so I'm an idiot or something. it looks to me (knowing nothing about php) like the login code has changed since this was posted (ie: I just installed gallery v1.4-pl2 and I can't find an if ($submit){ . . . }, and commenting out the if ($login){ . . . } and putting the suggested code in the suggested place still leaves me at the logon screen rather than returning me to albums.php.

I've attached a zipped copy of my unedited login.php, as I'm convinced that it would be useful information.

Please help! It would be really useful to be able to autologon for this application. All I really think I need is for this login.php to return the user to albums.php. Any assistance would be hugely appreciated.

Thanks,
Ken

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Mon, 2003-11-17 15:31

Try replacing $submit with $login in the above code.

 
stirstick

Joined: 2003-11-17
Posts: 2
Posted: Mon, 2003-11-17 15:52

Already tried and denied. I'm attaching the edited file, also zipped, so you can see what I'm doing wrong.

Thanks,
Ken

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Mon, 2003-11-17 16:24

I'm not in the mood for reviewing someone's code. The stuff has changed enough that you can't just apply my change above.

Maybe someone else will support this modification for you.

 
BeanyBoy
BeanyBoy's picture

Joined: 2003-11-11
Posts: 34
Posted: Wed, 2003-11-19 16:18
joan wrote:
***THIS SOLUTION WILL NOT WORK WITH 1.4.1 *****

A link that will automatically log you in looks something like this
http://your.address.com/gallery/login.php?uname=user&gallerypassword=secret&submit=Login
replacing the obvious with the correct username and password.

I really need to think outside the box more... this solved my problem of needing to cache credentials for the XP Publishing Wizard. After registering the service for a staff member, I can edit the url in the service href field, and first substituting publish_xp.php for login.php then the appropriate credentials, my staff users won't need to manually authenticate to Gallery just to publish photos.

And, it *is* working in 1.4.1-rc3!

Thanks, Joan! Although I did learn a lot about php and cookies trying to get the other approach working...

Gallery is my first look at php...

-dq

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Wed, 2003-11-19 17:07

mine too. a slippery slope!

 
webfeatus
webfeatus's picture

Joined: 2002-11-17
Posts: 17
Posted: Tue, 2004-03-16 12:04

Joan said...
But that will leave you on the login page. So edit login.php, to redirect you to albums if you have logged in correctly. Remove the if ($submit){ . . . } and insert this, near the top of the file (existing require and <html> left in to show you where to put it.

<?php require($GALLERY_BASEDIR . "init.php"); 
// Security check.
$uname = removeTags($uname);
if ($submit) {
        if ($uname && $gallerypassword) {
                $tmpUser = $gallery->userDB->getUserByUsername($uname);
                if ($tmpUser && $tmpUser->isCorrectPassword($gallerypassword)) {
                        $gallery->session->username = $uname;
                        header("Location: albums.php");
                } else {
                        $invalid = 1;
                        $gallerypassword = null;
                }
        } else {
                $error = 1;
        }
}
?>
<html> 

I want to follow the above procedure in v1.4.2 Only logged in users may view the albums. I have tried various alterations but I am left in the login window. I can not find a way to proceed to the albums page aftyer a successful login.

My browser also receives a "symrealwinopen" error from the UNMODIFIED version of login.php

Any help on the above issues?