Update branch

Merge branch 'fix/overlay-blocker-stm' of github.com:strapi/strapi into fix/overlay-blocker-stm
This commit is contained in:
cyril lopez 2018-01-25 11:00:29 +01:00
commit 1e81d96e91
3 changed files with 25 additions and 8 deletions

View File

@ -43,11 +43,14 @@ module.exports = function (strapi) {
const { host, port, username, password, database } = _.defaults(connection.settings, strapi.config.hook.settings.mongoose); const { host, port, username, password, database } = _.defaults(connection.settings, strapi.config.hook.settings.mongoose);
// Connect to mongo database // Connect to mongo database
if (_.isEmpty(username) || _.isEmpty(password)) { const connectOptions = {}
instance.connect(`mongodb://${host}:${port}/${database}`); if (!_.isEmpty(username)) {
} else { connectOptions.user = username
instance.connect(`mongodb://${username}:${password}@${host}:${port}/${database}`); if (!_.isEmpty(password)) {
connectOptions.pass = password
}
} }
instance.connect(`mongodb://${host}:${port}/${database}`, connectOptions);
// Handle error // Handle error
instance.connection.on('error', error => { instance.connection.on('error', error => {

View File

@ -9,8 +9,16 @@ const logger = require('strapi-utils').logger;
module.exports = (scope, success, error) => { module.exports = (scope, success, error) => {
const Mongoose = require(path.resolve(`${scope.rootPath}/node_modules/mongoose`)); const Mongoose = require(path.resolve(`${scope.rootPath}/node_modules/mongoose`));
Mongoose.connect(`mongodb://${ (scope.database.settings.username && scope.database.settings.password) ? `${scope.database.settings.username}:${scope.database.settings.password}@` : '' }${scope.database.settings.host}:${scope.database.settings.port}/${scope.database.settings.database}`, function (err) { const { username, password } = scope.database.settings
const connectOptions = {}
if (username) {
connectOptions.user = username
if (password) {
connectOptions.pass = password
}
}
Mongoose.connect(`mongodb://${scope.database.settings.host}:${scope.database.settings.port}/${scope.database.settings.database}`, connectOptions, function (err) {
if (err) { if (err) {
logger.warn('Database connection has failed! Make sure your database is running.'); logger.warn('Database connection has failed! Make sure your database is running.');
return error(); return error();

View File

@ -8,6 +8,7 @@
const _ = require('lodash'); const _ = require('lodash');
const crypto = require('crypto'); const crypto = require('crypto');
const emailRegExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
module.exports = { module.exports = {
callback: async (ctx) => { callback: async (ctx) => {
@ -28,11 +29,11 @@ module.exports = {
const query = {}; const query = {};
// Check if the provided identifier is an email or not. // Check if the provided identifier is an email or not.
const isEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(params.identifier); const isEmail = emailRegExp.test(params.identifier);
// Set the identifier to the appropriate query field. // Set the identifier to the appropriate query field.
if (isEmail) { if (isEmail) {
query.email = params.identifier; query.email = params.identifier.toLowerCase();
} else { } else {
query.username = params.identifier; query.username = params.identifier;
} }
@ -170,6 +171,11 @@ module.exports = {
params.role = '1'; params.role = '1';
} }
// Check if the provided identifier is an email or not.
const isEmail = emailRegExp.test(params.identifier);
if (isEmail) {
params.identifier = params.identifier.toLowerCase();
}
params.password = await strapi.plugins['users-permissions'].services.user.hashPassword(params); params.password = await strapi.plugins['users-permissions'].services.user.hashPassword(params);
try { try {