01.12.2012 Views

7 Components: the Function Pages - Developers

7 Components: the Function Pages - Developers

7 Components: the Function Pages - Developers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

29 &TWiki::Store::readFile(<br />

30 $TWiki::remoteUserFilename );<br />

31 my @line = split( /\n/, $text );<br />

32<br />

33 # entry of new file<br />

34 my $newtext;<br />

35<br />

36 # find current user in file<br />

37 for (my $i = 0; $i < scalar(@line); $i++)<br />

38 {<br />

39 if (!grep(/\|$<strong>the</strong>RemoteUser\|/,<br />

40 $line[$i]))<br />

41 {<br />

42 $newtext .= $line[$i]."\n";<br />

43 }<br />

44 }<br />

45<br />

46 # save new file<br />

47 &TWiki::Store::saveFile(<br />

48 $TWiki::remoteUserFilename, $newtext );<br />

49<br />

50 # display confirmation page<br />

51 TWiki::redirect($query,<br />

52 TWiki::getOopsUrl("Main", "WebHome",<br />

53 "oopslogoff", $<strong>the</strong>RemoteUser));<br />

First of all, a few preparations are made that refer to <strong>the</strong> work relationship<br />

(lines 4-13). This is necessary to be able to integrate <strong>the</strong> libraries<br />

in <strong>the</strong> next step (lines 16-19). The variable $query (line 21)<br />

will be required later when a confirmation message is displayed. In<br />

line 24f., <strong>the</strong> current user is determined if <strong>the</strong>re is a corresponding<br />

entry. O<strong>the</strong>rwise, <strong>the</strong> value of $<strong>the</strong>RemoteUser is “guest.”<br />

Now, <strong>the</strong> registration file must be loaded and split into individual<br />

lines for fur<strong>the</strong>r processing (lines 28-31). Note that we do not use<br />

absolute file names and paths here, but ra<strong>the</strong>r <strong>the</strong> names specified in<br />

Twiki.cfg (via $TWiki::remoteUserFilename). Next, we see<br />

<strong>the</strong> heart of <strong>the</strong> script (lines 33-44): We put toge<strong>the</strong>r <strong>the</strong> text ($newtext)<br />

of a new file in which all entries are adopted that do not contain<br />

<strong>the</strong> name of <strong>the</strong> current user (line 39). This text saves <strong>the</strong> script<br />

in <strong>the</strong> file (lines 47f). Then, we redirect <strong>the</strong> browser to <strong>the</strong> display of<br />

a logout confirmation. (lines 51-53). When doing so, we make use of<br />

<strong>the</strong> Oops scripts that is generally used in TWiki to display messages.<br />

The first two parameters of TWiki::getOopsUrl indicate <strong>the</strong><br />

TWiki page to which <strong>the</strong> OK link leads. The next entry refers to <strong>the</strong><br />

14.6 A Mixed Strategy for Au<strong>the</strong>ntication �<br />

�<br />

�<br />

215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!