From 05cf05e423f26005bab5797f0e5b53d05ede56c5 Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 21 Apr 2020 02:39:18 +1000 Subject: Part of the validated member list code. --- src/sledjchisl/sledjchisl.c | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'src/sledjchisl/sledjchisl.c') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index b05aaa0..8980bd4 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -4761,6 +4761,96 @@ static int accountOut(reqData *Rd, inputForm *iF, inputValue *iV) return ret; } +typedef struct _RdAndListTbl RdAndListTbl; +struct _RdAndListTbl +{ + reqData *Rd; + qlisttbl_t *list; +}; +static int accountFilterValidated(struct dirtree *node) +{ + if (!node->parent) return DIRTREE_RECURSE | DIRTREE_SHUTUP; + + if (S_ISREG(node->st.st_mode)) + { + struct stat st; + struct timespec now; + RdAndListTbl *rdl = (RdAndListTbl *) node->parent->extra; + qhashtbl_t *tnm = qhashtbl(0, 0); + char *name = node->name; + char *where = xmprintf("%s/users/%s", scData, node->name); + int rt = LuaToHash(rdl->Rd, where, "user", tnm, 0, &st, &now, "user"); + +//t("accountFilterValidatedVoucher %s (%s) -> %s -> %s", name, getStrH(tnm, "level"), getStrH(tnm, "name"), getStrH(tnm, "voucher")); + if ((0 == rt) && (strcmp("-100", getStrH(tnm, "level")) == 0)) + rdl->list->put(rdl->list, getStrH(tnm, "name"), tnm, sizeof(*tnm)); + else + tnm->free(tnm); + free(where); + } + return 0; +} +qlisttbl_t *getAccounts(reqData *Rd) +{ + qlisttbl_t *ret = qlisttbl(0); + RdAndListTbl rdl = {Rd, ret}; + char *path = xmprintf("%s/users", scData); + struct dirtree *new = dirtree_add_node(0, path, 0); + + new->extra = (long) &rdl; + dirtree_handle_callback(new, accountFilterValidated); + ret->sort(ret); + free(path); + + return ret; +} +static void accountExploreValidatedVouchersWeb(reqData *Rd, inputForm *oF, inputValue *oV) +{ + qlisttbl_t *list =getAccounts(Rd); + char *name = getStrH(Rd->stuff, "name"); + + Rd->shs.UUID = NULL; + accountWebHeaders(Rd, oF, name); + accountWebFields(Rd, oF, oV); + + count = list->size(list); + Rd->reply->addstrf(Rd->reply, "\n"); + Rd->reply->addstr(Rd->reply, ""); + Rd->reply->addstr(Rd->reply, ""); + Rd->reply->addstr(Rd->reply, ""); + Rd->reply->addstr(Rd->reply, ""); + Rd->reply->addstr(Rd->reply, ""); + Rd->reply->addstr(Rd->reply, "\n"); + + qlisttbl_obj_t obj; + memset((void *) &obj, 0, sizeof(obj)); + list->lock(list); + while(list->getnext(list, &obj, NULL, false) == true) + { + qhashtbl_t *tnm = (qhashtbl_t *) obj.data; + char *nm = qstrreplace("tr", xstrdup(obj.name), " ", "_"); + + Rd->reply->addstrf(Rd->reply, "", Rd->Host, Rd->RUri, nm, obj.name); + Rd->reply->addstrf(Rd->reply, "", getStrH(tnm, "voucher"), getStrH(tnm, "level"), getStrH(tnm, "title")); + free(nm); + tnm->clear(tnm); +// TODO - crazy time again, either it frees twice, or not at all. +// list->removeobj(list, &obj); +// tnm->free(tnm); + } + list->unlock(list); + Rd->reply->addstr(Rd->reply, "
Validated users
namevoucherleveltitle
%s%s%s%s
"); + list->free(list); + + accountWebSubs(Rd, oF); + accountWebFooter(Rd, oF); +} +static int accountExploreValidatedVoucher(reqData *Rd, inputForm *iF, inputValue *iV) +{ + int ret = 0; + return ret; +} + qhashtbl_t *accountPages = NULL; inputForm *newInputForm(char *name, char *title, char *help, inputFormShowFunc web, inputFormShowFunc eWeb) @@ -5106,6 +5196,14 @@ void account_html(char *file, reqData *Rd, HTMLfile *thisFile) addSubmit(iF, "logout", "logout", NULL, accountOut, "accountLogin"); + iF = newInputForm("accountValidated", "account validated list", NULL, accountExploreValidatedVouchersWeb, accountLoginWeb); + addSession(iF); + fld = addInputField(iF, LUA_TSTRING, "name", "name", NULL, nameValidate, nameWeb); + inputFieldExtra(fld, FLD_HIDDEN, 42, 63); + addSubmit(iF, "login", "", NULL, accountView, "accountView"); // Coz we sometimes want to trigger this from code. + addSubmit(iF, "cancel", "cancel", NULL, accountView, "accountView"); + + iF = newInputForm("accountEdit", "account edit", NULL, accountEditWeb, accountLoginWeb); addSession(iF); // fld = addInputField(iF, LUA_TSTRING, "UUID", "UUID", NULL, UUIDValidate, UUIDWeb); -- cgit v1.1