Skip to content

Commit

Permalink
Add a setting to disable form login (#213)
Browse files Browse the repository at this point in the history
When form login is disabled, a user can only login to his account using a JWT.
Resuming and guest login are still allowed.
  • Loading branch information
xsyann authored Nov 22, 2022
1 parent ce2ffeb commit 5a1c005
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ Please note, that as stated in section `Deploy in production`, there is an addit
"allowAccountCreation": "all", // all for everyone, none for no-one, except:lvl_xxx to block a level
"allowLevelCreation": true,
"allowProfileEdition": true, // Shows 'My account' tab in the user settings menu
"allowFormLogin": true, // Disable to only allow JWT login (make sure to configure 'jwtAuthSecret' in this case)
"contactURL": ""
},

Expand Down
1 change: 1 addition & 0 deletions app/_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"allowAccountCreation": "all",
"allowLevelCreation": true,
"allowProfileEdition": true,
"allowFormLogin": true,
"contactURL": ""
},

Expand Down
1 change: 1 addition & 0 deletions app/settings-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"allowAccountCreation": "all",
"allowLevelCreation": true,
"allowProfileEdition": true,
"allowFormLogin": true,
"contactURL": "",
"guest": {
"changeSkin": false,
Expand Down
2 changes: 1 addition & 1 deletion core/client/lemverse.hbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
</div>

{{#if and guest (not onboarding)}}
{{#if and (and guest (not onboarding)) allowFormLogin}}
{{> formAccount visible=loading}}
{{else if onboarding}}
{{> userOnboarding}}
Expand Down
1 change: 1 addition & 0 deletions core/client/lemverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ Template.lemverse.helpers({
mainModules: () => Session.get('mainModules'),
gameModules: () => Session.get('gameModules'),
displayNotificationButton: () => (Meteor.settings.public.features?.notificationButton?.enabled !== false),
allowFormLogin: () => (Meteor.settings.public.permissions?.allowFormLogin !== false)
});

Template.lemverse.events({
Expand Down
7 changes: 6 additions & 1 deletion core/server/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ Accounts.onLogin(param => {
});

Accounts.validateLoginAttempt(param => {
const { user, methodName } = param;
const { user, methodName, type } = param;
log('validateLoginAttempt: start', { type: param.type, allowed: param.allowed, methodName, username: param.methodArguments?.[0].user?.username, error: param.error, connection: param.connection, userId: user?._id });

if (Meteor.settings.public.permissions?.allowFormLogin === false && !(['jwt', 'resume', 'guest'].includes(type))) {
error(`validateLoginAttempt: ${type} login is disabled`);
return false;
}

if (Meteor.settings.forbiddenIPs?.includes(lp.ip(param).ip)) {
error('validateLoginAttempt: watched ip detected!', { ip: lp.ip(param).ip, userId: user?._id });
Expand Down

0 comments on commit 5a1c005

Please sign in to comment.