Auto create accounts in Gallery and auto login the user in.

floweringmind

Joined: 2005-02-10
Posts: 4
Posted: Fri, 2005-02-11 23:58

I whipped up a quick hack that allows our users to who are already registered with our site, just go right to the gallery and start posting. The script auto creates accounts in the gallery based off our current account info and then logs them in. Others may have made better versions of this but I couldn't find any scripts.

The script should be saved as a php file in the gallery directory.

?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2004 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: create_user.php,v 1.37.2.3 2004/07/22 18:04:16 cryptographite Exp $
*/
?>
<?php

require(dirname(__FILE__) . '/init.php');

// !IMPORTANT! - You will need to send data to this page such as the user ID of the user or
// pull it from a cookie to do a query and get the user info so that we can give it
// to the gallery program and have it setup the account. You should validate any info
// you send this script via cookies or sessions to make sure people don't tamper with
// the program and setup account.

// I don't show my code for decrypting our cookie but that is what I do here and compare the decrypted
// cookie data to the database data.

// !IMPORTANT! - at the bottom of where we create the user account we make a database query to update
// our database so next time we know that the user account doesn't need to be created in the gallery
// database next time they come through. You will need to add the ACCOUNT field to your database.

// setup access to your database

include('../scripts/db.php');

$sql = mysql_query("SELECT username FROM td_users WHERE user_id = '$uid'") or die (mysql_error());

$temp = mysql_fetch_object($sql);
$u = $temp->username;
$p = $temp->password;
$email = $temp->email;
$account = $temp->account;

// check if we have an invalid user

if ($p != $pw || $p == $nothing){

// just send them to the photo board
echo"<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=index.php\">";
exit();
}

$errorCount=0;
$action = "create";

// define account info

$uname = $u;
$password1 = $p;

$username = $u;
$gallerypassword = $p;

// If the user doesn't have an account in the gallery, which we track in our database
// then we need to create an account in the gallery that matches their account in our database

if ($account != $nothing){

$gallery->userDB->validNewUserName($uname);

$gallery->userDB->validPassword($password1);

if (!$errorCount) {
doctype();
?>
<html>
<head>
<title><?php echo _("Create User") ?></title>
<?php common_header(); ?>
</head>
<body dir="<?php echo $gallery->direction ?>">
<center>
<?php
$tmpUser = new Gallery_User();
$tmpUser->setUsername($uname);
$tmpUser->setPassword($new_password1);
$tmpUser->setFullname($fullname);
$tmpUser->setCanCreateAlbums($canCreate);
$tmpUser->setEmail($email);
$tmpUser->origEmail=$email;
$tmpUser->setDefaultLanguage($defaultLanguage);
$tmpUser->version = $gallery->user_version;
$tmpUser->log("register");
$tmpUser->save();
//print sprintf(_("User %s created"), $uname) . "<br><br>";
if (isset($send_email)) {
$msg = ereg_replace("!!PASSWORD!!", $new_password1,
ereg_replace("!!USERNAME!!", $uname,
ereg_replace("!!FULLNAME!!", $fullname,
ereg_replace("!!NEWPASSWORDLINK!!",
$tmpUser->genRecoverPasswordHash(),
welcome_email()))));
$logmsg = sprintf(_("%s has registered by %s. Email has been sent to %s."),
$uname, $gallery->user->getUsername(), $email);
$logmsg2 = sprintf("%s has registered by %s. Email has been sent to %s.",
$uname, $gallery->user->getUsername(), $email);
if ($logmsg != $logmsg2) {
$logmsg .= " <<<<>>>>> $logmsg2";
}

if (gallery_mail($email, _("Gallery Registration"),$msg, $logmsg)) {
clearstatcache();
$tmpUser->save();
print sprintf(_("Email sent to %s."), $email);
print "<br><br>";
}
}

// update our database so we know that we have setup the user in the gallery

$sql = mysql_query("UPDATE td_users SET account = '1' WHERE username = '$u'") or die (mysql_error());

}

}

// the user has an account in the gallery so lets log them in

$tmpUser = $gallery->userDB->getUserByUsername($username);

$tmpUser->log("login");
$tmpUser->save();
$gallery->session->username = $username;
gallery_syslog("Successful login for $username from " . $HTTP_SERVER_VARS['REMOTE_ADDR']);
if ($tmpUser->getDefaultLanguage() != "") {
$gallery->session->language =
$tmpUser->getDefaultLanguage();
}
if (!$gallery->session->offline) {
dismissAndReload();
} else {
print "<span class=error>SUCCEEDED</span><p>";
return;
}

echo"<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=index.php\">";
exit();

Login or register to post comments
jako

Joined: 2006-01-09
Posts: 1
Posted: Mon, 2006-01-09 11:27

This does not work with last version of the Gallery !

Is there any way to autmaticaly login a user when you know is login an password with the last version of the gallery ?

require(dirname(__FILE__) . '/init.php');
include('../scripts/db.php');

I could not find these file in my version ?

Thanks for your help,
JaKo

Login or register to post comments