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 - Ensure that registration tokens can be used even if
registration is disabled. registration is disabled.
[~] 4: Account management [~] 4: Account management
[ ] Deactivate [~] Deactivate
[ ] Make sure UserLogin() fails if user is deactivated. [x] Make sure UserLogin() fails if user is deactivated.
[ ] Change password [ ] Change password
[x] Whoami [x] Whoami
[ ] 9: User Data [ ] 9: User Data

View file

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

View file

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

View file

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

View file

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

View file

@ -26,7 +26,7 @@ if [ "$user_available" = "true" ]; then
fi fi
# Log in # Log in
ACCESS_TOKEN=$(( RESPONSE=$((
printf '{' printf '{'
printf ' "identifier": {' printf ' "identifier": {'
printf ' "type": "m.id.user",' printf ' "type": "m.id.user",'
@ -35,10 +35,12 @@ ACCESS_TOKEN=$((
printf ' "type": "m.login.password",' printf ' "type": "m.login.password",'
printf ' "password": %s' "$PASSWORD" printf ' "password": %s' "$PASSWORD"
printf '}' 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 if [ -z "$ACCESS_TOKEN" ]; then
echo "Unable to log in." echo "$RESPONSE" | json
exit 1 exit 1
fi fi