commit 72c78cdffe5c608e61c0da4dff6675640854a645
parent 347ca498726cd4b495130349d066c3b038b2afec
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Tue, 26 Mar 2024 19:55:09 -0700
Add and use tk_prompt_login function
This is the new standard function for a page to use when authentication
is required but missing.
Diffstat:
6 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/pages/account.c b/pages/account.c
@@ -21,7 +21,7 @@ pageaccount(struct pagedata *pd)
enum kcgi_err status;
if (!pd->user)
- return errorpage(pd, KHTTP_401);
+ return tk_prompt_login(pd);
if (pd->req.fieldmap[KeyDelete]) {
k = pd->req.fieldmap[KeyDelete]->parsed.s;
diff --git a/pages/archive.c b/pages/archive.c
@@ -92,7 +92,7 @@ pagearchive(struct pagedata *pd)
struct timesheet *times, *firsttimes;
if (!pd->user)
- errorpage(pd, KHTTP_401);
+ return tk_prompt_login(pd);
if ((status = tk_startpage(pd, &template, KHTTP_200)) != KCGI_OK)
return status;
diff --git a/pages/common.c b/pages/common.c
@@ -127,3 +127,9 @@ tk_errorpage(struct pagedata *pd, enum khttp code)
return status;
return tk_endpage(pd, &template);
}
+
+enum kcgi_err
+tk_prompt_login(struct pagedata *pd)
+{
+ return redirect(pd, pd->pages[PageLogin], "Page requires authentication");
+}
diff --git a/pages/common.h b/pages/common.h
@@ -16,3 +16,4 @@ enum kcgi_err tk_startpage(struct pagedata *pd, struct pagetemplate *t,
enum khttp code);
enum kcgi_err tk_htmlerror(struct pagedata *pd, char *fmt, ...);
enum kcgi_err tk_errorpage(struct pagedata *pd, enum khttp code);
+enum kcgi_err tk_prompt_login(struct pagedata *pd);
diff --git a/pages/export.c b/pages/export.c
@@ -34,7 +34,7 @@ pageexport(struct pagedata *pd)
unsigned int period;
if (!pd->user)
- return errorpage(pd, KHTTP_401);
+ return tk_prompt_login(pd);
if (pd->req.fieldmap[KeyFormat]) {
/*
diff --git a/pages/main.c b/pages/main.c
@@ -347,7 +347,7 @@ pagemain(struct pagedata *pd)
int menuoffset;
if (!pd->user)
- return errorpage(pd, KHTTP_401);
+ return tk_prompt_login(pd);
period = pd->req.fieldmap[KeyPeriod] ?
pd->req.fieldmap[KeyPeriod]->parsed.i : 0;