Need to modify the "Your are logged in as...(Logout)" link text

Need to modify the "Your are logged in as...(Logout)" link text

by Fred Lunau -
Number of replies: 24
Hi,

For reason of authentication, I need to remove the "(Logout)" string at the end of the "You are logged in as foo.bar (Logout)" string in the header and footer.

Can someone please point me to where I can make the change? Moodle seems to generate this in the context variable $menu, but I can't seem to find where this is defined in order to remove this (Logout).

Thanks,

Fred

ps: I need to remove the "Logout" given a custom SSO plug-in, to avoid confusing the user...
Average of ratings: -
In reply to Fred Lunau

Re: Need to modify the "Your are logged in as...(Logout)" link text

by Ann Adamcik -
Fred,

In this case, the parenthesis around the logout string are hard-coded, and the string doesn't have an id or classname, so you can't use css to hide just the '(Logout)' part.

You can hide the entire 'You are logged in as...' string by adding this to your theme's stylesheet -

.logininfo {
display: none;
}

(Note that you'll need to provide some other way for users to get to their profiles.)

Or, you can edit the code in lib/weblib.php, on about line 3442, in user_login_string() (1.9.2+):

$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '.
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';

Comment out the above line and add the following:

$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username);

In reply to Ann Adamcik

Re: Need to modify the "Your are logged in as...(Logout)" link text

by Thomas Hanley -
Hi,

Thanks for the useful info Ann. I am trying to style the login elements described above. Specifically I would like to put the Login and Logout pieces of text onto the line below the lines 'You are not logged in.' and 'You are logged in as: Name'.

However, both pieces of text appear as links within the div.logininfo. Neither of these links have ids so I don't think this is possible with CSS (I have just tried for several hours!).

I can't target them with CSS selectors because when the logout link is displayed it is the second <a> element within the div.logininfo.

In order to target them am I right in thinking someone will have to add ids into a PHP file somewhere?

Any info or help would be appreciated.

~thomas

In reply to Thomas Hanley

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by May Nightsage -
1) The parentheses are hard coded but they can be removed without any problems as far as I have seen.

Do this for all the code that refers to 'login,' 'logout,' 'switchrolereturn,' and 'loggedinas'
In my weblib.php this runs from lines 3477 to 3497

Remove the ( that occurs after the " and the ) that is just before the last ';

Original:

$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';

After:

$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
" <a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>';


2) To put a line break between login status (ie "You are logged in as..." or "You are not logged in.") and the 'login' link, you can add two br tags and appropriate php code:

For example, to make a line break between the 'logged in as' text and the 'logout' link, do the following:

Before:

$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).
" <a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>';


After:

$loggedinas = get_string('loggedinnot', 'moodle').
'<br><br>' . " <a $CFG->frametarget href=\"$wwwroot/login/index.php\">".get_string('login').'</a>';
}


Again, you can do this to all the code that refers to 'login,' 'logout,' 'switchrolereturn,' and 'loggedinas' to keep everything looking uniform.


BE VERY CAREFUL when editing. Remove the wrong parenthesis or forget to add a '. and you probably don't need me to warn you of how that will mess up your site.

Hope this helps you!

I have also been able to add style tags to my theme's css and then apply them to the php strings for 'login' and 'logout.' I didn't want to put that on here too as I know this all can be confusing enough. Feel free to message me if you have more questions about this, thanks!
In reply to May Nightsage

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Thomas Hanley -
Hi May,

Many thanks for your very helpful explanation. Everything works as you have described it.

I am trying now to hide the text: 'you are logged in as' and 'you are not logged in'. feel that this text is redundant. I would like Moodle just to show:

Login (when user is not logged in)

and

Username Logout (when user is logged in)

I have tried language editing: leaving an empty string but Moodle detects this. Whilst writing this post I had an idea to use a HTML character entity for a space &#160;

This actually does trick Moodle but is a horrible hack! I do not know anything much about PHP at all (I am an XHTML/CSS developer). Is there a way to address the PHP variable '
loggedinnot' using CSS? I would then set it to display: none; using CSS.

Is this what you meant when you wrote:

I have also been able to add style tags to my theme's css and then apply them to the php strings for 'login' and 'logout.'

Any advice on how to do this would be appreciated.

Many thanks

~thomas
In reply to Thomas Hanley

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Stephen Macchia -
love the MS Word HTML output above :S

I presume you are looking for a hook? You can add a <span> with a class name where the double line break is above with out any problems. You wont be able to select a string with CSS across all browsers.
In reply to Stephen Macchia

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Thomas Hanley -

Hi Stephen,

Many thanks for the info. So you can select a PHP string with CSS? Any pointers on how to do this would be appreciated. I am just curious how this works (and in which browsers it doesn't work!

~thomas

In reply to Thomas Hanley

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Stephen Macchia -
Hi Thomas, No you can't select a PHP string with CSS because PHP is run at server. What I ment was that you can create a new hook for your css adapting the above code.

So in stead of using this new adaption:

$loggedinas = get_string('loggedinnot', 'moodle').
'<br><br>' . " <a $CFG->frametarget href=\"$wwwroot/login/index.php\">".get_string('login').'</a>';
}


you would use

$loggedinas = get_string('loggedinnot', 'moodle').
'<span class=\"someClass\">' . " <a $CFG->frametarget href=\"$wwwroot/login/index.php\">".get_string('login').'</a></span>';
}

In reply to Stephen Macchia

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Thomas Hanley -

Hi Stephen,

Thanks for the clarification. I guess this is what May also meant. Whereas I was complexifying things by imagining that you could directly access PHP variables from CSS.

~thomas

In reply to Stephen Macchia

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Stanick Grascher -
This has all been very helpful and thanks for taking the time to explain.

I have another issue though.

A client has asked us to move the loginifro string below the nav bar...

any ideas on how to do this?

Thanks!
In reply to Stanick Grascher

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
You could try wrapping your login code with a new set of div tags with it's own unique id selector and place it below the breadcrumb navigation in the header, and then format it via CSS file.

That's if I am reading your request correctly?

Mary
In reply to Mary Evans

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Stanick Grascher -
Thanks, Mary. Which library file would the code be modified in? Nickstan
In reply to Stanick Grascher

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
header.html (which you will find in your current theme's folder)

Mary



In reply to Stanick Grascher

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Frank Ralf -
Hi Stanick,

Have a look at Themes_FAQ#Moving_things for some ideas, especially at http://moodle.org/mod/forum/discuss.php?d=128599

hth
Frank
In reply to Frank Ralf

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Heinser Diaz -

Hello everybody,

I'm using the standard theme on my site. I already have a logo on the header, but i want it to expand horizontally 100%,. if i do that the "you are logged in as.." will be blocked or not visualized.

there is a thin black line below the logoon standard theme, and my question is. can i move the login info section below the line on the right side.

Thanks

In reply to Thomas Hanley

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Miguel Sanchez -

Hi everybody,

I'm trying to do the same thing, would you please tell which file from the language package do I have to edit to remove the "you are now logged in as" message.

Thank you!

In reply to Miguel Sanchez

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

If you want to remove the message from your page, then I would suggest using css to hide it rather than deleting/editing it in the language pack as that would affect every theme on your site.

Off the top of my head (so you may need to check this yourself) I think its

.logininfo {display:none;}

but I can't remember whether its .logininfo or #logininfo (whether its a class or an id selector). You'd need to add this line to the end of your main css file in the theme - or on the customcss box of the theme's settings page if it has one.

HTH

Richard

In reply to Thomas Hanley

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Miguel Sanchez -

Hi Thomas,

Could you please tell how did you do that, I mean which file did you modify.

I've been trying to find it in the language editor with no success.

Thank you in advance,

Miguel S.

In reply to Miguel Sanchez

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

moodle/lang/en/moodle.php

In reply to Mary Evans

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Miguel Sanchez -

Thank you Mary,

It was just right there.

In reply to Miguel Sanchez

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Thomas Hanley -

Hi Miguel,

Just to be clear, this was an issue for me in Moodle 1.9. Our site has now moved to Moodle 2 and a theme which I based on the Aardvark theme. So if you were using Moodle 2 and Aardvark the hack below is not needed. I have pasted in notes I made at the time though in case you are using 1.9 and if so they may help.

To change the text: “You are logged in as” you need to edit the language files and the weblib.php

Language files:
Admin ->Language ->Language Editing ->Moodle.php

If you try to remove the text: ‘”you are not logged in” from the language file ie. leave a blank string then Moodle will detect this and prevent you from doing so, with a blank string error message.

To remove the text you have to remove the call to write this text out from within weblib.php

Weblib.php
Location is: /web/lib/weblib.php within your Moodle directory structure.

...as described in the above posts.

Hope this helps.

~t

In reply to Thomas Hanley

Re: Need to modify the "Your are logged in as...(Logout)" link text - Here is a solution

by Miguel Sanchez -

Hi Thomas,

Thank you very much for taking the time to explain me all this, it also worked as you said, especially in the case of leaving it blank.

Thank you very much!

Miguel S.

In reply to Ann Adamcik

Odp: Re: Need to modify the "Your are logged in as...(Logout)" link text

by Tomasz Woźniczka -

In Moodle 2.3+ you can find lines

$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '.
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';

in \lib\outputrenders.php file, on about line 486.

In reply to Tomasz Woźniczka

Re: Odp: Re: Need to modify the "Your are logged in as...(Logout)" link text

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

That is useful to know thanks!