r2 - 06 Jun 2003 - 06:35:00 - PeterThoenyYou are here: TWiki >  Support Web > DetectLogin
Tags:
, create new tag

Question

I'll like to detect if current user was logged in or not.

AFAICT we have 3 variables with user name: USERNAME% WIKINAME% WIKIUSERNAME% All 3 have same value:

If I'll turn $rememberRemoreUser off, all are TwikiGuest? . If I'll turn it on, Twiki remembers me by IP address and all 3 are my name. My view is not authorised and I do not use SessionPlugin? .

Is there any way to detect in view if my browser was logged in?

What I was hoping for was to find some TWiki variable which is TWikiGuest if browser is not authorised, and my name after browser is authorised. So I can have special user with name PleaseLogIn, display it on the skin, in User.PleaseLogIn have link to viewauthorised for existing users, and link to registration for new users. And after user authorised, instead of LogIn there will be his own name displayed.

I was hoping at least one of the variables works as I needed, but it is not the case.

Am I missing something? Is it possible? Is there another smarter way to do it?

  • TWiki version: 26 Apr 2003
  • Perl version:
  • Web server & version:
  • Server OS:
  • Web browser & version:
  • Client OS:

-- PeterMasiar - 05 Jun 2003

Answer

There is no explicit login step with basic authentication. You could use a session Plugin with cookie based authentication. Or you could simulate the login/logout with basic authentication like this:

  • Enable remember user by IP address in TWiki.cfg
  • Create a symlink from view to viewauth (search the TWiki docs for viewauth)
  • Show conditional text in the skin: "welcome guest (login)" or "welcome FooBar (logout)"
  • Use the latest SpreadSheetPlugin for conditional text; test on %WIKINAME% equals TWikiGuest.
  • login links to the same topic, but to script viewauth instead of view.
  • logout links to a page that has a %LOGOUT% variable. Add some code in a Plugin that gets activated with that variable. The code reads the remoteusers.txt file, removes the user entry and saves the file.

BTW, the three variables you mention are not the same, see details in TWikiVariables.

  • USERNAME: Intranet login name
  • WIKINAME: WikiName (identical to USERNAME if there is no login name mapping)
  • WIKIUSERNAME: Main.WikiName

-- PeterThoeny - 06 Jun 2003

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo