Recent Topics

1 Aug 17, 2005 22:30    

How to automatically click on the login link when accessing the default blog ?

What I'd like is to make it so as soon an user access the default blog page (which is my "blog all"), it would act as if the "login" link in the "misc" section of the sidebar would have been clicked by the user so that he automatically access the login page (which I have modified so that the login form fills and submits itself without the user being able to even see it).

This is as close as I get to automatic authentication.

Here's how I modified the _login_form.php file to make it so the login form fills and submits itself automatically.


<fieldset>

<div class="input"><input type="hidden" name="log" id="log" size="16" maxlength="30" value="<?php echo "{$_SERVER["REMOTE_USER"]}"?>" class="large" /></div> 

</fieldset>

<fieldset>

<div class="input"><input type="hidden" name="pwd" id="pwd" size="16" maxlength="30" value="defaultpwd" class="large" /></div>
		
</fieldset>

<script type="text/javascript">
<!--
javascript:document.formulaire.submit();
//-->
</script>

<fieldset>

<div class="input">

<input type="submit" name="submit" value="<?php echo T_('Log in!') ?>" class="search" />

</div>

</fieldset>

So I'm able to modify the login form so that it fills and submits itself automatically but Im unable to make it so the "login" link in the sidebar is clicked automatically (mainly because I cant find where that link is ... it looks like a function instead of a link: user_login_link( '<li>', '</li>' ); )

Some help would be very appreciated, am having a hard time with this part. Once I'm done with it I'll be able to share the knowledge on automatic authentication for those interested.

2 Aug 17, 2005 23:27

I'd like to know where this function, found in the _main.php file of every skin, can be found and altered.

The function is: user_login_link( '<li>', '</li>' );

How does it work ? (Im completely lost on this one!! It must be simple but Im too dumb to see what it does !)

Help a fellow in distress ;)

3 Aug 17, 2005 23:46

It's a function all right, and it lives in b2evocore/_functions_users.php. Hope it helps.

4 Aug 18, 2005 19:24

It really does help. Thanks EdB.

All I had to do was to go and add an ID for the link created in the user_login_link function ... called it V1

Then in the _main.php file of my blogall's skin I simply added


<script type="text/javascript">
	<!--
	javascript:window.V1.click();
	//-->
</script>

After this bit of code


<div class="bSideItem">
	<h3><?php echo T_('Misc') ?></h3>
	<ul>
	<?php
	user_login_link( '<li>', '</li>' );
	user_register_link( '<li>', '</li>' );
	user_admin_link( '<li>', '</li>' );
	user_profile_link( '<li>', '</li>' );
	user_logout_link( '<li>', '</li>' );
	?>
	</ul>
</div>

This works very well with Internet Explorer but it does not work with Firefox and Mozilla (those two dont like my little javascript). Here's the error log in Firefox's JAvascript Console:

Error: window.V1 has no properties

Am putting it here in case someone would be a javascript expert that knows what this problem is and also because I didnt find a solution yet :-/

5 Aug 18, 2005 21:45

Try this:


<script type="text/javascript"> 
   <!-- 
     document.getElementById("V1").click();
   //--> 
</script>

6 Aug 19, 2005 17:06

Thanks Kweb for the quick reply.

I already had tried to use this line:


javascript:document.getElementById("V1").click();

I tried to your suggestion, here's the error it gives me now:

Error: document.getElementById("V1").click is not a function

What's weird is that it works perfectly when I access the page with Internet Explorer but it gives me the error above with Firefox (and thats what the majority of people here use).

I keep on searching for a solution, if I come up with one I'll put it here. Feel free to continue suggesting me possible solutions, they are very welcome ;)

7 Aug 19, 2005 18:23

Ok. That was a guess - I didn't test it.

Instead of trying to click the link, why don't you write your JavaScript to just redirect the user to the login URL. Or even better - you could do it in PHP, and redirect the user before displaying the page at all.

8 Aug 19, 2005 21:31

I suceeded in implementing it using this line of code:


javascript:document.location=document.getElementById("V1").href;

Now it works with Firefox/Mozilla and IE

As to why I didnt write a Javascript to just redirect to the login URL or use PHP to redirect before displaying the page is because I hadnt thought about those options before I started coding the solution I'm using. Plus I'm far from a web guru, PHP and JS are pretty new to me ... I "tried" making it simple :roll:

The fact is Im spending about 30 minutes a day on this project since it's a secondary project, am working on another more important project. The quality of my work on the weblogs suffered due to that.

I know my solution is far from ideal but it's good for what we need here since the blogs are hosted on intranet. If anyone is interested in implementing my solution, request it here (I would put it here now IF I had the time to do so but instead I'll wait to see if it interests anyone)

9 Aug 19, 2005 22:24

Glad you got it working. I understand the need to get it done in a short amount of time.

If you get a chance, you should post your solution, and someone who has more time might take a crack at making it more efficient or creating version that is all server-side (no javascript). Then you could benefit from their work later if you want to upgrade your setup a little. Just a thought.

10 Aug 23, 2005 19:39

Aye I will post it here in the forums, Im still tweaking in when I have some free time to spare, its not yet working exactly as we want it (but it's up and running) so I will post this in the right forum in another thread, later.

Stay tuned :)


Form is loading...