Recent Topics

1 Jun 08, 2010 11:09    

My b2evolution Version: Not Entered

I am in the final step of turning b2 into a client base for a law firm.

All i need is just one more thing,

After login; instead of redirecting to backoffice;

Check if user owns a blog > Redirect to the owned blog

2 Jun 09, 2010 00:47

With a tad of luck "function auto_select_blog()" will work, if not then you'll need a mysql hit :(

global $DB, $current_User;
if( is_logged_in() && ( $id = $DB->get_var( 'SELECT blog_ID FROM T_blogs WHERE blog_owner_user_ID='.$current_User->ID.' LIMIT 1' ) )
{
  $redirect_to = get_Cache('BlogCache')->get_by_id( $id )->get_permanent_url();
}

*disclaimer : Free typed and all that ;)

¥

3 Jun 09, 2010 23:37

¥åßßå wrote:

With a tad of luck "function auto_select_blog()" will work, if not then you'll need a mysql hit :(

global $DB, $current_User;
if( is_logged_in() && ( $id = $DB->get_var( 'SELECT blog_ID FROM T_blogs WHERE blog_owner_user_ID='.$current_User->ID.' LIMIT 1' ) )
{
  $redirect_to = get_Cache('BlogCache')->get_by_id( $id )->get_permanent_url();
}

*disclaimer : Free typed and all that ;)

¥

:P i wish that function auto_select_blog_based_on_telekinetic_guess_of_what_i_need existed, but mysql hit will do just fine for now..

You just had one typo and i've fixed it but it's still not working..
Btw, given your usual rate of typos in 2 lines, it seems you code better than you speak (:

Fatal error: Call to undefined method Blog::get_permanent_url() in /home/.../htsrv/login.php on line 387

Cant we make use of one of [url=http://doc.b2evo.net/v-2-4/evocore/BlogCache.html#sec-method-summary]these methods[/url] in order to do this ?

BlogCache BlogCache() Constructor
boolean add() Add object to cache, handling our own indices.
Blog &get_by_url() Get an object from cache by its url ("siteurl")
Blog|false &get_by_urlname() Get a blog from cache by its URL name.
void get_option_list() Returns form option list with cache contents
array load_owner_blogs() Load a list of blogs owner by specific ID into the cache
array load_public() Load a list of public blogs into the cache
array load_user_blogs() Load blogs a user has permissions for.

load_owner_blogs() seems to make sense ?

Thank you very much again

4 Jun 10, 2010 00:25

<?php
echo 'load_owner_blogs looks like a winner, but I bet it involves a mysql hit ;)';
?>

With a tad of luck that won't throw an error :D

¥

5 Jun 10, 2010 02:16

How about this ?

get_Cache('BlogCache')->get_by_id( $id )->get('url');

6 Jun 10, 2010 04:53

sam2kb wrote:

How about this ?

get_Cache('BlogCache')->get_by_id( $id )->get('url');

Yep, that did the trick pretty well, except for one thing;

When you login, it does not redirect right away,
"you are already logged in as "..." Click to continue message appears, and it does not redirect until after you click 'continue'..
Why do you think this happens, and what do i do to fix this ?

thanks again

7 Jun 10, 2010 05:29

$redirect_to = ...
header_redirect($redirect_to);

BTW where did you put this code? I guess it should work fine in hacks.php

8 Jun 10, 2010 08:55

sam2kb wrote:

$redirect_to = ...
header_redirect($redirect_to);

BTW where did you put this code? I guess it should work fine in hacks.php

There is no hacks.php file in the install.. do i just create an empty hacks.php file ? i am not sure how to use it..

i have put it in .../htsrv/login.php ...
first, commented out the below lines (L.380 - 390 approx.):

/*if( preg_match( '#/login.php([&?].*)?$#', $redirect_to ) )
{ // avoid "endless loops"
	$redirect_to = $admin_url;
}*/

and placed ¥åßßå's code right before that part. so that it looks sth like this:


// lines 380 - 400
	.......  }
	if( ! $cookie_domain_match )
	{
		$Messages->add( sprintf( T_('WARNING: you are trying to log in to <strong>%s</strong> but your cookie domain is <strong>%s</strong>. You will not be able to successfully log in to the requested domain until you fix your cookie domain in your %s configuration.'), $redirect_to, $cookie_domain, $app_name ), 'error' );
	}
}
	if( is_logged_in() && $current_User->validated )
global $DB, $current_User;
if( is_logged_in() && ( $id = $DB->get_var( 'SELECT blog_ID FROM T_blogs WHERE blog_owner_user_ID='.$current_User->ID.' LIMIT 1' ) ) )
{
  $redirect_to = get_Cache('BlogCache')->get_by_id( $id )->get('url');
} 
/*if( preg_match( '#/login.php([&?].*)?$#', $redirect_to ) )
{ // avoid "endless loops"
	$redirect_to = $admin_url;
}*/

// Remove login and pwd parameters from URL, so that they do not trigger the login screen again:
$redirect_to = preg_replace( '~(?<=\?|&) (login|pwd) = [^&]+ ~x', '', $redirect_to );
$Debuglog->add( 'redirect_to: '.$redirect_to );
........

9 Jun 10, 2010 20:07

i have put it in .../htsrv/login.php ...

Naa, change everything back. Create an empty file /conf/hacks.php with the code posted by Yabba

10 Jun 12, 2010 08:20

sam2kb wrote:

i have put it in .../htsrv/login.php ...

Naa, change everything back. Create an empty file /conf/hacks.php with the code posted by Yabba

changed back, placed it in hacks.php.. everything works still the same..

when you login you get the message "you are already logged in as ... click continue" and you dont get to be redirected until after you click on "continue"

11 Jun 12, 2010 18:00

Based on 2.4.x because I have no desire to inflict spam and spyware onto any of my servers by upgrading beyond that series :

inc/_main.inc.php

	if( $pass_ok )
	{ // Login succeeded, set cookies
		$Debuglog->add( 'User successfully logged in with username and password...', 'login');
		// set the user from the login that succeeded
		$current_User = & $UserCache->get_by_login($login);
		// save the user for later hits
		$Session->set_User( $current_User );
if( $id = $DB->get_var( 'SELECT blog_ID FROM T_blogs WHERE blog_owner_user_ID='.$current_User->ID.' LIMIT 1' ) )
{
  $redirect_to = get_Cache('BlogCache')->get_by_id( $id )->get_permanent_url();
} 
	}

¥

12 Jun 12, 2010 18:13

¥åßßå wrote:

Based on 2.4.x because I have no desire to inflict spam and spyware onto any of my servers by upgrading beyond that series :

inc/_main.inc.php

	if( $pass_ok )
	{ // Login succeeded, set cookies
		$Debuglog->add( 'User successfully logged in with username and password...', 'login');
		// set the user from the login that succeeded
		$current_User = & $UserCache->get_by_login($login);
		// save the user for later hits
		$Session->set_User( $current_User );
if( $id = $DB->get_var( 'SELECT blog_ID FROM T_blogs WHERE blog_owner_user_ID='.$current_User->ID.' LIMIT 1' ) )
{
  $redirect_to = get_Cache('BlogCache')->get_by_id( $id )->get_permanent_url();
} 
	}

¥

That seems to do the trick, thank you (;


Form is loading...