mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
Make password input optional while editing
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
a3304c7b88
commit
4d5af2c95d
@ -246,16 +246,6 @@ module.exports = {
|
||||
);
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
return ctx.badRequest(
|
||||
null,
|
||||
formatError({
|
||||
id: 'missing.password',
|
||||
message: 'Missing password',
|
||||
field: ['password'],
|
||||
})
|
||||
);
|
||||
}
|
||||
const admin = await strapi.query('administrator', 'admin').findOne({ id });
|
||||
|
||||
// check the user exists
|
||||
@ -301,7 +291,7 @@ module.exports = {
|
||||
blocked: blocked === true ? true : false,
|
||||
};
|
||||
|
||||
if (password !== admin.password) {
|
||||
if (password && password !== admin.password) {
|
||||
user.password = await strapi.admin.services.auth.hashPassword(password);
|
||||
}
|
||||
|
||||
|
||||
@ -16,9 +16,9 @@ module.exports = {
|
||||
*/
|
||||
async add(values) {
|
||||
if (values.password) {
|
||||
values.password = await strapi.plugins[
|
||||
'users-permissions'
|
||||
].services.user.hashPassword(values);
|
||||
values.password = await strapi.plugins['users-permissions'].services.user.hashPassword(
|
||||
values
|
||||
);
|
||||
}
|
||||
|
||||
return strapi.query('user', 'users-permissions').create(values);
|
||||
@ -29,13 +29,10 @@ module.exports = {
|
||||
* @return {Promise}
|
||||
*/
|
||||
async edit(params, values) {
|
||||
// Note: The current method will return the full response of Mongo.
|
||||
// To get the updated object, you have to execute the `findOne()` method
|
||||
// or use the `findOneOrUpdate()` method with `{ new:true }` option.
|
||||
if (values.password) {
|
||||
values.password = await strapi.plugins[
|
||||
'users-permissions'
|
||||
].services.user.hashPassword(values);
|
||||
values.password = await strapi.plugins['users-permissions'].services.user.hashPassword(
|
||||
values
|
||||
);
|
||||
}
|
||||
|
||||
return strapi.query('user', 'users-permissions').update(params, values);
|
||||
|
||||
@ -25,9 +25,7 @@ module.exports = strapi => {
|
||||
composeEndpoint(value, { router: strapi.router });
|
||||
});
|
||||
|
||||
strapi.router.prefix(
|
||||
_.get(strapi.config, 'currentEnvironment.request.router.prefix', '')
|
||||
);
|
||||
strapi.router.prefix(_.get(strapi.config, 'currentEnvironment.request.router.prefix', ''));
|
||||
|
||||
if (!_.isEmpty(_.get(strapi.admin, 'config.routes', false))) {
|
||||
// Create router for admin.
|
||||
@ -52,27 +50,18 @@ module.exports = strapi => {
|
||||
});
|
||||
|
||||
// Exclude routes with prefix.
|
||||
const excludedRoutes = _.omitBy(
|
||||
plugin.config.routes,
|
||||
o => !_.has(o.config, 'prefix')
|
||||
);
|
||||
|
||||
_.forEach(
|
||||
_.omit(plugin.config.routes, _.keys(excludedRoutes)),
|
||||
value => {
|
||||
(plugin.config.routes || [])
|
||||
.filter(route => !_.has(route.config, 'prefix'))
|
||||
.forEach(value => {
|
||||
composeEndpoint(value, { plugin: pluginName, router });
|
||||
}
|
||||
);
|
||||
|
||||
// /!\ Could override main router's routes.
|
||||
if (!_.isEmpty(excludedRoutes)) {
|
||||
_.forEach(excludedRoutes, value => {
|
||||
composeEndpoint(value, {
|
||||
plugin: pluginName,
|
||||
router: strapi.router,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// if you set a prefix key in the route it will ignore the plugin prefix
|
||||
(plugin.config.routes || [])
|
||||
.filter(route => _.has(route.config, 'prefix'))
|
||||
.forEach(value => {
|
||||
composeEndpoint(value, { plugin: pluginName, router: strapi.router });
|
||||
});
|
||||
|
||||
// Mount plugin router
|
||||
strapi.app.use(router.routes()).use(router.allowedMethods());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user