diff --git a/core/auth.html b/core/auth.html
index fd2b780f..0125db16 100644
--- a/core/auth.html
+++ b/core/auth.html
@@ -89,9 +89,12 @@
self.tab_changed('guest')}>
+
+ self.tab_changed('change')}>
+
-
+
diff --git a/core/auth.js b/core/auth.js
index 19ad1902..ab3df6ed 100644
--- a/core/auth.js
+++ b/core/auth.js
@@ -141,7 +141,7 @@ function handler(request, response) {
if (formData.submit == "Login") {
let account = gDatabase.get("user:" + formData.name);
account = account ? JSON.parse(account) : account;
- if (formData.register == "1") {
+ if (formData.register == '1') {
if (!account &&
isNameValid(formData.name) &&
formData.password == formData.confirm) {
@@ -160,12 +160,23 @@ function handler(request, response) {
}
session = makeJwt({name: formData.name});
account = {password: hashPassword(formData.password)};
- gDatabase.set("user:" + formData.name, JSON.stringify(account));
+ gDatabase.set('user:' + formData.name, JSON.stringify(account));
if (noAdministrator()) {
makeAdministrator(formData.name);
}
} else {
- loginError = "Error registering account.";
+ loginError = 'Error registering account.';
+ }
+ } else if (formData.change == '1') {
+ if (account &&
+ isNameValid(formData.name) &&
+ formData.new_password == formData.confirm &&
+ verifyPassword(formData.password, account.password)) {
+ session = makeJwt({name: formData.name});
+ account = {password: hashPassword(formData.new_password)};
+ gDatabase.set('user:' + formData.name, JSON.stringify(account));
+ } else {
+ loginError = 'Error changing password.';
}
} else {
if (account &&
@@ -176,7 +187,7 @@ function handler(request, response) {
makeAdministrator(formData.name);
}
} else {
- loginError = "Invalid username or password.";
+ loginError = 'Invalid username or password.';
}
}
} else {
diff --git a/tools/autotest.py b/tools/autotest.py
index ca80b47b..016c55d5 100755
--- a/tools/autotest.py
+++ b/tools/autotest.py
@@ -101,6 +101,25 @@ try:
driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click()
driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'error')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'change_label').click()
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('test_user')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('test_password')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'new_password').send_keys('new_password')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'confirm').send_keys('new_password')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click()
+ wait.until(expected_conditions.presence_of_element_located((By.ID, 'document')))
+ driver.find_element(By.TAG_NAME, 'tf-navigation').shadow_root.find_element(By.LINK_TEXT, 'logout test_user').click()
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'login_label').click()
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('test_user')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('test_password')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click()
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'error')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'login_label').click()
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('test_user')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('new_password')
+ driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click()
+ wait.until(expected_conditions.presence_of_element_located((By.ID, 'document')))
+
print('SUCCESS.')
finally:
driver.close()