forked from lda/telodendria
Begin work on validating registration request.
This commit is contained in:
parent
53846b0994
commit
f837988156
3 changed files with 52 additions and 2 deletions
3
TODO.txt
3
TODO.txt
|
@ -15,6 +15,9 @@ Milestone: v0.1.1
|
|||
[ ] Abstract /email/requestToken and /msidsn/requestToken
|
||||
|
||||
[ ] User registration
|
||||
[ ] Username validation
|
||||
[ ] Password validation
|
||||
[ ] Password hashing
|
||||
|
||||
Milestone: v1.0.0
|
||||
-----------------
|
||||
|
|
|
@ -459,5 +459,7 @@ HashMap *
|
|||
MatrixRateLimit(HttpServerContext *context, Db *db)
|
||||
{
|
||||
/* TODO: Implement rate limiting */
|
||||
(void) context;
|
||||
(void) db;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,15 @@ ROUTE_IMPL(RouteRegister, args)
|
|||
|
||||
char *pathPart = NULL;
|
||||
|
||||
JsonValue *val;
|
||||
|
||||
char *username = NULL;
|
||||
char *password = NULL;
|
||||
char *initialDeviceDisplayName = NULL;
|
||||
int refreshToken = 0;
|
||||
int inhibitLogin = 0;
|
||||
char *deviceId;
|
||||
|
||||
if (MATRIX_PATH_PARTS(args->path) == 0)
|
||||
{
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
|
@ -59,12 +68,48 @@ ROUTE_IMPL(RouteRegister, args)
|
|||
goto finish;
|
||||
}
|
||||
|
||||
response = MatrixUserInteractiveAuth(args->context, args->matrixArgs->db, request);
|
||||
response = MatrixUserInteractiveAuth(args->context,
|
||||
args->matrixArgs->db, request);
|
||||
|
||||
if (response)
|
||||
{
|
||||
goto finish;
|
||||
}
|
||||
|
||||
val = HashMapGet(request, "username");
|
||||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
username = JsonValueAsString(val);
|
||||
|
||||
val = HashMapGet(request, "password");
|
||||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
password = JsonValueAsString(val);
|
||||
|
||||
/* TODO: Register new user here */
|
||||
|
||||
finish:
|
||||
|
@ -77,7 +122,7 @@ finish:
|
|||
if (HttpRequestMethodGet(args->context) == HTTP_GET &&
|
||||
MATRIX_PATH_EQUALS(pathPart, "available"))
|
||||
{
|
||||
char *username = HashMapGet(
|
||||
username = HashMapGet(
|
||||
HttpRequestParams(args->context), "username");
|
||||
|
||||
if (!username)
|
||||
|
|
Loading…
Reference in a new issue