| Author | Message |
| Post Title: Prevent login with Gallery2? | |
denney
Joined: Dec 24, 2007 Posts: 28
|
Posted: Thu Jan 17, 2008 7:19 am
Is it possible to redirect the login page from an embedded Gallery2 (when accessing a protected item for example) to phpBB3's login page?
That way users can have the option to register and have the proper recover password link. |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Thu Jan 17, 2008 11:18 am
From the GalleryEmbed.class file
Quote: › /**
* Initialize Gallery; must be called before most GalleryEmbed methods can be used. * This method should only be called once during the lifetime of the request. * * @param array $initParams (optional--required before calling handleRequest) ( * 'embedUri' => URI to access G2 via CMS application * (example: /portal/index.php?module=gallery2) * 'g2Uri' = URL path to G2 * (example: /gallery2/, see extended docs for special character '|') * 'loginRedirect' => (optional) URI for redirect to CMS login view (example: /cms/index.php) * 'embedSessionString' => (optional) To support cookieless browsing, pass in key=value for * CMS session key and session id value to be added as query parameter in urls * 'gallerySessionId' => (optional) To support cookieless browsing, pass in G2 session id * (when cookies not in use, CMS must track this value between requests) * 'activeUserId' => (optional) external user id of active user * (empty string for anonymous/guest user) * 'activeLanguage' => (optional) language code in use for this session * 'fullInit' => (optional) call GalleryInitSecondPass * (only use when not calling handleRequest) * 'apiVersion' => (optional) array int major, int minor (check if your integration is * compatible) * ) * @return object GalleryStatus a status object */ I have not tried this, but try adding the loginRedirect option to the init array in g2helper.inc Example- Code: › function g2helper($db) {
global $user; $user->add_lang('acp/gallery2'); $sql = 'SELECT fullPath, embedUri, g2Uri, activeAdminId FROM ' . GALLERY2_TABLE; if (!$row = $db->sql_fetchrow($db->sql_query_limit($sql, 1))) { msg_handler(E_G2_ERROR, $user->lang['OBTAIN_SETTINGS_FAILED'], __FILE__, __LINE__); } $this->_activeAdminId = $row['activeAdminId']; $this->_init_array = array( 'embedUri' => $row['embedUri'], 'g2Uri' => $row['g2Uri'], 'loginRedirect' => '/phpBB3/ucp.php?mode=login', 'apiVersion' => array($this->_compatibleEmbedVersionMajor, $this->_compatibleEmbedVersionMinor) ); if ($this->_activeAdminId == 0) { msg_handler(E_G2_ERROR, $user->lang['G2_AUTHADMIN_FAILED'], __FILE__, __LINE__); } else { require_once($row['fullPath']); } } Set the loginRedirect path to your actual phpbb3 path. That's probably worth adding to the integration - let me know how it works! |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
denney
Joined: Dec 24, 2007 Posts: 28
|
Posted: Thu Jan 17, 2008 12:03 pm
That works great! 2 issues have come up though...
1. When using phpBB's login, you are redirected back to the index page and not the gallery page you were after! This is easily fixed by editing ucp.php and the following: Find: Code: › case 'login':
if ($user->data['is_registered']) { redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } login_box(request_var('redirect', "index.$phpEx")); break; And replace with: Code: › case 'login':
$referer = $_SERVER['HTTP_REFERER']; if (empty($referer) || $referer == '') { $referer = "{$phpbb_root_path}index.$phpEx"; } if ($user->data['is_registered']) { redirect(append_sid($referer)); } login_box(request_var('redirect', $referer)); break; 2. If you use the above edit, it redirects you back to the page BEFORE the page you were after, making you have to click the link again. The only way around this is to modify phpBB to accept a redirect parameter when showing the login box. That's easy but I don't know how easy it is to get this information from Gallery. |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Thu Jan 17, 2008 12:58 pm
I don't know of a way to get that info from gallery. One would have to pass the desired gallery url along with the login request. I image that would require mods to the gallery code. Getting back to the calling page with the link on it seems close enough, doesn't it?
Isn't this Code: › if (empty($referer) || $referer == '')
The same as Code: › if (empty($referer))
This is a better way to make the g2helper change, then it works for all integrations and doesn't have a hard coded path - Code: › 'loginRedirect' => dirname($row['embedUri']) . '/ucp.php?mode=login', |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Thu Jan 17, 2008 1:33 pm
This is nice, I think I will add it to the integration core. It also takes you back to the gallery if you login from a gallery page. My mod looks like this
Code: › #
#-----[ OPEN ]------------------------------------------ # ucp.php # #-----[ FIND ]------------------------------------------ # if ($user->data['is_registered']) { redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } login_box(request_var('redirect', "index.$phpEx")); # #-----[ REPLACE WITH ]------------------------------------------ # $referer = (empty($_SERVER['HTTP_REFERER'])) ? "{$phpbb_root_path}index.$phpEx" : $_SERVER['HTTP_REFERER']; if ($user->data['is_registered']) { redirect(append_sid($referer)); } login_box(request_var('redirect', $referer)); |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
denney
Joined: Dec 24, 2007 Posts: 28
|
Posted: Thu Jan 17, 2008 1:44 pm
I didn't try from a gallery page to another so it's good that works. I was trying it from a link in a forum post to the gallery. It ends up redirecting you back to the forum post instead of the gallery you clicked on.
Good to see it going into the integration though! |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
txll
Joined: Jan 10, 2008 Posts: 5
|
Posted: Fri Jan 25, 2008 5:37 am
Also you can do something like this:
Code: ›
# #-----[ OPEN ]------------------------------------------ # ucp.php # #-----[ FIND ]------------------------------------------ # meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")); $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> '); # #-----[ REPLACE WITH ]------------------------------------------ # $referer = (empty($_SERVER['HTTP_REFERER'])) ? "{$phpbb_root_path}index.$phpEx" : $_SERVER['HTTP_REFERER']; meta_refresh(3, append_sid($referer)); $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($referer) . '">', '</a> '); and when you logout while in gallery you will get back to the gallery rather than index of the forum. |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Fri Jan 25, 2008 11:26 am
Nice...
I'm not sure why one would want to go back to the previous page since logging out usually means you are done, but I played with the code a little and noticed a couple things. The code always says 'return to index' even if it is going to return you to another page and it will return you to other phpbb pages instead of the index page. I'm not sure of the usefulness of this, but I tweaked the code a bit so it gives alternate messages depending on if it is returning to gallery or phpbb and always returns to the phpbb index page if user is not in gallery. Code: › #
#-----[ OPEN ]------------------------------------------ # ucp.php # #-----[ FIND ]------------------------------------------ # meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx")); $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> '); # #-----[ REPLACE WITH ]------------------------------------------ # if (!empty($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], 'gallery2.php')) { $referer = $_SERVER['HTTP_REFERER']; $redirect = $user->lang['RETURN_PAGE']; } else { $referer = "{$phpbb_root_path}index.$phpEx"; $redirect = $user->lang['RETURN_INDEX']; } meta_refresh(3, append_sid($referer)); $message = $message . '<br /><br />' . sprintf($redirect, '<a href="' . append_sid($referer) . '">', '</a> '); |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Fri Jan 25, 2008 2:58 pm
I'll go ahead and add both login and logout mods to the integration for completeness and similar behavior of each...
|
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
denney
Joined: Dec 24, 2007 Posts: 28
|
Posted: Wed Feb 13, 2008 3:27 am
Is it possible to get the code for the new integration? Like a subversion repository or something?
It's been quite a while since the last release and there have been quite a few updates (according to this forum). |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Wed Feb 13, 2008 10:24 am
Dari has the new code - released this week, but he is very busy with real work these days.
I've also submitted the mod to the phpbb mods database, but it is still pending validation at this point. Don't know if or when it will be approved... |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
denney
Joined: Dec 24, 2007 Posts: 28
|
Posted: Wed Feb 13, 2008 10:29 am
Ahh... well that's great I guess.
Just a bummer it's not available anywhere. Oh well, looking forward to seeing it soon. |
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
jettyrat
Joined: Nov 28, 2005 Posts: 1144
|
Posted: Wed Feb 13, 2008 10:31 am
|
| Author | Message |
| Post Title: Re: Prevent login with Gallery2? | |
denney
Joined: Dec 24, 2007 Posts: 28
|
Posted: Wed Feb 13, 2008 10:43 am
Oh wonderful.... Thank you very much. It's much appreciated.
Keep up the great work guys! Time to try and break this thing again. |