forked from lda/telodendria
Finish up Uia fallback.
This commit is contained in:
parent
5431c2cd90
commit
737e060243
3 changed files with 33 additions and 17 deletions
|
@ -67,7 +67,11 @@ ROUTE_IMPL(RouteStaticResources, path, argp)
|
||||||
" var xhr = new XMLHttpRequest();"
|
" var xhr = new XMLHttpRequest();"
|
||||||
" xhr.open(meth, url);"
|
" xhr.open(meth, url);"
|
||||||
" xhr.setRequestHeader('Content-Type', 'application/json');"
|
" xhr.setRequestHeader('Content-Type', 'application/json');"
|
||||||
" xhr.onreadystatechange = () => cb(xhr);"
|
" xhr.onreadystatechange = () => {"
|
||||||
|
" if (xhr.readyState == 4) {"
|
||||||
|
" cb(xhr);"
|
||||||
|
" }"
|
||||||
|
" };"
|
||||||
" xhr.send(JSON.stringify(json));"
|
" xhr.send(JSON.stringify(json));"
|
||||||
"}"
|
"}"
|
||||||
"function onFormSubmit(frm, cb) {"
|
"function onFormSubmit(frm, cb) {"
|
||||||
|
|
|
@ -67,19 +67,14 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
||||||
return MatrixErrorCreate(M_NOT_JSON);
|
return MatrixErrorCreate(M_NOT_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LOG_DEBUG, "Building flows...");
|
|
||||||
flow = ArrayCreate();
|
flow = ArrayCreate();
|
||||||
flows = ArrayCreate();
|
flows = ArrayCreate();
|
||||||
ArrayAdd(flow, UiaStageBuild(authType, NULL));
|
ArrayAdd(flow, UiaStageBuild(authType, NULL));
|
||||||
ArrayAdd(flows, flow);
|
ArrayAdd(flows, flow);
|
||||||
Log(LOG_DEBUG, "about to UiaComplete()...");
|
|
||||||
uiaResult = UiaComplete(flows, args->context,
|
uiaResult = UiaComplete(flows, args->context,
|
||||||
args->matrixArgs->db, request, &response, config);
|
args->matrixArgs->db, request, &response, config);
|
||||||
Log(LOG_DEBUG, "Freeing flows...");
|
|
||||||
UiaFlowsFree(flows);
|
UiaFlowsFree(flows);
|
||||||
|
|
||||||
Log(LOG_DEBUG, "Completed UIA.");
|
|
||||||
|
|
||||||
if (uiaResult < 0)
|
if (uiaResult < 0)
|
||||||
{
|
{
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
@ -123,12 +118,26 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
||||||
"<input type=\"submit\" value=\"Authenticate\">");
|
"<input type=\"submit\" value=\"Authenticate\">");
|
||||||
HtmlEndForm(stream);
|
HtmlEndForm(stream);
|
||||||
HtmlBeginJs(stream);
|
HtmlBeginJs(stream);
|
||||||
/* TODO */
|
StreamPrintf(stream,
|
||||||
StreamPuts(stream,
|
|
||||||
"function buildRequest() {"
|
"function buildRequest() {"
|
||||||
" setFormError('Not implemented yet.');"
|
" let user = document.getElementById('user').value;"
|
||||||
" return false;"
|
" let pass = document.getElementById('password').value;"
|
||||||
"}");
|
" if (!user || !pass) {"
|
||||||
|
" setFormError('Please specify a username and password.');"
|
||||||
|
" return false;"
|
||||||
|
" }"
|
||||||
|
" return {"
|
||||||
|
" auth: {"
|
||||||
|
" type: '%s',"
|
||||||
|
" identifier: {"
|
||||||
|
" type: 'm.id.user',"
|
||||||
|
" user: user"
|
||||||
|
" },"
|
||||||
|
" password: pass,"
|
||||||
|
" session: '%s'"
|
||||||
|
" }"
|
||||||
|
" };"
|
||||||
|
"}", authType, sessionId);
|
||||||
HtmlEndJs(stream);
|
HtmlEndJs(stream);
|
||||||
}
|
}
|
||||||
else if (strcmp(authType, "m.login.registration_token") == 0)
|
else if (strcmp(authType, "m.login.registration_token") == 0)
|
||||||
|
@ -171,9 +180,11 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlBeginJs(stream);
|
HtmlBeginJs(stream);
|
||||||
StreamPuts(stream,
|
StreamPrintf(stream,
|
||||||
"function processResponse(xhr) {"
|
"function processResponse(xhr) {"
|
||||||
" if (xhr.status == 200) {"
|
" let r = JSON.parse(xhr.responseText);"
|
||||||
|
" console.log(r);"
|
||||||
|
" if (xhr.status == 200 || r.completed.includes('%s')) {"
|
||||||
" if (window.onAuthDone) {"
|
" if (window.onAuthDone) {"
|
||||||
" window.onAuthDone();"
|
" window.onAuthDone();"
|
||||||
" } else if (window.opener && window.opener.postMessage) {"
|
" } else if (window.opener && window.opener.postMessage) {"
|
||||||
|
@ -181,12 +192,12 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
||||||
" } else {"
|
" } else {"
|
||||||
" setFormError('Client error.');"
|
" setFormError('Client error.');"
|
||||||
" }"
|
" }"
|
||||||
|
" } else if (r.session != '%s') {"
|
||||||
|
" setFormError('Invalid session.');"
|
||||||
" } else {"
|
" } else {"
|
||||||
" console.log(xhr.responseText);"
|
" setFormError('Invalid credentials.');"
|
||||||
" let r = JSON.parse(xhr.responseText);"
|
|
||||||
" setFormError(`${r.errcode}: ${r.error}`);"
|
|
||||||
" }"
|
" }"
|
||||||
"}");
|
"}", authType, sessionId);
|
||||||
|
|
||||||
StreamPuts(stream,
|
StreamPuts(stream,
|
||||||
"onFormSubmit('auth-form', (frm) => {"
|
"onFormSubmit('auth-form', (frm) => {"
|
||||||
|
|
|
@ -33,3 +33,4 @@ fi
|
||||||
|
|
||||||
export PATH="$(pwd)/tools/bin:$(pwd)/build/tools:$PATH"
|
export PATH="$(pwd)/tools/bin:$(pwd)/build/tools:$PATH"
|
||||||
export MANPATH="$(pwd)/man:$MANPATH"
|
export MANPATH="$(pwd)/man:$MANPATH"
|
||||||
|
export MALLOC_OPTIONS="CFGJS"
|
||||||
|
|
Loading…
Reference in a new issue