Check paths for /available and /(email|msisdn)/requestToken

This commit is contained in:
Jordan Bancino 2022-12-14 16:21:01 +00:00
parent 0305ef183d
commit 5880cf3ea0

View file

@ -28,17 +28,17 @@
#include <Json.h>
#include <HashMap.h>
#include <Util.h>
#include <Memory.h>
ROUTE_IMPL(RouteRegister, args)
{
HashMap *request = NULL;
HashMap *response = NULL;
if (MATRIX_PATH_PARTS(args->path) > 0)
char *pathPart = NULL;
if (MATRIX_PATH_PARTS(args->path) == 0)
{
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
return MatrixErrorCreate(M_NOT_FOUND);
}
if (HttpRequestMethodGet(args->context) != HTTP_POST)
{
@ -59,6 +59,46 @@ ROUTE_IMPL(RouteRegister, args)
return MatrixErrorCreate(M_NOT_JSON);
}
/* TODO: Complete account registration flow */
JsonFree(request);
}
else
{
pathPart = MATRIX_PATH_POP(args->path);
if (HttpRequestMethodGet(args->context) == HTTP_GET &&
MATRIX_PATH_EQUALS(pathPart, "available"))
{
/* TODO: Check if ?username=x is available */
}
else if (HttpRequestMethodGet(args->context) == HTTP_POST &&
(MATRIX_PATH_EQUALS(pathPart, "email") ||
MATRIX_PATH_EQUALS(pathPart, "msisdn")))
{
Free(pathPart);
pathPart = MATRIX_PATH_POP(args->path);
if (!MATRIX_PATH_EQUALS(pathPart, "requestToken"))
{
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_UNRECOGNIZED);
}
else
{
/* TODO: Validate request body and potentially return
* M_BAD_JSON */
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_THREEPID_DENIED);
}
}
else
{
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_UNRECOGNIZED);
}
Free(pathPart);
}
return response;
}