Skip to content

Commit

Permalink
fix: closes NodeBB#13024, on register dont auto login with user doesn…
Browse files Browse the repository at this point in the history
…'t have local:login privilege

on login page show login form if at least one user group has local:login privilege, for example local:login might be removed from registered-users but verified-users can have login privilege so login form should be still visible
  • Loading branch information
barisusakli committed Jan 6, 2025
1 parent d155da3 commit 238a3ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ async function registerAndLoginUser(req, res, userData) {

const uid = await user.create(userData);
if (res.locals.processLogin) {
await authenticationController.doLogin(req, uid);
const hasLoginPrivilege = await privileges.global.can('local:login', uid);
if (hasLoginPrivilege) {
await authenticationController.doLogin(req, uid);
}
}

// Distinguish registrations through invites from direct ones
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const meta = require('../meta');
const user = require('../user');
const plugins = require('../plugins');
const privileges = require('../privileges');
const privilegesHelpers = require('../privileges/helpers');
const helpers = require('./helpers');

const Controllers = module.exports;
Expand Down Expand Up @@ -124,7 +125,8 @@ Controllers.login = async function (req, res) {
data.title = '[[pages:login]]';
data.allowPasswordReset = !meta.config['password:disableEdit'];

const hasLoginPrivilege = await privileges.global.canGroup('local:login', 'registered-users');
const loginPrivileges = await privilegesHelpers.getGroupPrivileges(0, ['groups:local:login']);
const hasLoginPrivilege = !!loginPrivileges.find(privilege => privilege.privileges['groups:local:login']);
data.allowLocalLogin = hasLoginPrivilege || parseInt(req.query.local, 10) === 1;

if (!data.allowLocalLogin && !data.allowRegistration && data.alternate_logins && data.authentication.length === 1) {
Expand Down

0 comments on commit 238a3ed

Please sign in to comment.