Commit 92bca127 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Fix issues on profile page

parent 4e3c30e6
...@@ -35,6 +35,7 @@ export default { ...@@ -35,6 +35,7 @@ export default {
proceed: 'fortfahren', proceed: 'fortfahren',
}, },
membership: { membership: {
none: 'KEIN MITGLIED',
regular: 'ORDENTLICHES MITGLIED', regular: 'ORDENTLICHES MITGLIED',
extraordinary: 'AUSSERORDENTLICHES MITGLIED', extraordinary: 'AUSSERORDENTLICHES MITGLIED',
honorary: 'EHRENMITGLIED', honorary: 'EHRENMITGLIED',
...@@ -106,12 +107,18 @@ export default { ...@@ -106,12 +107,18 @@ export default {
setRfid: 'Setze deine RFID unten, um gratis Bier zu erhalten!', setRfid: 'Setze deine RFID unten, um gratis Bier zu erhalten!',
rfid: 'RFID', rfid: 'RFID',
rfidError: '6 Ziffern erforderlich. Siehe Rückseite deiner Legi.', rfidError: '6 Ziffern erforderlich. Siehe Rückseite deiner Legi.',
rfidChanged: 'RFID Nummer aktualisiert.',
rfidPatchError:
'Ein Fehler ist aufgetreten. Möglichweise ist die RFID Nummer bereits in Verwendung.',
rfidNotSet: 'nicht gesetzt',
password: { password: {
change: 'Passwort ändern', change: 'Passwort ändern',
changed: 'Password wurde geändert.', changed: 'Password wurde geändert.',
revertToLdap: 'Zu LDAP zurückkehren', revertToLdap: 'Zu LDAP zurückkehren',
revertToLdapWarning: revertToLdapWarning:
'Falls du dich nicht über das ETH LDAP authentifizieren kannst, ist das einloggen nicht mehr möglich!\nNur ETH Angehörige sollten diese Aktion ausführen.\n\n**Dies kann nicht rückgängig gemacht werden!**', 'Falls du dich nicht über das ETH LDAP authentifizieren kannst, ist das einloggen nicht mehr möglich!\nNur ETH Angehörige sollten diese Aktion ausführen.\n\n**Dies kann nicht rückgängig gemacht werden!**',
explanation:
'Du kannst dich jederzeit mit deinen ETH-Anmeldedaten anmelden. Du kannst aber auch ein zusätzliches Passwort für die Anmeldung bei AMIV-Diensten festlegen.',
set: 'Passwort setzen', set: 'Passwort setzen',
requirements: 'Passwort muss zwischen 7 und 100 Zeichen lang sein.', requirements: 'Passwort muss zwischen 7 und 100 Zeichen lang sein.',
current: 'Aktuelles Passwort', current: 'Aktuelles Passwort',
......
...@@ -35,6 +35,7 @@ export default { ...@@ -35,6 +35,7 @@ export default {
proceed: 'proceed', proceed: 'proceed',
}, },
membership: { membership: {
none: 'NO MEMBER',
regular: 'REGULAR MEMBER', regular: 'REGULAR MEMBER',
extraordinary: 'EXTRAORDINARY MEMBER', extraordinary: 'EXTRAORDINARY MEMBER',
honorary: 'HONORARY MEMBER', honorary: 'HONORARY MEMBER',
...@@ -106,12 +107,17 @@ export default { ...@@ -106,12 +107,17 @@ export default {
setRfid: 'Set your RFID below to get free beer!', setRfid: 'Set your RFID below to get free beer!',
rfid: 'RFID', rfid: 'RFID',
rfidError: '6 digits required. See back of your legi.', rfidError: '6 digits required. See back of your legi.',
rfidChanged: 'RFID number changed.',
rfidPatchError: 'An error occurred. The number might already be in use.',
rfidNotSet: 'not set',
password: { password: {
change: 'Change password', change: 'Change password',
changed: 'Password updated.', changed: 'Password updated.',
revertToLdap: 'Revert to LDAP', revertToLdap: 'Revert to LDAP',
revertToLdapWarning: revertToLdapWarning:
'If you cannot authenticate against the ETH LDAP service, you can no longer log in!\nOnly ETH affiliated people should use this function.\n\n**This cannot be undone!**', 'If you cannot authenticate against the ETH LDAP service, you can no longer log in!\nOnly ETH affiliated people should use this function.\n\n**This cannot be undone!**',
explanation:
'You can always log in with your ETH credentials, but you can also set an additional password to log in to AMIV services.',
set: 'Set password', set: 'Set password',
requirements: 'Password has to be between 7 and 100 characters long.', requirements: 'Password has to be between 7 and 100 characters long.',
current: 'Current password', current: 'Current password',
......
...@@ -83,9 +83,6 @@ export default class UserController { ...@@ -83,9 +83,6 @@ export default class UserController {
}) })
.then(result => { .then(result => {
this._user = result; this._user = result;
})
.catch(e => {
error(e.message);
}); });
} }
......
...@@ -106,6 +106,10 @@ ...@@ -106,6 +106,10 @@
grid-template-columns: 1fr auto; grid-template-columns: 1fr auto;
grid-gap: 1em; grid-gap: 1em;
padding: 0 1em 1em; padding: 0 1em 1em;
.infobox {
grid-column: ~'1 / 3';
}
} }
.change-password { .change-password {
......
...@@ -21,6 +21,7 @@ export default class ChangePasswordForm { ...@@ -21,6 +21,7 @@ export default class ChangePasswordForm {
this.password_old = ''; this.password_old = '';
this.password1 = ''; this.password1 = '';
this.password2 = ''; this.password2 = '';
this.notification = { type: 'info', label: i18n('profile.password.explanation') };
} }
static _createSession(user, password) { static _createSession(user, password) {
......
import m from 'mithril'; import m from 'mithril';
import { Card } from 'polythene-mithril'; import { Card } from 'polythene-mithril';
import { DropdownCard } from 'amiv-web-ui-components'; import { DropdownCard, Spinner } from 'amiv-web-ui-components';
import UserInfo from './userInfo'; import UserInfo from './userInfo';
import ChangePasswordForm from './changePasswordForm'; import ChangePasswordForm from './changePasswordForm';
import RfidForm from './rfidForm'; import RfidForm from './rfidForm';
...@@ -31,6 +31,10 @@ export default class Profile { ...@@ -31,6 +31,10 @@ export default class Profile {
} }
static view() { static view() {
if (!userController.user) {
return m('.loading', m(Spinner, { show: true, size: '96px' }));
}
return m('div.profile-container', [ return m('div.profile-container', [
m(Card, { m(Card, {
className: 'info-container', className: 'info-container',
...@@ -53,7 +57,7 @@ export default class Profile { ...@@ -53,7 +57,7 @@ export default class Profile {
content: m(SessionInfo, { userController }), content: m(SessionInfo, { userController }),
}), }),
m(DropdownCard, { m(DropdownCard, {
title: `RFID: ${userController.user.rfid}`, title: `RFID: ${userController.user.rfid || i18n('profile.rfidNotSet')}`,
style: { style: {
margin: '16px 0', margin: '16px 0',
borderRadius: '4px', borderRadius: '4px',
......
import m from 'mithril'; import m from 'mithril';
import { Icon } from 'polythene-mithril-icon';
import { i18n } from '../../models/language'; import { i18n } from '../../models/language';
import Button from '../../components/Button'; import Button from '../../components/Button';
import TextField from '../../components/TextField'; import TextField from '../../components/TextField';
import icons from '../../images/icons';
import { Infobox } from '../errors';
// provides a form to change the users rfid // provides a form to change the users rfid
export default class RfidForm { export default class RfidForm {
constructor(vnode) { constructor(vnode) {
this.userController = vnode.attrs.userController; this.userController = vnode.attrs.userController;
this.valid = true; this.valid = true;
this.rfid = null;
} }
submit() { submit() {
const savedRfid = this.rfid; const savedRfid = this.rfid || null;
this.busy = true; this.busy = true;
this.userController this.userController
.update({ rfid: savedRfid }) .update({ rfid: savedRfid })
.then(() => { .then(() => {
this.rfid = savedRfid; this.rfid = savedRfid || '';
this.busy = false; this.busy = false;
this.notification = { type: 'success', label: i18n('profile.rfidChanged') };
}) })
.catch(() => { .catch(() => {
this.rfid = savedRfid; this.rfid = savedRfid || '';
this.busy = false; this.busy = false;
this.notification = { type: 'fail', label: i18n('profile.rfidPatchError') };
}); });
} }
...@@ -29,12 +35,35 @@ export default class RfidForm { ...@@ -29,12 +35,35 @@ export default class RfidForm {
const buttonArgs = { events: { onclick: () => this.submit() } }; const buttonArgs = { events: { onclick: () => this.submit() } };
const { user } = this.userController; const { user } = this.userController;
if (this.rfid === undefined) this.rfid = user.rfid; if (user.rfid === undefined) {
return m('');
}
if (!this.rfid && this.rfid !== '') this.rfid = user.rfid || '';
if (!this.valid || this.busy) { if (!this.valid || this.busy) {
buttonArgs.disabled = true; buttonArgs.disabled = true;
} }
let notification;
if (this.notification) {
let iconSource;
if (this.notification.type === 'success') {
iconSource = icons.checkboxMarked;
} else if (this.notification.type === 'fail') {
iconSource = icons.error;
} else {
iconSource = icons.info;
}
notification = m(Infobox, {
className: 'info',
icon: m(Icon, { svg: { content: m.trust(iconSource) } }),
label: this.notification.label,
});
}
return m('div.rfid', [ return m('div.rfid', [
notification,
m(TextField, { m(TextField, {
label: i18n('profile.rfid'), label: i18n('profile.rfid'),
floatingLabel: true, floatingLabel: true,
...@@ -44,7 +73,7 @@ export default class RfidForm { ...@@ -44,7 +73,7 @@ export default class RfidForm {
events: { events: {
oninput: e => { oninput: e => {
this.rfid = e.target.value; this.rfid = e.target.value;
this.valid = /^\d{6}$/g.test(this.rfid); this.valid = /^\d{6}$/g.test(this.rfid) || this.rfid === '';
}, },
}, },
}), }),
......
...@@ -16,7 +16,7 @@ export default class UserInfo { ...@@ -16,7 +16,7 @@ export default class UserInfo {
let freeBeerNotice; let freeBeerNotice;
if (user.membership !== 'none') { if (user.membership !== 'none') {
if (user.rfid !== undefined && user.rfid.length === 6) { if (user.rfid && user.rfid.length === 6) {
freeBeerNotice = m('div', i18n('profile.freeBeer')); freeBeerNotice = m('div', i18n('profile.freeBeer'));
} else { } else {
freeBeerNotice = m('div', i18n('profile.setRfid')); freeBeerNotice = m('div', i18n('profile.setRfid'));
......
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