mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 16:57:39 -05:00
fixed regex
This commit is contained in:
@@ -14,12 +14,16 @@ const User = require("../../models/user");
|
||||
module.exports = new LocalStrategy({
|
||||
usernameField: "email"
|
||||
}, (email, password, done) => {
|
||||
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex/6969486#6969486
|
||||
const escapeRegExp = (string) => {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
||||
}
|
||||
User.findOne({
|
||||
$or: [{
|
||||
email: { '$regex': email, $options: 'i' }
|
||||
email: { '$regex': escapeRegExp(email), $options: 'i' }
|
||||
}, {
|
||||
local: {
|
||||
email: { '$regex': email, $options: 'i' }
|
||||
email: { '$regex': escapeRegExp(email), $options: 'i' }
|
||||
}
|
||||
}]
|
||||
}, (err, user) => {
|
||||
|
||||
Reference in New Issue
Block a user