Commit 9ded61ef authored by lic's avatar lic
Browse files

Merge remote-tracking branch 'origin/master' into listview

parents 4948699a 00ae4b6e
......@@ -7,6 +7,11 @@ ButtonCSS.addStyle('.blue-button', {
color_light_text: 'white',
});
ButtonCSS.addStyle('.flat-button', {
color_light_background: 'white',
color_light_text: 'gray',
});
/**
* Generic button component
*
......
......@@ -25,6 +25,7 @@ export default class InputGroup {
args = {};
}
args.value = vnode.attrs.value;
args.type = vnode.attrs.type;
args.onchange = vnode.attrs.onchange;
args.oninput = vnode.attrs.oninput;
args.getSuggestions = vnode.attrs.getSuggestions;
......
import m from 'mithril';
import { isLoggedIn } from '../models/auth';
import { isLoggedIn, getUsername, login } from '../models/auth';
import * as user from '../models/user';
import * as groups from '../models/groups';
import inputGroup from './form/inputGroup';
import { Button } from '../components';
// shows all relevant user information
......@@ -26,16 +27,30 @@ class showUserInfo {
// provides a form to change the users password (if not authenticated by LDAP)
class changePasswordForm {
oninit() {
this.password_old = '';
this.password1 = '';
this.password2 = '';
}
submit() {
const password = this.password1;
this.busy = true;
// renew authentication token, so we are allowed to change the password
login(getUsername(), this.password_old);
user
.update({ password })
.then(() => {
this.busy = false;
this.password_old = '';
this.password1 = '';
this.password2 = '';
})
.catch(() => {
this.busy = false;
this.password_old = '';
this.password2 = '';
});
}
......@@ -47,7 +62,8 @@ class changePasswordForm {
// * Does not contain any whitespace characters
validate() {
this.valid =
this.password1.length > 8 &&
this.password_old.length > 0 &&
this.password1.length >= 8 &&
this.password1.length <= 100 &&
!this.password1.match(/\s/g) &&
this.password1.match(/[A-Z]/g) &&
......@@ -60,36 +76,73 @@ class changePasswordForm {
view() {
if (user.get() === undefined) return m();
const buttonArgs = { events: { onclick: () => this.submit() } };
const buttonArgs = {};
let buttons;
if (!this.valid || !this.equal || this.busy) {
buttonArgs.disabled = true;
}
if (user.get().password_set) {
buttons = [
m(Button, {
...buttonArgs,
label: 'change password',
events: { onclick: () => this.submit() },
}),
m(Button, {
disabled: this.password_old.length === 0,
label: 'Revert to LDAP',
events: {
onclick: () => {
this.password1 = '';
this.password2 = '';
this.submit();
},
},
}),
];
} else {
buttons = m(Button, {
...buttonArgs,
label: 'set password',
events: { onclick: () => this.submit() },
});
}
return m('div', [
m('input', {
m('div', 'Requirements: min 8 characters, upper and lower case letters and numbers'),
m(inputGroup, {
name: 'password_old',
title: 'Old Password',
type: 'password',
value: this.password_old,
oninput: e => {
this.password_old = e.target.value;
this.validate();
},
}),
m(inputGroup, {
name: 'password1',
id: 'password1',
title: 'New Password',
type: 'password',
placeholder: 'Password',
value: this.password1,
oninput: e => {
this.password1 = e.target.value;
this.validate();
},
}),
m('input', {
m(inputGroup, {
name: 'password2',
id: 'password2',
title: 'Repeat',
type: 'password',
placeholder: 'Repeat',
value: this.password2,
oninput: e => {
this.password2 = e.target.value;
this.validate();
},
}),
m(Button, { ...buttonArgs, label: 'change password' }),
buttons,
]);
}
}
......@@ -120,11 +173,9 @@ class rfidForm {
}
return m('div', [
m('input', {
m(inputGroup, {
name: 'rfid',
id: 'rfid',
type: 'text',
placeholder: 'RFID',
title: 'RFID',
value: this.rfid,
oninput: e => {
this.rfid = e.target.value;
......@@ -166,43 +217,97 @@ class announceSubscriptionForm {
// shows group memberships and allows to withdraw and enroll for selected groups.
class groupMemberships {
static oninit() {
oninit() {
groups.load({ allow_self_enrollment: true });
groups.loadMemberships();
this.busy = [];
this.confirm = [];
this.query = '';
}
static view() {
view() {
// Searchbar for groups
const filterForm = m('div', [
m(inputGroup, {
name: 'group_search',
title: 'Search groups',
oninput: e => {
this.query = e.target.value;
if (this.query.length > 0) {
this.isValid = true;
}
},
}),
]);
return m('div', [
filterForm,
m(
'div',
groups.getMemberships().map(membership => {
const buttonArgs = {
events: {
onclick: () => {
this.busy[membership.group._id] = true;
groups
.withdraw(membership._id, membership._etag)
.then(() => {
this.busy[membership.group._id] = false;
})
.catch(() => {
this.busy[membership.group._id] = false;
});
},
},
};
const buttonArgs = {};
let buttons;
if (this.query.length > 0 && !new RegExp(this.query, 'gi').test(membership.group.name)) {
return m('');
}
if (this.busy[membership.group._id]) {
buttonArgs.disabled = true;
}
if (this.confirm[membership.group._id]) {
buttons = [
m(Button, {
...buttonArgs,
label: 'cancel',
className: 'flat-button',
events: {
onclick: () => {
this.confirm[membership.group._id] = false;
this.busy[membership.group._id] = false;
},
},
}),
m('span', ' '),
m(Button, {
...buttonArgs,
label: 'confirm',
events: {
onclick: () => {
this.busy[membership.group._id] = true;
groups
.withdraw(membership._id, membership._etag)
.then(() => {
this.busy[membership.group._id] = false;
this.confirm[membership.group._id] = false;
})
.catch(() => {
this.busy[membership.group._id] = false;
this.confirm[membership.group._id] = false;
});
},
},
}),
];
} else {
buttons = m(Button, {
...buttonArgs,
label: 'withdraw',
events: {
onclick: () => {
this.confirm[membership.group._id] = true;
},
},
});
}
return m('div', [
m('span', membership.group.name),
membership.expiry === undefined
? undefined
: m('span', `(expires on ${membership.expiry})`),
m(Button, { ...buttonArgs, label: 'withdraw' }),
buttons,
]);
})
),
......@@ -210,8 +315,13 @@ class groupMemberships {
'div',
groups.getList().map(group => {
if (groups.getMemberships().some(element => element.group._id === group._id)) {
return m.trust('');
return m('');
}
if (this.query.length > 0 && !new RegExp(this.query, 'gi').test(group.name)) {
return m('');
}
const buttonArgs = {
events: {
onclick: () => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment