Forgive me if this is an age-old question, but I've read numerous posts and docs and I guess I'm just missing the right one.
Instead of integrating G2 into another app, I'd like to use Gallery's authentication for the admin page of a chatbox script I've written-not embed it in Gallery as a module (tho it might come to that later) but just use the same authentication-that way I can have one admin user for the site w/o having to re-invent the wheel.
If anyone could point me in the right direction, or better provide some lines to pop in my PHP script, I'd be a joyful person.
Ng
Posts: 32509
no, this question wasn't asked before.
so you'd like to have a login box in your chat, and your php code in the chat authenticates the user against G2.
or do you want to login in G2 and when you login in G2, it notifies your chat script that the user is logged in such that the chat can create a cookie or so?
See modules/core/UserLogin.inc
Posts: 178
Well, eventually I'd like to tie the user end in (so instead of typing a name your Gallery ID is prepended automagically if you are logged in), but for now, something (I hope) simpler.
In Gallery1, you could include gallery's init file and do $gallery->isAdmin() (not exact wording but I'm w/o the reference now).
By doing that you could verify that the session belonged to a Gallery admin and so let them do, well, adminnish (adminesque ?) actions in your own application.
For now, I want to do something similar-if this person/session is a gallery admin, let them into the chat admin page. Else kick them back to the main page (or be nice and display a message telling them to log into Gallery first, yada yada).
Your file reference looks like it has the calls I'll need to use, but what is the best way to access/tie into Gallery's functions?
Posts: 32509
so i assume the chat script is in the same directory as g2's main.php? or in a subdirectory.
else, you have a problem, because the browser doesn't send the g2 session cookie to your chat script. if the chat script is in another directory or higher in the directory tree, you can change G2's cookie path in site admin, e.g. to '/'.
in your chat script,
require_once('embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true));
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
list ($ret, $isSitedmin) = GalleryCoreApi::isUserInSiteAdminGroup();
if ($ret->isError()) {
print $ret->getAsHtml();
exit;
}
if ( $isSitedmin) {
print "is admin";
} else {
print "is not admin";
}
Posts: 178
Thank you greatly for your help.
This is what I came up with, in case it might be of use to others, or can be improved.
I did end up changing the cookie path to '/' as the site is also using a blog that I would like eventually to tie into Gallery as well, so there is a common user base, and that would facilitate it should I get to that point.
I put this code in a file in Gallery2's root, then included it in my admin page (again, so I can reuse it as needed). Of course all the print stuff is in the chat page, but here for consistency.
Thanks again,
NotGoddess