Fossil SCM

Added 'L' pseudo-capability character to indicate is-logged-in, for use with th1 capexpr. Removed hard-coded addition of login/logout menu entries in skin headers, delegating them to the mainmenu setting, and added Login/Logout entries to the default mainmenu value.

stephan 2021-02-10 14:25 trunk
Commit e5240c9749e2b277049244150e5325d01811b6cb9ee8ccb69eb1bdcad167e7b2
--- skins/black_and_white/header.txt
+++ skins/black_and_white/header.txt
@@ -17,11 +17,6 @@
1717
foreach {name url expr class} $mainmenu {
1818
if {![capexpr $expr]} continue
1919
if {[string match /* $url]} {set url $home$url}
2020
html "<a href='$url'>$name</a><br/>\n"
2121
}
22
-if {[info exists login]} {
23
- html "<a href='$home/login'>Logout</a>\n"
24
-} else {
25
- html "<a href='$home/login'>Login</a>\n"
26
-}
2722
</th1></div>
2823
--- skins/black_and_white/header.txt
+++ skins/black_and_white/header.txt
@@ -17,11 +17,6 @@
17 foreach {name url expr class} $mainmenu {
18 if {![capexpr $expr]} continue
19 if {[string match /* $url]} {set url $home$url}
20 html "<a href='$url'>$name</a><br/>\n"
21 }
22 if {[info exists login]} {
23 html "<a href='$home/login'>Logout</a>\n"
24 } else {
25 html "<a href='$home/login'>Login</a>\n"
26 }
27 </th1></div>
28
--- skins/black_and_white/header.txt
+++ skins/black_and_white/header.txt
@@ -17,11 +17,6 @@
17 foreach {name url expr class} $mainmenu {
18 if {![capexpr $expr]} continue
19 if {[string match /* $url]} {set url $home$url}
20 html "<a href='$url'>$name</a><br/>\n"
21 }
 
 
 
 
 
22 </th1></div>
23
--- skins/enhanced1/header.txt
+++ skins/enhanced1/header.txt
@@ -95,11 +95,6 @@
9595
foreach {name url expr class} $mainmenu {
9696
if {![capexpr $expr]} continue
9797
if {[string match /* $url]} {set url $home$url}
9898
html "<a href='$url'>$name</a>\n"
9999
}
100
-if {[info exists login]} {
101
- html "<a href='$home/logout'>Logout</a>\n"
102
-} else {
103
- html "<a href='$home/login'>Login</a>\n"
104
-}
105100
</th1></div>
106101
--- skins/enhanced1/header.txt
+++ skins/enhanced1/header.txt
@@ -95,11 +95,6 @@
95 foreach {name url expr class} $mainmenu {
96 if {![capexpr $expr]} continue
97 if {[string match /* $url]} {set url $home$url}
98 html "<a href='$url'>$name</a>\n"
99 }
100 if {[info exists login]} {
101 html "<a href='$home/logout'>Logout</a>\n"
102 } else {
103 html "<a href='$home/login'>Login</a>\n"
104 }
105 </th1></div>
106
--- skins/enhanced1/header.txt
+++ skins/enhanced1/header.txt
@@ -95,11 +95,6 @@
95 foreach {name url expr class} $mainmenu {
96 if {![capexpr $expr]} continue
97 if {[string match /* $url]} {set url $home$url}
98 html "<a href='$url'>$name</a>\n"
99 }
 
 
 
 
 
100 </th1></div>
101
--- skins/khaki/header.txt
+++ skins/khaki/header.txt
@@ -16,12 +16,7 @@
1616
foreach {name url expr class} $mainmenu {
1717
if {![capexpr $expr]} continue
1818
if {[string match /* $url]} {set url $home$url}
1919
html "<a href='$url'>$name</a>\n"
2020
}
21
-if {[info exists login]} {
22
- html "<a href='$home/logout'>Logout</a>\n"
23
-} else {
24
- html "<a href='$home/login'>Login</a>\n"
25
-}
2621
</th1></div>
2722
<div id='hbdrop'></div>
2823
--- skins/khaki/header.txt
+++ skins/khaki/header.txt
@@ -16,12 +16,7 @@
16 foreach {name url expr class} $mainmenu {
17 if {![capexpr $expr]} continue
18 if {[string match /* $url]} {set url $home$url}
19 html "<a href='$url'>$name</a>\n"
20 }
21 if {[info exists login]} {
22 html "<a href='$home/logout'>Logout</a>\n"
23 } else {
24 html "<a href='$home/login'>Login</a>\n"
25 }
26 </th1></div>
27 <div id='hbdrop'></div>
28
--- skins/khaki/header.txt
+++ skins/khaki/header.txt
@@ -16,12 +16,7 @@
16 foreach {name url expr class} $mainmenu {
17 if {![capexpr $expr]} continue
18 if {[string match /* $url]} {set url $home$url}
19 html "<a href='$url'>$name</a>\n"
20 }
 
 
 
 
 
21 </th1></div>
22 <div id='hbdrop'></div>
23
--- skins/original/header.txt
+++ skins/original/header.txt
@@ -15,11 +15,6 @@
1515
foreach {name url expr class} $mainmenu {
1616
if {![capexpr $expr]} continue
1717
if {[string match /* $url]} {set url $home$url}
1818
html "<a href='$url'>$name</a>\n"
1919
}
20
-if {[info exists login]} {
21
- html "<a href='$home/logout'>Logout</a>\n"
22
-} else {
23
- html "<a href='$home/login'>Login</a>\n"
24
-}
2520
</th1></div>
2621
--- skins/original/header.txt
+++ skins/original/header.txt
@@ -15,11 +15,6 @@
15 foreach {name url expr class} $mainmenu {
16 if {![capexpr $expr]} continue
17 if {[string match /* $url]} {set url $home$url}
18 html "<a href='$url'>$name</a>\n"
19 }
20 if {[info exists login]} {
21 html "<a href='$home/logout'>Logout</a>\n"
22 } else {
23 html "<a href='$home/login'>Login</a>\n"
24 }
25 </th1></div>
26
--- skins/original/header.txt
+++ skins/original/header.txt
@@ -15,11 +15,6 @@
15 foreach {name url expr class} $mainmenu {
16 if {![capexpr $expr]} continue
17 if {[string match /* $url]} {set url $home$url}
18 html "<a href='$url'>$name</a>\n"
19 }
 
 
 
 
 
20 </th1></div>
21
--- skins/plain_gray/header.txt
+++ skins/plain_gray/header.txt
@@ -8,12 +8,7 @@
88
foreach {name url expr class} $mainmenu {
99
if {![capexpr $expr]} continue
1010
if {[string match /* $url]} {set url $home$url}
1111
html "<a href='$url'>$name</a>\n"
1212
}
13
-if {[info exists login]} {
14
- html "<a href='$home/logout'>Logout</a>\n"
15
-} else {
16
- html "<a href='$home/login'>Login</a>\n"
17
-}
1813
</th1></div>
1914
<div id='hbdrop' class='hbdrop'></div>
2015
--- skins/plain_gray/header.txt
+++ skins/plain_gray/header.txt
@@ -8,12 +8,7 @@
8 foreach {name url expr class} $mainmenu {
9 if {![capexpr $expr]} continue
10 if {[string match /* $url]} {set url $home$url}
11 html "<a href='$url'>$name</a>\n"
12 }
13 if {[info exists login]} {
14 html "<a href='$home/logout'>Logout</a>\n"
15 } else {
16 html "<a href='$home/login'>Login</a>\n"
17 }
18 </th1></div>
19 <div id='hbdrop' class='hbdrop'></div>
20
--- skins/plain_gray/header.txt
+++ skins/plain_gray/header.txt
@@ -8,12 +8,7 @@
8 foreach {name url expr class} $mainmenu {
9 if {![capexpr $expr]} continue
10 if {[string match /* $url]} {set url $home$url}
11 html "<a href='$url'>$name</a>\n"
12 }
 
 
 
 
 
13 </th1></div>
14 <div id='hbdrop' class='hbdrop'></div>
15
--- skins/rounded1/header.txt
+++ skins/rounded1/header.txt
@@ -16,11 +16,6 @@
1616
foreach {name url expr class} $mainmenu {
1717
if {![capexpr $expr]} continue
1818
if {[string match /* $url]} {set url $home$url}
1919
html "<a href='$url'>$name</a>\n"
2020
}
21
-if {[info exists login]} {
22
- html "<a href='$home/logout'>Logout</a>\n"
23
-} else {
24
- html "<a href='$home/login'>Login</a>\n"
25
-}
2621
</th1></div>
2722
--- skins/rounded1/header.txt
+++ skins/rounded1/header.txt
@@ -16,11 +16,6 @@
16 foreach {name url expr class} $mainmenu {
17 if {![capexpr $expr]} continue
18 if {[string match /* $url]} {set url $home$url}
19 html "<a href='$url'>$name</a>\n"
20 }
21 if {[info exists login]} {
22 html "<a href='$home/logout'>Logout</a>\n"
23 } else {
24 html "<a href='$home/login'>Login</a>\n"
25 }
26 </th1></div>
27
--- skins/rounded1/header.txt
+++ skins/rounded1/header.txt
@@ -16,11 +16,6 @@
16 foreach {name url expr class} $mainmenu {
17 if {![capexpr $expr]} continue
18 if {[string match /* $url]} {set url $home$url}
19 html "<a href='$url'>$name</a>\n"
20 }
 
 
 
 
 
21 </th1></div>
22
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -92,13 +92,14 @@
9292
updateClock();
9393
</script>
9494
<div class="mainmenu"><th1>
9595
foreach {name url expr class} $mainmenu {
9696
if {![capexpr $expr]} continue
97
- html "<a href='$home$url'>$name</a>\n"
98
-}
99
-if {[info exists login]} {
100
- html "<a href='$home/logout'>Logout</a>\n"
101
-} else {
102
- html "<a href='$home/login'>Login</a>\n"
97
+ if {[string match /* $url]} {
98
+ if {[string match /$current_page* $url]} {
99
+ set class "active $class"
100
+ }
101
+ set url $home$url
102
+ }
103
+ html "<a href='$url' class='$class'>$name</a>\n"
103104
}
104105
</th1></div>
105106
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -92,13 +92,14 @@
92 updateClock();
93 </script>
94 <div class="mainmenu"><th1>
95 foreach {name url expr class} $mainmenu {
96 if {![capexpr $expr]} continue
97 html "<a href='$home$url'>$name</a>\n"
98 }
99 if {[info exists login]} {
100 html "<a href='$home/logout'>Logout</a>\n"
101 } else {
102 html "<a href='$home/login'>Login</a>\n"
 
103 }
104 </th1></div>
105
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -92,13 +92,14 @@
92 updateClock();
93 </script>
94 <div class="mainmenu"><th1>
95 foreach {name url expr class} $mainmenu {
96 if {![capexpr $expr]} continue
97 if {[string match /* $url]} {
98 if {[string match /$current_page* $url]} {
99 set class "active $class"
100 }
101 set url $home$url
102 }
103 html "<a href='$url' class='$class'>$name</a>\n"
104 }
105 </th1></div>
106
--- src/login.c
+++ src/login.c
@@ -1330,10 +1330,13 @@
13301330
13311331
/*
13321332
** If the current login lacks any of the capabilities listed in
13331333
** the input, then return 0. If all capabilities are present, then
13341334
** return 1.
1335
+**
1336
+** As a special case, the 'L' pseudo-capability ID means "is logged
1337
+** in" and will return true for any non-guest user.
13351338
*/
13361339
int login_has_capability(const char *zCap, int nCap, u32 flgs){
13371340
int i;
13381341
int rc = 1;
13391342
FossilUserPerms *p = (flgs & LOGIN_ANON) ? &g.anon : &g.perm;
@@ -1373,10 +1376,14 @@
13731376
case '6': rc = p->AdminForum;break;
13741377
case '7': rc = p->EmailAlert;break;
13751378
case 'A': rc = p->Announce; break;
13761379
case 'C': rc = p->Chat; break;
13771380
case 'D': rc = p->Debug; break;
1381
+ case 'L': rc = g.zLogin && *g.zLogin; break;
1382
+ /* Mainenance reminder: '@' should not be used because
1383
+ it would semantically collide with the @ in the
1384
+ capexpr TH1 command. */
13781385
default: rc = 0; break;
13791386
}
13801387
}
13811388
return rc;
13821389
}
13831390
--- src/login.c
+++ src/login.c
@@ -1330,10 +1330,13 @@
1330
1331 /*
1332 ** If the current login lacks any of the capabilities listed in
1333 ** the input, then return 0. If all capabilities are present, then
1334 ** return 1.
 
 
 
1335 */
1336 int login_has_capability(const char *zCap, int nCap, u32 flgs){
1337 int i;
1338 int rc = 1;
1339 FossilUserPerms *p = (flgs & LOGIN_ANON) ? &g.anon : &g.perm;
@@ -1373,10 +1376,14 @@
1373 case '6': rc = p->AdminForum;break;
1374 case '7': rc = p->EmailAlert;break;
1375 case 'A': rc = p->Announce; break;
1376 case 'C': rc = p->Chat; break;
1377 case 'D': rc = p->Debug; break;
 
 
 
 
1378 default: rc = 0; break;
1379 }
1380 }
1381 return rc;
1382 }
1383
--- src/login.c
+++ src/login.c
@@ -1330,10 +1330,13 @@
1330
1331 /*
1332 ** If the current login lacks any of the capabilities listed in
1333 ** the input, then return 0. If all capabilities are present, then
1334 ** return 1.
1335 **
1336 ** As a special case, the 'L' pseudo-capability ID means "is logged
1337 ** in" and will return true for any non-guest user.
1338 */
1339 int login_has_capability(const char *zCap, int nCap, u32 flgs){
1340 int i;
1341 int rc = 1;
1342 FossilUserPerms *p = (flgs & LOGIN_ANON) ? &g.anon : &g.perm;
@@ -1373,10 +1376,14 @@
1376 case '6': rc = p->AdminForum;break;
1377 case '7': rc = p->EmailAlert;break;
1378 case 'A': rc = p->Announce; break;
1379 case 'C': rc = p->Chat; break;
1380 case 'D': rc = p->Debug; break;
1381 case 'L': rc = g.zLogin && *g.zLogin; break;
1382 /* Mainenance reminder: '@' should not be used because
1383 it would semantically collide with the @ in the
1384 capexpr TH1 command. */
1385 default: rc = 0; break;
1386 }
1387 }
1388 return rc;
1389 }
1390
--- src/style.c
+++ src/style.c
@@ -610,10 +610,12 @@
610610
@ Forum /forum {@2 3 4 5 6} wideonly
611611
@ Chat /chat C wideonly
612612
@ Tickets /ticket r wideonly
613613
@ Wiki /wiki j wideonly
614614
@ Setup /setup s {}
615
+@ Logout /logout L {}
616
+@ Login /login !L {}
615617
;
616618
617619
/*
618620
** Return the default menu
619621
*/
620622
--- src/style.c
+++ src/style.c
@@ -610,10 +610,12 @@
610 @ Forum /forum {@2 3 4 5 6} wideonly
611 @ Chat /chat C wideonly
612 @ Tickets /ticket r wideonly
613 @ Wiki /wiki j wideonly
614 @ Setup /setup s {}
 
 
615 ;
616
617 /*
618 ** Return the default menu
619 */
620
--- src/style.c
+++ src/style.c
@@ -610,10 +610,12 @@
610 @ Forum /forum {@2 3 4 5 6} wideonly
611 @ Chat /chat C wideonly
612 @ Tickets /ticket r wideonly
613 @ Wiki /wiki j wideonly
614 @ Setup /setup s {}
615 @ Logout /logout L {}
616 @ Login /login !L {}
617 ;
618
619 /*
620 ** Return the default menu
621 */
622
--- www/caps/ref.html
+++ www/caps/ref.html
@@ -422,10 +422,22 @@
422422
<th>Debug</th>
423423
<td>
424424
Enable debugging features. Mnemonic: <b>d</b>ebug.
425425
</td>
426426
</tr>
427
+
428
+ <tr id="L">
429
+ <th>L</th>
430
+ <th>Is-logged-in</th>
431
+ <td>
432
+ This is not a real capability, but is used in certain capability
433
+ checks, e.g. via <a href="../th1.md#capexpr">capexpr</a>. It
434
+ resolves to true if the current user is logged in.
435
+ Mnemonic: <b>L</b>ogged in.
436
+ </td>
437
+ </tr>
438
+
427439
</table>
428440
429441
<hr/>
430442
431443
<p id="backlink"><a href="./"><em>Back to Administering User
432444
--- www/caps/ref.html
+++ www/caps/ref.html
@@ -422,10 +422,22 @@
422 <th>Debug</th>
423 <td>
424 Enable debugging features. Mnemonic: <b>d</b>ebug.
425 </td>
426 </tr>
 
 
 
 
 
 
 
 
 
 
 
 
427 </table>
428
429 <hr/>
430
431 <p id="backlink"><a href="./"><em>Back to Administering User
432
--- www/caps/ref.html
+++ www/caps/ref.html
@@ -422,10 +422,22 @@
422 <th>Debug</th>
423 <td>
424 Enable debugging features. Mnemonic: <b>d</b>ebug.
425 </td>
426 </tr>
427
428 <tr id="L">
429 <th>L</th>
430 <th>Is-logged-in</th>
431 <td>
432 This is not a real capability, but is used in certain capability
433 checks, e.g. via <a href="../th1.md#capexpr">capexpr</a>. It
434 resolves to true if the current user is logged in.
435 Mnemonic: <b>L</b>ogged in.
436 </td>
437 </tr>
438
439 </table>
440
441 <hr/>
442
443 <p id="backlink"><a href="./"><em>Back to Administering User
444
+14
--- www/th1.md
+++ www/th1.md
@@ -285,11 +285,25 @@
285285
```
286286
capexpr {j o r} True if any one of j, o, or r are available
287287
capexpr {oh} True if both o and h are available
288288
capexpr {@2 @3 4 5 6} 2 or 3 available for anonymous or one of
289289
4, 5 or 6 is available for the user
290
+ capexpr L True if the user is logged in
291
+ capexpr !L True if the user is not logged in
292
+```
293
+
294
+The `L` pseudo-capability is intended only to be used on its own or with
295
+the `!` prefix for implementing login/logout menus via the `mainmenu`
296
+site configuration option:
297
+
298
+```
299
+Login /login !L {}
300
+Logout /logout L {}
290301
```
302
+
303
+i.e. if the user is logged in, show the "Logout" link, else show the
304
+"Login" link.
291305
292306
<a id="captureTh1"></a>TH1 captureTh1 Command
293307
-----------------------------------------------------
294308
295309
* captureTh1 STRING
296310
--- www/th1.md
+++ www/th1.md
@@ -285,11 +285,25 @@
285 ```
286 capexpr {j o r} True if any one of j, o, or r are available
287 capexpr {oh} True if both o and h are available
288 capexpr {@2 @3 4 5 6} 2 or 3 available for anonymous or one of
289 4, 5 or 6 is available for the user
 
 
 
 
 
 
 
 
 
 
 
290 ```
 
 
 
291
292 <a id="captureTh1"></a>TH1 captureTh1 Command
293 -----------------------------------------------------
294
295 * captureTh1 STRING
296
--- www/th1.md
+++ www/th1.md
@@ -285,11 +285,25 @@
285 ```
286 capexpr {j o r} True if any one of j, o, or r are available
287 capexpr {oh} True if both o and h are available
288 capexpr {@2 @3 4 5 6} 2 or 3 available for anonymous or one of
289 4, 5 or 6 is available for the user
290 capexpr L True if the user is logged in
291 capexpr !L True if the user is not logged in
292 ```
293
294 The `L` pseudo-capability is intended only to be used on its own or with
295 the `!` prefix for implementing login/logout menus via the `mainmenu`
296 site configuration option:
297
298 ```
299 Login /login !L {}
300 Logout /logout L {}
301 ```
302
303 i.e. if the user is logged in, show the "Logout" link, else show the
304 "Login" link.
305
306 <a id="captureTh1"></a>TH1 captureTh1 Command
307 -----------------------------------------------------
308
309 * captureTh1 STRING
310

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button