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 {
proceed: 'fortfahren',
},
membership: {
none: 'KEIN MITGLIED',
regular: 'ORDENTLICHES MITGLIED',
extraordinary: 'AUSSERORDENTLICHES MITGLIED',
honorary: 'EHRENMITGLIED',
......@@ -106,12 +107,18 @@ export default {
setRfid: 'Setze deine RFID unten, um gratis Bier zu erhalten!',
rfid: 'RFID',
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: {
change: 'Passwort ändern',
changed: 'Password wurde geändert.',
revertToLdap: 'Zu LDAP zurückkehren',
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!**',
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',
requirements: 'Passwort muss zwischen 7 und 100 Zeichen lang sein.',
current: 'Aktuelles Passwort',
......
......@@ -35,6 +35,7 @@ export default {
proceed: 'proceed',
},
membership: {
none: 'NO MEMBER',
regular: 'REGULAR MEMBER',
extraordinary: 'EXTRAORDINARY MEMBER',
honorary: 'HONORARY MEMBER',
......@@ -106,12 +107,17 @@ export default {
setRfid: 'Set your RFID below to get free beer!',
rfid: 'RFID',
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: {
change: 'Change password',
changed: 'Password updated.',
revertToLdap: 'Revert to LDAP',
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!**',
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',
requirements: 'Password has to be between 7 and 100 characters long.',
current: 'Current password',
......
......@@ -83,9 +83,6 @@ export default class UserController {
})
.then(result => {
this._user = result;
})
.catch(e => {
error(e.message);
});
}
......
......@@ -106,6 +106,10 @@
grid-template-columns: 1fr auto;
grid-gap: 1em;
padding: 0 1em 1em;
.infobox {
grid-column: ~'1 / 3';
}
}
.change-password {
......
......@@ -21,6 +21,7 @@ export default class ChangePasswordForm {
this.password_old = '';
this.password1 = '';
this.password2 = '';
this.notification = { type: 'info', label: i18n('profile.password.explanation') };
}
static _createSession(user, password) {
......
import m from '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 ChangePasswordForm from './changePasswordForm';
import RfidForm from './rfidForm';
......@@ -31,6 +31,10 @@ export default class Profile {
}
static view() {
if (!userController.user) {
return m('.loading', m(Spinner, { show: true, size: '96px' }));
}
return m('div.profile-container', [
m(Card, {
className: 'info-container',
......@@ -53,7 +57,7 @@ export default class Profile {
content: m(SessionInfo, { userController }),
}),
m(DropdownCard, {
title: `RFID: ${userController.user.rfid}`,
title: `RFID: ${userController.user.rfid || i18n('profile.rfidNotSet')}`,
style: {
margin: '16px 0',
borderRadius: '4px',
......
import m from 'mithril';
import { Icon } from 'polythene-mithril-icon';
import { i18n } from '../../models/language';
import Button from '../../components/Button';
import TextField from '../../components/TextField';
import icons from '../../images/icons';
import { Infobox } from '../errors';
// provides a form to change the users rfid
export default class RfidForm {
constructor(vnode) {
this.userController = vnode.attrs.userController;
this.valid = true;
this.rfid = null;
}
submit() {
const savedRfid = this.rfid;
const savedRfid = this.rfid || null;
this.busy = true;
this.userController
.update({ rfid: savedRfid })
.then(() => {
this.rfid = savedRfid;
this.rfid = savedRfid || '';
this.busy = false;
this.notification = { type: 'success', label: i18n('profile.rfidChanged') };
})
.catch(() => {
this.rfid = savedRfid;
this.rfid = savedRfid || '';
this.busy = false;
this.notification = { type: 'fail', label: i18n('profile.rfidPatchError') };
});
}
......@@ -29,12 +35,35 @@ export default class RfidForm {
const buttonArgs = { events: { onclick: () => this.submit() } };
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) {
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', [
notification,
m(TextField, {
label: i18n('profile.rfid'),
floatingLabel: true,
......@@ -44,7 +73,7 @@ export default class RfidForm {
events: {
oninput: e => {
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 {
let freeBeerNotice;
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'));
} else {
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