Apply #65, remove printf() in Db, and make tt show login messages.

This commit is contained in:
Jordan Bancino 2023-03-15 13:36:49 +00:00
parent afc7667737
commit 5dbaf3c223
6 changed files with 35 additions and 7 deletions

View file

@ -55,8 +55,8 @@ Milestone: v0.3.0
- Ensure that registration tokens can be used even if
registration is disabled.
[~] 4: Account management
[ ] Deactivate
[ ] Make sure UserLogin() fails if user is deactivated.
[~] Deactivate
[x] Make sure UserLogin() fails if user is deactivated.
[ ] Change password
[x] Whoami
[ ] 9: User Data

View file

@ -460,7 +460,6 @@ DbLockFromArr(Db * db, Array * args)
/* Lock the file on the disk */
if (fcntl(fileno(fp), F_SETLK, &lock) < 0)
{
printf("fcntl() failed on %s (%s)\n", file, strerror(errno));
fclose(fp);
ref = NULL;
goto finish;

View file

@ -242,6 +242,15 @@ ROUTE_IMPL(RouteLogin, args)
break;
}
if (UserDeactivated(user))
{
UserUnlock(user);
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_USER_DEACTIVATED);
break;
}
loginInfo = UserLogin(user, password, deviceId,
initialDeviceDisplayName, refreshToken);

View file

@ -246,7 +246,7 @@ UserLogin(User * user, char *password, char *deviceId, char *deviceDisplayName,
return NULL;
}
if (!UserCheckPassword(user, password))
if (!UserCheckPassword(user, password) || UserDeactivated(user))
{
return NULL;
}
@ -428,6 +428,21 @@ UserDeactivate(User * user)
return 1;
}
int
UserDeactivated(User *user)
{
HashMap *json;
if (!user)
{
return 1;
}
json = DbJson(user->ref);
return JsonValueAsBoolean(HashMapGet(json, "deactivated"));
}
HashMap *
UserGetDevices(User * user)
{

View file

@ -84,6 +84,9 @@ extern int
extern int
UserDeactivate(User *);
extern int
UserDeactivated(User *);
extern HashMap *
UserGetDevices(User *);

View file

@ -26,7 +26,7 @@ if [ "$user_available" = "true" ]; then
fi
# Log in
ACCESS_TOKEN=$((
RESPONSE=$((
printf '{'
printf ' "identifier": {'
printf ' "type": "m.id.user",'
@ -35,10 +35,12 @@ ACCESS_TOKEN=$((
printf ' "type": "m.login.password",'
printf ' "password": %s' "$PASSWORD"
printf '}'
) | http -X POST -d @- "$BASE/_matrix/client/v3/login" | json -s "access_token->@decode")
) | http -X POST -d @- "$BASE/_matrix/client/v3/login")
ACCESS_TOKEN=$(echo "$RESPONSE" | json -s "access_token->@decode")
if [ -z "$ACCESS_TOKEN" ]; then
echo "Unable to log in."
echo "$RESPONSE" | json
exit 1
fi