mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	fix: #7567, allow invite and approval at the same time
This commit is contained in:
		| @@ -27,6 +27,7 @@ | ||||
|     "maximumTagLength": 15, | ||||
|     "allowTopicsThumbnail": 0, | ||||
|     "registrationType": "normal", | ||||
|     "registrationApprovalType": "normal", | ||||
|     "allowAccountDelete": 1, | ||||
|     "allowFileUploads": 0, | ||||
|     "allowedFileExtensions": "png,jpg,bmp", | ||||
|   | ||||
| @@ -34,13 +34,15 @@ | ||||
| 	"online-cutoff-help": "If user performs no actions for this duration, they are considered inactive and they do not receive realtime updates.", | ||||
| 	"registration": "User Registration", | ||||
| 	"registration-type": "Registration Type", | ||||
| 	"registration-approval-type": "Registration Approval Type", | ||||
| 	"registration-type.normal": "Normal", | ||||
| 	"registration-type.admin-approval": "Admin Approval", | ||||
| 	"registration-type.admin-approval-ip": "Admin Approval for IPs", | ||||
| 	"registration-type.invite-only": "Invite Only", | ||||
| 	"registration-type.admin-invite-only": "Admin Invite Only", | ||||
| 	"registration-type.disabled": "No registration", | ||||
| 	"registration-type.help": "Normal - Users can register from the /register page.<br/>\nAdmin Approval - User registrations are placed in an <a href=\"%1/admin/manage/registration\">approval queue</a> for administrators.<br/>\nAdmin Approval for IPs - Normal for new users, Admin Approval for IP addresses that already have an account.<br/>\nInvite Only - Users can invite others from the <a href=\"%1/users\" target=\"_blank\">users</a> page.<br/>\nAdmin Invite Only - Only administrators can invite others from <a href=\"%1/users\" target=\"_blank\">users</a> and <a href=\"%1/admin/manage/users\">admin/manage/users</a> pages.<br/>\nNo registration - No user registration.<br/>", | ||||
| 	"registration-type.help": "Normal - Users can register from the /register page.<br/>\nInvite Only - Users can invite others from the <a href=\"%1/users\" target=\"_blank\">users</a> page.<br/>\nAdmin Invite Only - Only administrators can invite others from <a href=\"%1/users\" target=\"_blank\">users</a> and <a href=\"%1/admin/manage/users\">admin/manage/users</a> pages.<br/>\nNo registration - No user registration.<br/>", | ||||
| 	"registration-approval-type.help": "Normal - Users are registered immediately.<br/>\nAdmin Approval - User registrations are placed in an <a href=\"%1/admin/manage/registration\">approval queue</a> for administrators.<br/>\nAdmin Approval for IPs - Normal for new users, Admin Approval for IP addresses that already have an account.<br/>", | ||||
| 	"registration.max-invites": "Maximum Invitations per User", | ||||
| 	"max-invites": "Maximum Invitations per User", | ||||
| 	"max-invites-help": "0 for no restriction. Admins get infinite invitations<br>Only applicable for \"Invite Only\"", | ||||
|   | ||||
| @@ -100,7 +100,6 @@ Controllers.login = function (req, res, next) { | ||||
| 	var data = {}; | ||||
| 	var loginStrategies = require('../routes/authentication').getLoginStrategies(); | ||||
| 	var registrationType = meta.config.registrationType || 'normal'; | ||||
|  | ||||
| 	var allowLoginWith = (meta.config.allowLoginWith || 'username-email'); | ||||
| 	var returnTo = (req.headers['x-return-to'] || '').replace(nconf.get('base_url') + nconf.get('relative_path'), ''); | ||||
|  | ||||
| @@ -117,7 +116,7 @@ Controllers.login = function (req, res, next) { | ||||
|  | ||||
| 	data.alternate_logins = loginStrategies.length > 0; | ||||
| 	data.authentication = loginStrategies; | ||||
| 	data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip'; | ||||
| 	data.allowRegistration = registrationType === 'normal'; | ||||
| 	data.allowLoginWith = '[[login:' + allowLoginWith + ']]'; | ||||
| 	data.breadcrumbs = helpers.buildBreadcrumbs([{ | ||||
| 		text: '[[global:login]]', | ||||
| @@ -159,7 +158,7 @@ Controllers.register = function (req, res, next) { | ||||
| 	var registrationType = meta.config.registrationType || 'normal'; | ||||
|  | ||||
| 	if (registrationType === 'disabled') { | ||||
| 		return next(); | ||||
| 		return setImmediate(next); | ||||
| 	} | ||||
|  | ||||
| 	var errorText; | ||||
|   | ||||
| @@ -63,7 +63,7 @@ module.exports = function (middleware) { | ||||
| 			'brand:logo:url': meta.config['brand:logo:url'] || '', | ||||
| 			'brand:logo:alt': meta.config['brand:logo:alt'] || '', | ||||
| 			'brand:logo:display': meta.config['brand:logo'] ? '' : 'hide', | ||||
| 			allowRegistration: registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip', | ||||
| 			allowRegistration: registrationType === 'normal', | ||||
| 			searchEnabled: plugins.hasListeners('filter:search.query'), | ||||
| 			config: res.locals.config, | ||||
| 			relative_path: nconf.get('relative_path'), | ||||
|   | ||||
							
								
								
									
										20
									
								
								src/upgrades/1.12.3/update_registration_type.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/upgrades/1.12.3/update_registration_type.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var db = require('../../database'); | ||||
|  | ||||
| module.exports = { | ||||
| 	name: 'Update registration type', | ||||
| 	timestamp: Date.UTC(2019, 5, 4), | ||||
| 	method: function (callback) { | ||||
| 		const meta = require('../../meta'); | ||||
| 		const registrationType = meta.config.registrationType || 'normal'; | ||||
| 		if (registrationType === 'admin-approval' || registrationType === 'admin-approval-ip') { | ||||
| 			db.setObject('config', { | ||||
| 				registrationType: 'normal', | ||||
| 				registrationApprovalType: registrationType, | ||||
| 			}, callback); | ||||
| 		} else { | ||||
| 			setImmediate(callback); | ||||
| 		} | ||||
| 	}, | ||||
| }; | ||||
| @@ -163,15 +163,15 @@ module.exports = function (User) { | ||||
| 	} | ||||
|  | ||||
| 	User.shouldQueueUser = function (ip, callback) { | ||||
| 		var registrationType = meta.config.registrationType || 'normal'; | ||||
| 		if (registrationType === 'normal' || registrationType === 'invite-only' || registrationType === 'admin-invite-only') { | ||||
| 			setImmediate(callback, null, false); | ||||
| 		} else if (registrationType === 'admin-approval') { | ||||
| 		const registrationApprovalType = meta.config.registrationApprovalType; | ||||
| 		if (registrationApprovalType === 'admin-approval') { | ||||
| 			setImmediate(callback, null, true); | ||||
| 		} else if (registrationType === 'admin-approval-ip') { | ||||
| 		} else if (registrationApprovalType === 'admin-approval-ip') { | ||||
| 			db.sortedSetCard('ip:' + ip + ':uid', function (err, count) { | ||||
| 				callback(err, !!count); | ||||
| 			}); | ||||
| 		} else { | ||||
| 			setImmediate(callback, null, false); | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
|   | ||||
| @@ -167,8 +167,6 @@ | ||||
| 				<label>[[admin/settings/user:registration-type]]</label> | ||||
| 				<select class="form-control" data-field="registrationType"> | ||||
| 					<option value="normal">[[admin/settings/user:registration-type.normal]]</option> | ||||
| 					<option value="admin-approval">[[admin/settings/user:registration-type.admin-approval]]</option> | ||||
| 					<option value="admin-approval-ip">[[admin/settings/user:registration-type.admin-approval-ip]]</option> | ||||
| 					<option value="invite-only">[[admin/settings/user:registration-type.invite-only]]</option> | ||||
| 					<option value="admin-invite-only">[[admin/settings/user:registration-type.admin-invite-only]]</option> | ||||
| 					<option value="disabled">[[admin/settings/user:registration-type.disabled]]</option> | ||||
| @@ -177,6 +175,17 @@ | ||||
| 					[[admin/settings/user:registration-type.help, {config.relative_path}]] | ||||
| 				</p> | ||||
| 			</div> | ||||
| 			<div class="form-group"> | ||||
| 				<label>[[admin/settings/user:registration-approval-type]]</label> | ||||
| 				<select class="form-control" data-field="registrationApprovalType"> | ||||
| 					<option value="normal">[[admin/settings/user:registration-type.normal]]</option> | ||||
| 					<option value="admin-approval">[[admin/settings/user:registration-type.admin-approval]]</option> | ||||
| 					<option value="admin-approval-ip">[[admin/settings/user:registration-type.admin-approval-ip]]</option> | ||||
| 				</select> | ||||
| 				<p class="help-block"> | ||||
| 					[[admin/settings/user:registration-approval-type.help, {config.relative_path}]] | ||||
| 				</p> | ||||
| 			</div> | ||||
| 			<div class="form-group"> | ||||
| 				<label>[[admin/settings/user:max-invites]]</label> | ||||
| 				<input type="number" class="form-control" data-field="maximumInvites" placeholder="0"> | ||||
|   | ||||
| @@ -396,9 +396,9 @@ describe('authentication', function () { | ||||
| 	}); | ||||
|  | ||||
| 	it('should queue user if ip is used before', function (done) { | ||||
| 		meta.config.registrationType = 'admin-approval-ip'; | ||||
| 		meta.config.registrationApprovalType = 'admin-approval-ip'; | ||||
| 		registerUser('another@user.com', 'anotheruser', 'anotherpwd', function (err, response, body) { | ||||
| 			meta.config.registrationType = 'normal'; | ||||
| 			meta.config.registrationApprovalType = 'normal'; | ||||
| 			assert.ifError(err); | ||||
| 			assert.equal(response.statusCode, 200); | ||||
| 			assert.equal(body.message, '[[register:registration-added-to-queue]]'); | ||||
|   | ||||
							
								
								
									
										10
									
								
								test/user.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								test/user.js
									
									
									
									
									
								
							| @@ -1588,13 +1588,11 @@ describe('User', function () { | ||||
| 	}); | ||||
|  | ||||
| 	describe('approval queue', function () { | ||||
| 		var socketAdmin = require('../src/socket.io/admin'); | ||||
|  | ||||
| 		var oldRegistrationType; | ||||
| 		var oldRegistrationApprovalType; | ||||
| 		var adminUid; | ||||
| 		before(function (done) { | ||||
| 			oldRegistrationType = meta.config.registrationType; | ||||
| 			meta.config.registrationType = 'admin-approval'; | ||||
| 			oldRegistrationApprovalType = meta.config.registrationApprovalType; | ||||
| 			meta.config.registrationApprovalType = 'admin-approval'; | ||||
| 			User.create({ username: 'admin', password: '123456' }, function (err, uid) { | ||||
| 				assert.ifError(err); | ||||
| 				adminUid = uid; | ||||
| @@ -1603,7 +1601,7 @@ describe('User', function () { | ||||
| 		}); | ||||
|  | ||||
| 		after(function (done) { | ||||
| 			meta.config.registrationType = oldRegistrationType; | ||||
| 			meta.config.registrationApprovalType = oldRegistrationApprovalType; | ||||
| 			done(); | ||||
| 		}); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user