From 4b4a701b66a14db5465d24cdec6114da017215c1 Mon Sep 17 00:00:00 2001 From: opi Date: Wed, 7 May 2014 17:25:57 +0200 Subject: [PATCH] [enh] #16 Allow admin to force user password in edit form. --- js/app.js | 32 ++++++++++++++++++++++++++------ views/user/user_edit.ms | 14 ++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/js/app.js b/js/app.js index efbdc83c..5d149927 100644 --- a/js/app.js +++ b/js/app.js @@ -399,7 +399,7 @@ app = Sammy('#main', function (sam) { sam.post('#/users', function (c) { if (c.params['password'] == c.params['confirmation']) { if (c.params['password'].length < 4) { - c.flash('fail', "Passwords is too short"); + c.flash('fail', "Password is too short"); store.clear('slide'); } else { @@ -430,16 +430,36 @@ app = Sammy('#main', function (sam) { sam.put('#/users/:user', function (c) { params = {} $.each(c.params.toHash(), function(key, value) { - if (value !== '' && value !== 'user') { params[key] = value; } + if (value !== '' && key !== 'user') { params[key] = value; } }); + if ($.isEmptyObject(params)) { c.flash('fail', 'You should modify something'); store.clear('slide'); - c.redirect('#/users/'+ c.params['user'] + '/edit'); + // c.redirect('#/users/'+ c.params['user'] + '/edit'); } else { - c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 - c.redirect('#/users/'+ c.params['user']); - }, 'PUT', params); + if (params['password']) { + if (params['password'] == params['confirmation']) { + if (params['password'].length < 4) { + c.flash('fail', "Password is too short"); + store.clear('slide'); + } + else { + params['change_password'] = params['password']; + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 + c.redirect('#/users/'+ c.params['user']); + }, 'PUT', params); + } + } else { + c.flash('fail', "Passwords don't match"); + store.clear('slide'); + } + } + else { + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 + c.redirect('#/users/'+ c.params['user']); + }, 'PUT', params); + } } }); diff --git a/views/user/user_edit.ms b/views/user/user_edit.ms index 71272e5c..3433aef1 100644 --- a/views/user/user_edit.ms +++ b/views/user/user_edit.ms @@ -34,6 +34,20 @@ +
+
+ +
+ +
+
+
+ +
+ +
Password must be at least 4 characters long.
+
+