forked from Telodendria/Telodendria
Apply modified #57: Implement logout all.
This commit is contained in:
parent
97990c5009
commit
e4ec250d8f
4 changed files with 56 additions and 6 deletions
5
TODO.txt
5
TODO.txt
|
@ -14,12 +14,13 @@ Milestone: v0.2.0
|
|||
[ ] Abstract /email/requestToken and /msidsn/requestToken
|
||||
- Call it RouteRequestToken
|
||||
- Reference it all the places it's needed
|
||||
- Finish implementing JSON parsing
|
||||
|
||||
[ ] User Interactive Authentication
|
||||
[ ] Fix UiaComplete so we can use multi-stage flows
|
||||
|
||||
[~] User login
|
||||
[ ] Logout all
|
||||
[x] User login
|
||||
[x] Logout all
|
||||
|
||||
[ ] Documentation
|
||||
[ ] User functions
|
||||
|
|
|
@ -77,12 +77,17 @@ ROUTE_IMPL(RouteLogout, args)
|
|||
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
Free(pathPart);
|
||||
|
||||
/* TODO: Implement /all */
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
if (!UserDeleteTokens(user))
|
||||
{
|
||||
/* 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
|
||||
{
|
||||
|
|
41
src/User.c
41
src/User.c
|
@ -599,6 +599,47 @@ UserDeleteToken(User * user, char *token)
|
|||
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 *
|
||||
UserParseId(char *id, char *defaultServer)
|
||||
{
|
||||
|
|
|
@ -99,6 +99,9 @@ extern void
|
|||
extern int
|
||||
UserDeleteToken(User *, char *);
|
||||
|
||||
extern int
|
||||
UserDeleteTokens(User *);
|
||||
|
||||
extern UserId *
|
||||
UserParseId(char *, char *);
|
||||
|
||||
|
|
Loading…
Reference in a new issue