forked from Telodendria/Telodendria
Apply modified #57: Implement logout all.
This commit is contained in:
parent
97990c5009
commit
e4ec250d8f
5
TODO.txt
5
TODO.txt
|
@ -14,12 +14,13 @@ Milestone: v0.2.0
|
||||||
[ ] Abstract /email/requestToken and /msidsn/requestToken
|
[ ] Abstract /email/requestToken and /msidsn/requestToken
|
||||||
- Call it RouteRequestToken
|
- Call it RouteRequestToken
|
||||||
- Reference it all the places it's needed
|
- Reference it all the places it's needed
|
||||||
|
- Finish implementing JSON parsing
|
||||||
|
|
||||||
[ ] User Interactive Authentication
|
[ ] User Interactive Authentication
|
||||||
[ ] Fix UiaComplete so we can use multi-stage flows
|
[ ] Fix UiaComplete so we can use multi-stage flows
|
||||||
|
|
||||||
[~] User login
|
[x] User login
|
||||||
[ ] Logout all
|
[x] Logout all
|
||||||
|
|
||||||
[ ] Documentation
|
[ ] Documentation
|
||||||
[ ] User functions
|
[ ] User functions
|
||||||
|
|
|
@ -77,12 +77,17 @@ ROUTE_IMPL(RouteLogout, args)
|
||||||
response = MatrixErrorCreate(M_NOT_FOUND);
|
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
Free(pathPart);
|
Free(pathPart);
|
||||||
|
|
||||||
/* TODO: Implement /all */
|
if (!UserDeleteTokens(user))
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
{
|
||||||
response = MatrixErrorCreate(M_UNKNOWN);
|
/* If we can't delete all of our tokens, then something is
|
||||||
|
* wrong. */
|
||||||
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
response = MatrixErrorCreate(M_UNKNOWN);
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
response = HashMapCreate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
41
src/User.c
41
src/User.c
|
@ -599,6 +599,47 @@ UserDeleteToken(User * user, char *token)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
UserDeleteTokens(User * user)
|
||||||
|
{
|
||||||
|
HashMap *devices;
|
||||||
|
char *deviceId;
|
||||||
|
JsonValue *deviceObj;
|
||||||
|
|
||||||
|
if (!user)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
devices = JsonValueAsObject(HashMapGet(DbJson(user->ref), "devices"));
|
||||||
|
if (!devices)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (HashMapIterate(devices, &deviceId, (void **) &deviceObj))
|
||||||
|
{
|
||||||
|
HashMap *device = JsonValueAsObject(deviceObj);
|
||||||
|
char *accessToken = JsonValueAsString(HashMapGet(device, "accessToken"));
|
||||||
|
char *refreshToken = JsonValueAsString(HashMapGet(device, "refreshToken"));
|
||||||
|
|
||||||
|
if (accessToken)
|
||||||
|
{
|
||||||
|
DbDelete(user->db, 3, "tokens", "access", accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (refreshToken)
|
||||||
|
{
|
||||||
|
DbDelete(user->db, 3, "tokens", "refresh", refreshToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonValueFree(HashMapDelete(DbJson(user->ref), "devices"));
|
||||||
|
HashMapSet(DbJson(user->ref), "devices", JsonValueObject(HashMapCreate()));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
UserId *
|
UserId *
|
||||||
UserParseId(char *id, char *defaultServer)
|
UserParseId(char *id, char *defaultServer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,6 +99,9 @@ extern void
|
||||||
extern int
|
extern int
|
||||||
UserDeleteToken(User *, char *);
|
UserDeleteToken(User *, char *);
|
||||||
|
|
||||||
|
extern int
|
||||||
|
UserDeleteTokens(User *);
|
||||||
|
|
||||||
extern UserId *
|
extern UserId *
|
||||||
UserParseId(char *, char *);
|
UserParseId(char *, char *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue