mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Edit user mail aliases & forward.
This commit is contained in:
parent
c4d488b87c
commit
8d4ef07e98
4 changed files with 101 additions and 44 deletions
111
js/app.js
111
js/app.js
|
@ -332,6 +332,14 @@ app = Sammy('#main', function (sam) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
arrayDiff: function(arr1, arr2) {
|
||||||
|
arr1 = arr1 || [];
|
||||||
|
arr2 = arr2 || [];
|
||||||
|
return arr1.filter(function (a) {
|
||||||
|
return ((arr2.indexOf(a) == -1) && (a != ""));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -705,13 +713,14 @@ app = Sammy('#main', function (sam) {
|
||||||
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0
|
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0
|
||||||
c.api('/domains', function(dataDomains) { // http://api.yunohost.org/#!/domain/domain_list_get_2
|
c.api('/domains', function(dataDomains) { // http://api.yunohost.org/#!/domain/domain_list_get_2
|
||||||
|
|
||||||
|
// User email use a fake splitted field
|
||||||
email = data.mail.split('@');
|
email = data.mail.split('@');
|
||||||
data.email = {
|
data.email = {
|
||||||
username : email[0],
|
username : email[0],
|
||||||
domain : email[1]
|
domain : email[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Domains
|
||||||
data.domains = []
|
data.domains = []
|
||||||
$.each(dataDomains.domains, function(key, value) {
|
$.each(dataDomains.domains, function(key, value) {
|
||||||
data.domains.push({
|
data.domains.push({
|
||||||
|
@ -727,50 +736,70 @@ app = Sammy('#main', function (sam) {
|
||||||
|
|
||||||
// Update user information
|
// Update user information
|
||||||
sam.put('#/users/:user', function (c) {
|
sam.put('#/users/:user', function (c) {
|
||||||
params = {}
|
// Get full user object
|
||||||
|
c.api('/users/'+ c.params['user'], function(user) {
|
||||||
|
|
||||||
// concat email/domain pseudo field
|
// concat email/domain pseudo field
|
||||||
if (c.params['mail'] !== c.params['email'] + c.params['domain']) {
|
if (c.params['mail'] !== c.params['email'] + c.params['domain']) {
|
||||||
c.params['mail'] = c.params['email'] + c.params['domain'];
|
c.params['mail'] = c.params['email'] + c.params['domain'];
|
||||||
}
|
|
||||||
else {
|
|
||||||
c.params['mail'] = '';
|
|
||||||
}
|
|
||||||
c.params['email'] = '';
|
|
||||||
c.params['domain'] = '';
|
|
||||||
|
|
||||||
$.each(c.params.toHash(), function(key, value) {
|
|
||||||
if (value !== '' && key !== 'user') { params[key] = value; }
|
|
||||||
});
|
|
||||||
|
|
||||||
if ($.isEmptyObject(params)) {
|
|
||||||
c.flash('fail', y18n.t('error_modify_something'));
|
|
||||||
store.clear('slide');
|
|
||||||
// c.redirect('#/users/'+ c.params['user'] + '/edit');
|
|
||||||
} else {
|
|
||||||
if (params['password']) {
|
|
||||||
if (params['password'] == params['confirmation']) {
|
|
||||||
if (params['password'].length < 4) {
|
|
||||||
c.flash('fail', y18n.t('password_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', y18n.t('passwords_dont_match'));
|
|
||||||
store.clear('slide');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1
|
c.params['mail'] = '';
|
||||||
c.redirect('#/users/'+ c.params['user']);
|
|
||||||
}, 'PUT', params);
|
|
||||||
}
|
}
|
||||||
}
|
// Clear temporary inputs
|
||||||
|
c.params['email'] = c.params['domain'] = '';
|
||||||
|
|
||||||
|
|
||||||
|
// force array type for mail aliases and redirections
|
||||||
|
if (typeof c.params['mailalias'] == 'string') {c.params['mailalias'] = [c.params['mailalias']]};
|
||||||
|
if (typeof c.params['mailforward'] == 'string') {c.params['mailforward'] = [c.params['mailforward']]};
|
||||||
|
|
||||||
|
// Check for added/removed aliases and redirections
|
||||||
|
c.params['add_mailalias'] = c.arrayDiff(c.params['mailalias'], user['mail-aliases']);
|
||||||
|
c.params['remove_mailalias'] = c.arrayDiff(user['mail-aliases'], c.params['mailalias']);
|
||||||
|
c.params['add_mailforward'] = c.arrayDiff(c.params['mailforward'], user['mail-forward']);
|
||||||
|
c.params['remove_mailforward'] = c.arrayDiff(user['mail-forward'], c.params['mailforward']);
|
||||||
|
|
||||||
|
// Clear temporary inputs
|
||||||
|
c.params['mailalias'] = c.params['mailforward'] = '';
|
||||||
|
|
||||||
|
// Remove empty inputs
|
||||||
|
params = {}
|
||||||
|
$.each(c.params.toHash(), function(key, value) {
|
||||||
|
if (value.length > 0 && key !== 'user') { params[key] = value; }
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($.isEmptyObject(params)) {
|
||||||
|
c.flash('fail', y18n.t('error_modify_something'));
|
||||||
|
store.clear('slide');
|
||||||
|
c.redirect('#/users/'+ c.params['user'] + '/edit');
|
||||||
|
} else {
|
||||||
|
if (params['password']) {
|
||||||
|
if (params['password'] == params['confirmation']) {
|
||||||
|
if (params['password'].length < 4) {
|
||||||
|
c.flash('fail', y18n.t('password_too_short'));
|
||||||
|
store.clear('slide');
|
||||||
|
c.redirect('#/users/'+ c.params['user'] + '/edit');
|
||||||
|
}
|
||||||
|
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', y18n.t('passwords_dont_match'));
|
||||||
|
store.clear('slide');
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 'GET');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove existing user
|
// Remove existing user
|
||||||
|
|
|
@ -235,5 +235,7 @@
|
||||||
"user_fullname" : "Fullname",
|
"user_fullname" : "Fullname",
|
||||||
"user_email" : "Email",
|
"user_email" : "Email",
|
||||||
"user_emailaliases" : "Mail aliases",
|
"user_emailaliases" : "Mail aliases",
|
||||||
"user_emailforward" : "Mail forward"
|
"user_emailforward" : "Mail forward",
|
||||||
|
"user_new_mail": "newmail@mydomain.org",
|
||||||
|
"user_new_forward": "newforward@myforeigndomain.org"
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,5 +235,7 @@
|
||||||
"user_fullname" : "Nom complet",
|
"user_fullname" : "Nom complet",
|
||||||
"user_email" : "Email",
|
"user_email" : "Email",
|
||||||
"user_emailaliases" : "Adresses supplémentaires",
|
"user_emailaliases" : "Adresses supplémentaires",
|
||||||
"user_emailforward" : "Adresses de transfert"
|
"user_emailforward" : "Adresses de transfert",
|
||||||
|
"user_new_mail": "nouvelle_adresse@domaine.org",
|
||||||
|
"user_new_forward": "nouveau_transfert@domainedistant.org"
|
||||||
}
|
}
|
|
@ -44,6 +44,29 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="mailalias" class="col-sm-3 control-label">{{t 'user_emailaliases'}}</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{{#mail-aliases}}
|
||||||
|
<input type="email" name="mailalias" class="form-control" value="{{.}}" style="margin-bottom: 5px;">
|
||||||
|
{{/mail-aliases}}
|
||||||
|
<input id="mailalias" type="email" name="mailalias" class="mailalias-input form-control" placeholder="{{t 'user_new_mail'}}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="mailforward" class="col-sm-3 control-label">{{t 'user_emailforward'}}</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
{{#mail-forward}}
|
||||||
|
<input type="email" name="mailforward" class="form-control" value="{{.}}" style="margin-bottom: 5px;">
|
||||||
|
{{/mail-forward}}
|
||||||
|
<input id="mailforward" type="email" name="mailforward" class="mailforward-input form-control" placeholder="{{t 'user_new_forward'}}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password" class="col-sm-3 control-label">{{t 'password'}}</label>
|
<label for="password" class="col-sm-3 control-label">{{t 'password'}}</label>
|
||||||
|
@ -58,6 +81,7 @@
|
||||||
<div class="help-block">{{t 'password_description'}}</div>
|
<div class="help-block">{{t 'password_description'}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue