refactor: switch to using slugify module

This commit is contained in:
Barış Soner Uşaklı
2020-10-11 21:49:37 -04:00
parent bddfcb5867
commit dc29f4dca2
28 changed files with 88 additions and 60 deletions

View File

@@ -13,6 +13,7 @@ const meta = require('../meta');
const user = require('../user');
const plugins = require('../plugins');
const utils = require('../utils');
const slugify = require('../slugify');
const translator = require('../translator');
const helpers = require('./helpers');
const privileges = require('../privileges');
@@ -81,7 +82,7 @@ authenticationController.register = async function (req, res) {
throw new Error('[[error:invalid-email]]');
}
if (!userData.username || userData.username.length < meta.config.minimumUsernameLength || utils.slugify(userData.username).length < meta.config.minimumUsernameLength) {
if (!userData.username || userData.username.length < meta.config.minimumUsernameLength || slugify(userData.username).length < meta.config.minimumUsernameLength) {
throw new Error('[[error:username-too-short]]');
}
@@ -356,7 +357,7 @@ authenticationController.localLogin = async function (req, username, password, n
return next(new Error('[[error:password-too-long]]'));
}
const userslug = utils.slugify(username);
const userslug = slugify(username);
const uid = await user.getUidByUserslug(userslug);
try {
const [userData, isAdminOrGlobalMod, banned, hasLoginPrivilege] = await Promise.all([

View File

@@ -6,7 +6,7 @@ const user = require('../../user');
const groups = require('../../groups');
const events = require('../../events');
const meta = require('../../meta');
const utils = require('../../utils');
const slugify = require('../../slugify');
const notifications = require('../../notifications');
const helpers = require('../helpers');
@@ -114,7 +114,7 @@ Groups.leave = async (req, res) => {
type: 'group-leave',
bodyShort: '[[groups:membership.leave.notification-title, ' + username + ', ' + group.name + ']]',
nid: 'group:' + validator.escape(group.name) + ':uid:' + req.params.uid + ':group-leave',
path: '/groups/' + utils.slugify(group.name),
path: '/groups/' + slugify(group.name),
});
const uids = await groups.getOwners(group.name);
await notifications.push(notification, uids);