Posted by crotown on July 2, 2009 at 12:18pm
I'm wondering what tricks people know for hiding the login block but keeping it accessible for administrators (so they don't have to type ?q=user/login). Anyone like to share? Thanks in advance.
I'm wondering what tricks people know for hiding the login block but keeping it accessible for administrators (so they don't have to type ?q=user/login). Anyone like to share? Thanks in advance.
Comments
Boy to my knowledge there is
Boy to my knowledge there is no way to do that.
You have to be logged in as something in order for Drupal to know what to show you or what not to show you (e.g. the login block) different from what anonymous users see.
One thing: the url is just /?q=user and if you enable Clean URLs it's just /user
admin/settings/clean-urls
Good point
Good point that the URL is just "user" and that with clean URL's you just need to add "/user" in the browser. A point to ponder: user/login works, but user/foo does not.
You can hide a link to /user
I suppose it might be possible to write a module that saves a cookie to identify the user as someone who has logged in as the administrator, and use that to decide whether to display the login block. There might be a chicken and egg problem with that though...
One thing I've seen is to put a link to /user somewhere on the page that is colored the same as the background. It will be invisible, but the cursor will change when you hover over it (or you can even disable that, with css). You'll know where to click. It's basically the same as having to know to type "/user" in the address field, or to create a bookmark to "/user".
If you don't want to be so (transparently) secretive, just put a (unhidden) link to /user in a tasteful spot on the home page (or in a block that only displays with the home page)
hiding links
Thanks Pat,
Your idea of hiding (or not hiding) is a little like a trick I remember hearing. And bookmarking /user for admins is practical. I'm thinking that the trick I vaguely remember hearing involves making the login block float (with a module?) and then hiding a link to it. Ring any bells?
Javascript can do that
You can show/hide the block with some fairly simple javascript and css. Three things are needed:
Here's a javascript function that I've used (not in Drupal though):
<script language="javascript">function toggleDisplay(n) {
if (document.getElementById) {
var e = document.getElementById(n);
var eStyle = e.style.display;
eStyle = (eStyle == 'block') ? 'none' : 'block';
e.style.display = eStyle;
}
else if (document.all) {
var e = document.all[n];
var eStyle = e.style.display;
eStyle = (eStyle == 'block') ? 'none' : 'block';
e.style.display = eStyle;
}
}
</script>
And then for your link, something like
<a href="javascript:void(0)" onclick="toggleDisplay(--the id--)">show login</a>If you just want to hide the login block
One thing you can do is to create a primary link with the path simply 'user' (sans quotes).
Another idea: Since /user is
Another idea:
Since /user is hard to remember unless you use Drupal a lot, you could make a redirect with .htaccess from /login to /user. Easier for clients to remember. They can drag it to their bookmarks toolbar to make it even easier.
Redirect 301 /login http://example.com/userThis got me to thinking
So I started playing around with a jQuery solution.
Here's what I did.
First, I created a file called login.js that contained this code:
Drupal.behaviors.loginPopup = function(context){
$('body.not-logged-in a.popLogin', context).click(loginPopup);
$('#login-close', context).click(loginClose)
function loginPopup(){
$('#popup').show('slow');
$('a.popLogin', context).click(loginClose)
return false;
}
function loginClose(){
$('a.popLogin').unbind('click', loginClose);
$('#popup').hide('slow');
}
};
Next, I added a region in the theme's .info file called login_popup along with a call to load the login.js file
regions[login_popup] = Login Popup
scripts[] = login.js
Then, I made sure the page.tpl.php and page-front.tpl.php body tag included the $body_classes
<body class="<?php print $body_classes; ?>">Right under the body tag on the pages, added
<div id="popup"><?php print $login_popup; ?></div>In order to display the login/logout link, this was added beneath the primary links,
<div id="login"><!-- login link start -->
<?php print $pop_login; ?>
<!-- login link end -->
</div>
Now, in the template.php file (ifeeldirty2col being the theme name) this was added to create the login/logout link that appears when you print the $pop_login variable
function ifeeldirty2col_preprocess_page(&$variables) {if ($variables['logged_in']){
$variables['pop_login'] = '<a href="'.url('logout').'" class="popLogin">Log out</a>';
}else{
$variables['pop_login'] = l(t('Login'), 'user/login' , array('attributes' => array('class' =>'popLogin')));
}
}
Style it a bit
#login-close {float:right;
padding:0 10px 0 0;
}
#popup {
position:absolute;
top:60px;
left:775px;
width:300px;
z-index:100;
background-color:#FFFde8;
display:none;
}
In my case, I added a block-user-0.tpl.php file so I could add a CLOSE link to the login block. The code in the block:
<div id="login-close"><?php print '<a href=# class="loginCloseBlock">close</a>'; ?></div><?php print $block->content ?>
Almost there. Now, flush the cache. If you don't have the admin-menu module installed, another way to do this via admin/settings/performance and press the Clear cached data button.
Finally, assign the User Login block to the Login Popup region you created in the .info file.
If you want me to go over this at the next user group meeting, I'd be happy to do that.
Jim
Seems like a good topic for the next meetup
It's of interest to a few of us at least. Thanks all!
Hi jskowyra, Thanks for the
Hi jskowyra,
Thanks for the great solution. This is exactly what I was looking for: to have a nice neat login on my site. However there is an issue with Internet Explorer. The popup login appears and disappears straight away, as opposed to staying open in Firefox. I've checked that this also occurs on your site www.anthonymedia.com. I'm using IE7.0.5730.11 and Firefox 3.0.13.
Cheers,
Deirdre
Yup, problem fixed
Thanks for catching that. The line in the jquery function
function loginPopup()
$('a.popLogin', context).click(loginClose)when removed, fixes it.
I limited block display for
I limited block display for the login block to "show only on selected pages" - and entered "user" in the form. Presto!
sv Libertalia | Textnik Translations
Huh?
Now no user that appears as anonymous will ever see the login block to authenticate as user?
Presto! Lock out.
skowyra
Hello skowyra
I hate to bug you with this I have been trying to get your log in popup to work on the Acquia Marina theme but I am running into a problem I have followed every step you mentioned except the page-front.tpl file edits because I did not have one but I did the page.tpl edits.
I would not mind using a region that allready there the header middle but I can't talk it into showing up there either.
I wonder if you might have any insite as to what I may be doing wrong.
Thanks for your time
TOm
Login
Tom,
That's a tough one without seeing the code. If you want to send me a link to the site, and a text version of the code, I'll take a look at it.
Sorry for the delayed response. I just happened to look at this.
Jim
Solution:popup login appears and disappears . . .
Tested FF 3.5 IE 7/8
Drupal.behaviors.loginPopup = function(context){
};
One little edit
$('a.popLogin').unbind('click', loginClose);Icon link login
One thing I did for one site is to create an Icon for the footer of the site. I created a linkable [div] around it and now I just open the site URL, navigate to the footer and click the tiny icon and the login page renders.
I have heard of folks doing the same thing but making the linking [div] the same color as the footer (or wherever you desire to hide the 'spot') and then only alerting the 'need to know' site folks where that is.
Either way, it assists in eliminating an ugly logon block.
One can also simply have a link in Primary (or wherever) that hyperlinks to the logon page.
A "site independent" method
For any of you that manage a handful or more Drupal sites that don't need/want a public facing login block, I have a pretty good solution (works for me anyway :) ). I created dynamic (javascript) bookmarks to help me do/get to a few common tasks. These work on any Drupal site since the javascript takes care of the domain and destination paths. Here is an image as an example...
And here are examples of the actual bookmark URLs
Log In | javascript:window.location='/user?destination='+window.location.pathname.substr(1);
admin | javascript:window.location='/admin';
Clear Cache | javascript:window.location='/admin/settings/performance';
Log Out | javascript:window.location='/logout';
The Log In one is particularly useful because it allows you to log in and return to the page you were just on. Obviously this is not a great solution if you have a large group of people managing a site unless they are all ok with creating the bookmarks. Also, once logged in, something like Admin or AdminMenu can take over the other links functions...but I leave them there for the rare occasion these modules are not installed or behaving...and sometime these bookmarks are just quicker to get to :)
Login only on local host?
For those working with a local host to develop the site, and then upload it to the real site.
Would it be possible to have a fully working login block when working locally but block the login through some css command that is active ONLY at the real site. Did not try it, but I think it could be done with CSS.
For example, assign a div=disable_login to the login block with some smart coding to hide or disable that that block. Put it in a separate CSS file that is located ONLY on the remote host. Your local host does not have the hiding codes so the login block gets displayed. This way, you don't have to remember to change something when uploading because the extra file is unique on the remote host and does not get overwritten when updating the site from local host.
An alternative, much more easier way would be to display the login block only on a login page and use a special URL with a rewrite_rule in htaccess to access it. For example: the SEF url mydomain/NiceWeather brings you to the login page, but no other link, hover, or whatever inside the site itself can manage that.
That way nobody but you will ever see the login page either by accident or on purpose (hackers).