Commit 10cab468 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add link for changing password.

parent 077ff9a8
...@@ -99,6 +99,16 @@ ...@@ -99,6 +99,16 @@
font-style: italic; font-style: italic;
} }
#chpwspan a {
padding: 4px 0;
font-size: 0.9em;
color: #e4157e;
}
#chpwspan.invisible {
display: none;
}
.sidenav .user-logout a { .sidenav .user-logout a {
font-size: 1em; font-size: 1em;
padding: 7px 0 0; padding: 7px 0 0;
......
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
<div class="profile-info"> <div class="profile-info">
<span id="userspan"></span> <span id="userspan"></span>
<span id="permspan"></span> <span id="permspan"></span>
<span id="chpwspan" class="invisible"><a id="change-password">Change password</a></span>
</div> </div>
<div class="user-logout"> <div class="user-logout">
<a id="disconnectbutton"> <a id="disconnectbutton">
......
...@@ -29,6 +29,9 @@ let serverConnection; ...@@ -29,6 +29,9 @@ let serverConnection;
/** @type {Object} */ /** @type {Object} */
let groupStatus = {}; let groupStatus = {};
/** @type {boolean} */
let pwAuth = false;
/** @type {string} */ /** @type {string} */
let token = null; let token = null;
...@@ -331,6 +334,24 @@ async function gotConnected() { ...@@ -331,6 +334,24 @@ async function gotConnected() {
await join(again); await join(again);
} }
/**
* @param {string} username
*/
function setChangePassword(username) {
let s = document.getElementById('chpwspan');
let a = s.children[0];
if(!(a instanceof HTMLAnchorElement))
throw new Error('Bad type for chpwspan');
if(username) {
a.href = `/change-password.html?group=${encodeURI(group)}&username=${encodeURI(username)}`;
a.target = '_blank';
s.classList.remove('invisible');
} else {
a.href = null;
s.classList.add('invisible');
}
}
/** /**
* @param {boolean} again * @param {boolean} again
*/ */
...@@ -338,6 +359,7 @@ async function join(again) { ...@@ -338,6 +359,7 @@ async function join(again) {
let username = getInputElement('username').value.trim(); let username = getInputElement('username').value.trim();
let credentials; let credentials;
if(token) { if(token) {
pwAuth = false;
credentials = { credentials = {
type: 'token', type: 'token',
token: token, token: token,
...@@ -349,15 +371,18 @@ async function join(again) { ...@@ -349,15 +371,18 @@ async function join(again) {
} else { } else {
let pw = getInputElement('password').value; let pw = getInputElement('password').value;
getInputElement('password').value = ''; getInputElement('password').value = '';
if(!groupStatus.authServer) if(!groupStatus.authServer) {
pwAuth = true;
credentials = pw; credentials = pw;
else } else {
pwAuth = false;
credentials = { credentials = {
type: 'authServer', type: 'authServer',
authServer: groupStatus.authServer, authServer: groupStatus.authServer,
location: location.href, location: location.href,
password: pw, password: pw,
}; };
}
} }
try { try {
...@@ -2459,6 +2484,7 @@ async function gotJoined(kind, group, perms, status, data, error, message) { ...@@ -2459,6 +2484,7 @@ async function gotJoined(kind, group, perms, status, data, error, message) {
this.close(); this.close();
token = null; token = null;
setButtonsVisibility(); setButtonsVisibility();
setChangePassword(null);
return; return;
case 'join': case 'join':
case 'change': case 'change':
...@@ -2469,6 +2495,9 @@ async function gotJoined(kind, group, perms, status, data, error, message) { ...@@ -2469,6 +2495,9 @@ async function gotJoined(kind, group, perms, status, data, error, message) {
setTitle((status && status.displayName) || capitalise(group)); setTitle((status && status.displayName) || capitalise(group));
displayUsername(); displayUsername();
setButtonsVisibility(); setButtonsVisibility();
setChangePassword(pwAuth && !!groupStatus.canChangePassword &&
serverConnection.username
);
if(kind === 'change') if(kind === 'change')
return; return;
break; break;
......
Markdown is supported
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