chore: reconfig scripts to handle openid auth
This commit is contained in:
parent
a298f5ff4c
commit
8332d8ed14
@ -186,6 +186,9 @@ const otp_in = async () => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const on_openid = (item) => {
|
||||||
|
location.href=`/openid/${item}`;
|
||||||
|
};
|
||||||
const restart = () => {
|
const restart = () => {
|
||||||
const main_form = document.getElementById('main-form');
|
const main_form = document.getElementById('main-form');
|
||||||
const main_btns = document.getElementById('main-btns');
|
const main_btns = document.getElementById('main-btns');
|
||||||
|
@ -35,41 +35,41 @@ const get_otp_info = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const check_value = async (name,value,elem) => {
|
const check_value = async (name,value,elem) => {
|
||||||
if (login_messages.innerHTML!='') { login_messages.innerHTML=''; }
|
if (login_messages.innerHTML !== '') { login_messages.innerHTML=''; }
|
||||||
const elem_error = document.getElementById(`${name}-error`);
|
const elem_error = document.getElementById(`${name}-error`);
|
||||||
let res = await check_item(name,value);
|
let res = await check_item(name,value);
|
||||||
if (elem_error) { elem_error.innerHTML = res}
|
if (elem_error) { elem_error.innerHTML = res}
|
||||||
if (res != '') {
|
if (res !== '') {
|
||||||
elem.focus();
|
elem.focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const set_name = async (elem) => {
|
const set_name = async (elem) => {
|
||||||
if (elem.value == '' ) {
|
if (elem.value === ' ' ) {
|
||||||
login_messages.innerHTML='Please include a valid name';
|
login_messages.innerHTML='Please include a valid name';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return await check_value('name',elem.value,elem);
|
return await check_value('name',elem.value,elem);
|
||||||
};
|
};
|
||||||
const set_email = async (elem) => {
|
const set_email = async (elem) => {
|
||||||
if (elem.value == '' || !elem.value.includes('@')) {
|
if (elem.value === '' || !elem.value.includes('@')) {
|
||||||
login_messages.innerHTML='Please include a valid email';
|
login_messages.innerHTML='Please include a valid email';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return await check_value('email',elem.value,elem);
|
return await check_value('email',elem.value,elem);
|
||||||
};
|
};
|
||||||
const set_totp = (elem) => {
|
const set_totp = (elem) => {
|
||||||
if (login_messages.innerHTML!='') { login_messages.innerHTML=''; }
|
if (login_messages.innerHTML !== '') { login_messages.innerHTML=''; }
|
||||||
};
|
};
|
||||||
const make_role_chips = (elem) => {
|
const make_chips = (elem, keys) => {
|
||||||
const arr_items = elem.value == '' ? [] : elem.value.split(',');
|
const arr_items = elem.value === '' ? [] : elem.value.split(',');
|
||||||
const roles_chips = document.getElementById('roles-chips');
|
const elem_chips = document.getElementById(`${keys}-chips`);
|
||||||
if (roles_chips) {
|
if (elem_chips) {
|
||||||
roles_chips.innerHTML='';
|
elem_chips.innerHTML='';
|
||||||
if (arr_items.length == 0) { return; }
|
if (arr_items.length === 0) { return; }
|
||||||
arr_items.forEach(name => {
|
arr_items.forEach(name => {
|
||||||
if (name.replaceAll(' ','') !== '') {
|
if (name.replaceAll(' ','') !== '') {
|
||||||
const chip = document.createElement("span");
|
const chip = document.createElement("span");
|
||||||
chip.id = `badge-${name}`;
|
chip.id = `badge-${name}`;
|
||||||
const arr_classes = "inline-flex items-center px-2 py-1 mr-2 text-sm font-medium text-blue-800 bg-blue-100 rounded dark:bg-blue-900 dark:text-blue-300".split(" ");
|
const arr_classes = "inline-flex items-center px-2 py-1 mr-2 text-sm font-medium text-blue-800 bg-blue-100 rounded dark:bg-blue-900 dark:text-blue-300".split(" ");
|
||||||
@ -79,14 +79,14 @@ const make_role_chips = (elem) => {
|
|||||||
} else {
|
} else {
|
||||||
chip.innerHTML = `${name} <button type="button" class="inline-flex items-center p-0.5 ml-2 text-sm text-blue-400 bg-transparent rounded-sm hover:bg-blue-200 hover:text-blue-900 dark:hover:bg-blue-800 dark:hover:text-blue-300" data-dismiss-target="#badge-${name}" aria-label="Remove">
|
chip.innerHTML = `${name} <button type="button" class="inline-flex items-center p-0.5 ml-2 text-sm text-blue-400 bg-transparent rounded-sm hover:bg-blue-200 hover:text-blue-900 dark:hover:bg-blue-800 dark:hover:text-blue-300" data-dismiss-target="#badge-${name}" aria-label="Remove">
|
||||||
<svg aria-hidden="true" class="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
|
<svg aria-hidden="true" class="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>
|
||||||
<span class="sr-only">Remove role</span></button> `;
|
<span class="sr-only">Remove ${keys}</span></button> `;
|
||||||
}
|
}
|
||||||
roles_chips.append(chip);
|
elem_chips.append(chip);
|
||||||
if (!elem.disabled) {
|
if (!elem.disabled) {
|
||||||
document.getElementById(`badge-${name}`).addEventListener('click', (ev) => {
|
document.getElementById(`badge-${name}`).addEventListener('click', (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
chip.remove();
|
chip.remove();
|
||||||
elem.value = arr_items.filter(it => it != name).join(',');
|
elem.value = arr_items.filter(it => it !== name).join(',');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,11 +94,15 @@ const make_role_chips = (elem) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const set_role = (elem) => {
|
const set_role = (elem) => {
|
||||||
if (login_messages.innerHTML!='') { login_messages.innerHTML=''; }
|
if (login_messages.innerHTML !== '') { login_messages.innerHTML=''; }
|
||||||
make_role_chips(elem);
|
make_chips(elem, 'role');
|
||||||
|
};
|
||||||
|
const set_openids = (elem) => {
|
||||||
|
if (login_messages.innerHTML !== '') { login_messages.innerHTML = ''; }
|
||||||
|
make_chips(elem, 'openids');
|
||||||
};
|
};
|
||||||
const set_items = (elem) => {
|
const set_items = (elem) => {
|
||||||
if (login_messages.innerHTML!='') { login_messages.innerHTML=''; }
|
if (login_messages.innerHTML !== '') { login_messages.innerHTML=''; }
|
||||||
};
|
};
|
||||||
const clean_password_messages = () => {
|
const clean_password_messages = () => {
|
||||||
if (password_secure_bar) { password_secure_bar.style.width = '0%'; }
|
if (password_secure_bar) { password_secure_bar.style.width = '0%'; }
|
||||||
@ -107,16 +111,16 @@ const clean_password_messages = () => {
|
|||||||
if (password_warning) { password_warning.innerHTML=''; }
|
if (password_warning) { password_warning.innerHTML=''; }
|
||||||
if (password_error) { password_error.innerHTML=''; }
|
if (password_error) { password_error.innerHTML=''; }
|
||||||
};
|
};
|
||||||
const set_password = async (elem) => {
|
const set_password = async (elem) => {
|
||||||
if (login_messages.innerHTML!='') { login_messages.innerHTML=''; }
|
if (login_messages.innerHTML !== '') { login_messages.innerHTML=''; }
|
||||||
clean_password_messages();
|
clean_password_messages();
|
||||||
const feedback = await check_item('password',elem.value);
|
const feedback = await check_item('password',elem.value);
|
||||||
if (password_secure_bar) { password_secure_bar.style.width = `${parseInt(feedback.score)*10}%`; }
|
if (password_secure_bar) { password_secure_bar.style.width = `${parseInt(feedback.score)*10}%`; }
|
||||||
if (password_secure_val) { password_secure_val.innerHTML=feedback.score; }
|
if (password_secure_val) { password_secure_val.innerHTML=feedback.score; }
|
||||||
if (password_suggestions) { password_suggestions.innerHTML=feedback.suggestions; }
|
if (password_suggestions) { password_suggestions.innerHTML=feedback.suggestions; }
|
||||||
if (password_warning) { password_warning.innerHTML=feedback.warning; }
|
if (password_warning) { password_warning.innerHTML=feedback.warning; }
|
||||||
if (PASSWORD_SCORE && feedback.score < PASSWORD_SCORE) {
|
if (PASSWORD_SCORE && feedback.score < PASSWORD_SCORE) {
|
||||||
elem.focus();
|
elem.focus();
|
||||||
if (password_error) {
|
if (password_error) {
|
||||||
password_error.innerHTML = `Password under score value: ${PASSWORD_SCORE}`;
|
password_error.innerHTML = `Password under score value: ${PASSWORD_SCORE}`;
|
||||||
}
|
}
|
||||||
@ -136,7 +140,7 @@ const change_use_totp = (elem) => {
|
|||||||
} else {
|
} else {
|
||||||
const otp_auth = document.getElementById('user-totp-inpt');
|
const otp_auth = document.getElementById('user-totp-inpt');
|
||||||
const otp_code = document.getElementById('user-totp-code')
|
const otp_code = document.getElementById('user-totp-code')
|
||||||
if (otp_auth && otp_code && otp_code.value != 0 ) {
|
if (otp_auth && otp_code && otp_code.value !== 0 ) {
|
||||||
otp_auth.parentElement.classList.remove('hidden');
|
otp_auth.parentElement.classList.remove('hidden');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +159,7 @@ const reset_totp = (hide_parent) => {
|
|||||||
const totp_recovery_message = document.getElementById('totp-recovery-message');
|
const totp_recovery_message = document.getElementById('totp-recovery-message');
|
||||||
if (totp_recovery_message) { totp_recovery_message.classList.remove('hidden')}
|
if (totp_recovery_message) { totp_recovery_message.classList.remove('hidden')}
|
||||||
if (copy_code) { copy_code.classList.add('hidden') }
|
if (copy_code) { copy_code.classList.add('hidden') }
|
||||||
if (otp_auth) {
|
if (otp_auth) {
|
||||||
otp_auth.value = '';
|
otp_auth.value = '';
|
||||||
if (hide_parent) { otp_auth.parentElement.classList.add('hidden') }
|
if (hide_parent) { otp_auth.parentElement.classList.add('hidden') }
|
||||||
}
|
}
|
||||||
@ -170,8 +174,8 @@ const set_theme = (elem) => {
|
|||||||
const sel_theme = elem.value;
|
const sel_theme = elem.value;
|
||||||
const element = document.getElementsByTagName('html')[0];
|
const element = document.getElementsByTagName('html')[0];
|
||||||
const curr_theme = element.classList.contains('dark') ? 'dark': 'light';
|
const curr_theme = element.classList.contains('dark') ? 'dark': 'light';
|
||||||
if (curr_theme != sel_theme) {
|
if (curr_theme !== sel_theme) {
|
||||||
if (sel_theme != 'dark' && element.classList.contains('dark')) {
|
if (sel_theme !== 'dark' && element.classList.contains('dark')) {
|
||||||
element.classList.remove('dark');
|
element.classList.remove('dark');
|
||||||
} else {
|
} else {
|
||||||
element.classList.add('dark');
|
element.classList.add('dark');
|
||||||
@ -180,9 +184,9 @@ const set_theme = (elem) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const copy_otp_code = (elem) => {
|
const copy_otp_code = (elem) => {
|
||||||
const content = document.getElementById('user-totp-code').value || '';
|
const content = document.getElementById('user-totp-code').value || '';
|
||||||
if (content == '') { return }
|
if (content === '') { return }
|
||||||
const toast_target = document.getElementById('toast-copy-totp-code');
|
const toast_target = document.getElementById('toast-copy-totp-code');
|
||||||
navigator.clipboard.writeText(content).then(
|
navigator.clipboard.writeText(content).then(
|
||||||
() => {
|
() => {
|
||||||
if (toast_target) {
|
if (toast_target) {
|
||||||
@ -194,7 +198,7 @@ const copy_otp_code = (elem) => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const check_item = async (name, value) => {
|
const check_item = async (name, value) => {
|
||||||
if (CHECK_URL) {
|
if (CHECK_URL) {
|
||||||
const data = {
|
const data = {
|
||||||
name,
|
name,
|
||||||
@ -209,14 +213,14 @@ const check_item = async (name, value) => {
|
|||||||
});
|
});
|
||||||
login_messages.innerHTML='';
|
login_messages.innerHTML='';
|
||||||
if (response.ok && response.status === 200 ) {
|
if (response.ok && response.status === 200 ) {
|
||||||
if (name == 'password') {
|
if (name === 'password') {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
const arr_text = text.split('|');
|
const arr_text = text.split('|');
|
||||||
return {
|
return {
|
||||||
score: arr_text[0] || 0,
|
score: arr_text[0] || 0,
|
||||||
suggestions: arr_text[1].replace('\n','<br>') || '',
|
suggestions: arr_text[1].replace('\n','<br>') || '',
|
||||||
warning: arr_text[2] || '',
|
warning: arr_text[2] || '',
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -225,21 +229,21 @@ const check_item = async (name, value) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const log_in = async () => {
|
const log_in = async () => {
|
||||||
login_messages.innerHTML='';
|
login_messages.innerHTML='';
|
||||||
const elem_name = document.getElementById('user-name-inpt');
|
const elem_name = document.getElementById('user-name-inpt');
|
||||||
if (elem_name) {
|
if (elem_name) {
|
||||||
if (elem_name.value == '') {
|
if (elem_name.value === '') {
|
||||||
login_messages.innerHTML='Enter a name';
|
login_messages.innerHTML='Enter a name';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data_name = elem_name.dataset.val;
|
const data_name = elem_name.dataset.val;
|
||||||
if (data_name != elem_name.value) { if (! await set_name(elem_name)) { return; } }
|
if (data_name !== elem_name.value) { if (! await set_name(elem_name)) { return; } }
|
||||||
}
|
}
|
||||||
const name = elem_name ? elem_name.value : '';
|
const name = elem_name ? elem_name.value : '';
|
||||||
const elem_password = document.getElementById('user-password-inpt');
|
const elem_password = document.getElementById('user-password-inpt');
|
||||||
if (elem_password) {
|
if (elem_password) {
|
||||||
if (elem_password.value == '') {
|
if (elem_password.value === '') {
|
||||||
login_messages.innerHTML='Please include a password';
|
login_messages.innerHTML='Please include a password';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -254,14 +258,14 @@ const log_in = async () => {
|
|||||||
otp_code = elem_otp_code.value;
|
otp_code = elem_otp_code.value;
|
||||||
otp_url = document.getElementById('user-totp-url').value || ''
|
otp_url = document.getElementById('user-totp-url').value || ''
|
||||||
otp_auth = document.getElementById('user-totp-inpt').value || '';
|
otp_auth = document.getElementById('user-totp-inpt').value || '';
|
||||||
if (otp_code != '') {
|
if (otp_code !== '') {
|
||||||
if (otp_auth == '' && totp_mode == "mandatory") {
|
if (otp_auth === '' && totp_mode === "mandatory") {
|
||||||
login_messages.innerHTML='Please enter a valid TOTP code';
|
login_messages.innerHTML='Please enter a valid TOTP code';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (totp_mode == 'mandatory' || document.getElementById('use-totp').checked) {
|
if (totp_mode === 'mandatory' || document.getElementById('use-totp').checked) {
|
||||||
const numbers = /^[0-9]+$/;
|
const numbers = /^[0-9]+$/;
|
||||||
if(! otp_auth.match(numbers) || otp_auth.length != totp_digits ) {
|
if(! otp_auth.match(numbers) || otp_auth.length !== totp_digits ) {
|
||||||
login_messages.innerHTML='Please enter a valid TOTP code';
|
login_messages.innerHTML='Please enter a valid TOTP code';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -271,6 +275,9 @@ const log_in = async () => {
|
|||||||
const elem_roles = document.getElementById('user-roles-inpt');
|
const elem_roles = document.getElementById('user-roles-inpt');
|
||||||
var roles = '';
|
var roles = '';
|
||||||
if (elem_roles) { roles = elem_roles.value; }
|
if (elem_roles) { roles = elem_roles.value; }
|
||||||
|
const elem_openids = document.getElementById('user-openids-inpt');
|
||||||
|
var openids = '';
|
||||||
|
if (elem_openids) { openids = elem_openids.value; }
|
||||||
const elem_fullname= document.getElementById('user-fullname-inpt');
|
const elem_fullname= document.getElementById('user-fullname-inpt');
|
||||||
var fullname = '';
|
var fullname = '';
|
||||||
if (elem_fullname) { fullname = elem_fullname.value; }
|
if (elem_fullname) { fullname = elem_fullname.value; }
|
||||||
@ -280,20 +287,20 @@ const log_in = async () => {
|
|||||||
const elem_email = document.getElementById('user-email-inpt');
|
const elem_email = document.getElementById('user-email-inpt');
|
||||||
if (elem_email) {
|
if (elem_email) {
|
||||||
const data_email = elem_email.dataset.val;
|
const data_email = elem_email.dataset.val;
|
||||||
if (data_email != elem_email.value) { if (! await set_email(elem_email)) { return; } }
|
if (data_email !== elem_email.value) { if (! await set_email(elem_email)) { return; } }
|
||||||
}
|
}
|
||||||
const email = elem_email ? elem_email.value : '';
|
const email = elem_email ? elem_email.value : '';
|
||||||
const elem_theme = document.getElementById('theme-select');
|
const elem_theme = document.getElementById('theme-select');
|
||||||
var theme='';
|
var theme='';
|
||||||
var items={};
|
var items={};
|
||||||
if (elem_theme){
|
if (elem_theme){
|
||||||
theme= elem_theme.value;
|
theme= elem_theme.value;
|
||||||
items = {'theme': theme };
|
items = {'theme': theme };
|
||||||
}
|
}
|
||||||
if (INVITE_KEY && INVITE_KEY != '') {
|
if (INVITE_KEY && INVITE_KEY !== '') {
|
||||||
items.invite_key = INVITE_KEY;
|
items.invite_key = INVITE_KEY;
|
||||||
}
|
}
|
||||||
if (INVITE_ID && INVITE_ID != '') {
|
if (INVITE_ID && INVITE_ID !== '') {
|
||||||
items.invite_id = INVITE_ID;
|
items.invite_id = INVITE_ID;
|
||||||
}
|
}
|
||||||
const data = {
|
const data = {
|
||||||
@ -308,6 +315,7 @@ const log_in = async () => {
|
|||||||
otp_auth,
|
otp_auth,
|
||||||
roles,
|
roles,
|
||||||
items,
|
items,
|
||||||
|
openids,
|
||||||
//timestamp: new Date().toLocaleString(),
|
//timestamp: new Date().toLocaleString(),
|
||||||
};
|
};
|
||||||
const response = await fetch(SIGNIN_URL, {
|
const response = await fetch(SIGNIN_URL, {
|
||||||
@ -334,13 +342,14 @@ window.addEventListener('load', () => {
|
|||||||
const section_title = document.getElementById('section-title')
|
const section_title = document.getElementById('section-title')
|
||||||
const back_btn = document.getElementById('back-btn')
|
const back_btn = document.getElementById('back-btn')
|
||||||
const user_roles = document.getElementById('user-roles-inpt');
|
const user_roles = document.getElementById('user-roles-inpt');
|
||||||
|
const user_openids = document.getElementById('user-openids-inpt');
|
||||||
if (show_password) {
|
if (show_password) {
|
||||||
show_password.addEventListener('click', (ev) => {
|
show_password.addEventListener('click', (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
[...show_password.children].forEach(it => {
|
[...show_password.children].forEach(it => {
|
||||||
it.classList.toggle('hidden');
|
it.classList.toggle('hidden');
|
||||||
});
|
});
|
||||||
if (input_password.type == 'password') {
|
if (input_password.type === 'password') {
|
||||||
input_password.type = 'text';
|
input_password.type = 'text';
|
||||||
} else {
|
} else {
|
||||||
input_password.type = 'password';
|
input_password.type = 'password';
|
||||||
@ -353,12 +362,12 @@ window.addEventListener('load', () => {
|
|||||||
[...show_repeat_password.children].forEach(it => {
|
[...show_repeat_password.children].forEach(it => {
|
||||||
it.classList.toggle('hidden');
|
it.classList.toggle('hidden');
|
||||||
});
|
});
|
||||||
if (input_repeat_password.type == 'password') {
|
if (input_repeat_password.type === 'password') {
|
||||||
input_repeat_password.type = 'text';
|
input_repeat_password.type = 'text';
|
||||||
} else {
|
} else {
|
||||||
input_repeat_password.type = 'password';
|
input_repeat_password.type = 'password';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (otp_code_text) {
|
if (otp_code_text) {
|
||||||
otp_code_text.addEventListener('click', (ev) => {
|
otp_code_text.addEventListener('click', (ev) => {
|
||||||
@ -379,6 +388,9 @@ window.addEventListener('load', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (user_roles) {
|
if (user_roles) {
|
||||||
make_role_chips(user_roles);
|
make_chips(user_roles, 'roles');
|
||||||
|
}
|
||||||
|
if (user_openids) {
|
||||||
|
make_chips(user_openids, 'openids');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
const make_role_chips = (elem) => {
|
const make_chips = (elem,keys) => {
|
||||||
const arr_items = elem.value == '' ? [] : elem.value.split(',');
|
const arr_items = elem.value == '' ? [] : elem.value.split(',');
|
||||||
const roles_chips = document.getElementById('roles-chips');
|
const elem_chips = document.getElementById(`${keys}-chips`);
|
||||||
if (roles_chips) {
|
if (elem_chips) {
|
||||||
roles_chips.innerHTML='';
|
elem_chips.innerHTML='';
|
||||||
if (arr_items.length == 0) { return; }
|
if (arr_items.length == 0) { return; }
|
||||||
arr_items.forEach(name => {
|
arr_items.forEach(name => {
|
||||||
if (name.replaceAll(' ','') !== '') {
|
if (name.replaceAll(' ','') !== '') {
|
||||||
@ -11,7 +11,7 @@ const make_role_chips = (elem) => {
|
|||||||
const arr_classes = "inline-flex items-center px-2 py-1 mr-2 text-sm font-medium text-blue-800 bg-blue-100 rounded dark:bg-blue-900 dark:text-blue-300".split(" ");
|
const arr_classes = "inline-flex items-center px-2 py-1 mr-2 text-sm font-medium text-blue-800 bg-blue-100 rounded dark:bg-blue-900 dark:text-blue-300".split(" ");
|
||||||
chip.classList.add(...arr_classes);
|
chip.classList.add(...arr_classes);
|
||||||
chip.innerHTML = `${name}`;
|
chip.innerHTML = `${name}`;
|
||||||
roles_chips.append(chip);
|
elem_chips.append(chip);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -19,6 +19,10 @@ const make_role_chips = (elem) => {
|
|||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const user_roles = document.getElementById('user-roles-inpt');
|
const user_roles = document.getElementById('user-roles-inpt');
|
||||||
if (user_roles) {
|
if (user_roles) {
|
||||||
make_role_chips(user_roles);
|
make_chips(user_roles, 'roles');
|
||||||
|
}
|
||||||
|
const user_openids = document.getElementById('user-openids-inpt');
|
||||||
|
if (user_openids) {
|
||||||
|
make_chips(user_openids, 'openids');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -22,6 +22,7 @@ const load_elem = () => {
|
|||||||
email: document.getElementById('usr-email'),
|
email: document.getElementById('usr-email'),
|
||||||
description: document.getElementById('usr-description'),
|
description: document.getElementById('usr-description'),
|
||||||
roles: document.getElementById('usr-roles'),
|
roles: document.getElementById('usr-roles'),
|
||||||
|
openids: document.getElementById('usr-openids'),
|
||||||
items: document.getElementById('usr-items'),
|
items: document.getElementById('usr-items'),
|
||||||
status: document.getElementById('usr-status'),
|
status: document.getElementById('usr-status'),
|
||||||
current_status: document.getElementById('current-usr-status'),
|
current_status: document.getElementById('current-usr-status'),
|
||||||
@ -57,6 +58,7 @@ const fill_form = () => {
|
|||||||
usrs_elem.form.email.value = usrs_env.user.email;
|
usrs_elem.form.email.value = usrs_env.user.email;
|
||||||
usrs_elem.form.description.value = usrs_env.user.description;
|
usrs_elem.form.description.value = usrs_env.user.description;
|
||||||
usrs_elem.form.roles.value = usrs_env.user.roles;
|
usrs_elem.form.roles.value = usrs_env.user.roles;
|
||||||
|
usrs_elem.form.openids.value = usrs_env.user.openids;
|
||||||
usrs_elem.form.items.value = usrs_env.user.items;
|
usrs_elem.form.items.value = usrs_env.user.items;
|
||||||
usrs_elem.form.status.value = usrs_env.user.status;
|
usrs_elem.form.status.value = usrs_env.user.status;
|
||||||
usrs_env.user.isadmin == 1 ?
|
usrs_env.user.isadmin == 1 ?
|
||||||
@ -86,6 +88,7 @@ const fill_form = () => {
|
|||||||
default:
|
default:
|
||||||
color='yellow';
|
color='yellow';
|
||||||
}
|
}
|
||||||
|
usrs_elem.form.openids.value = usrs_env.openids;
|
||||||
set_user_status(usrs_elem.form.status.value,color);
|
set_user_status(usrs_elem.form.status.value,color);
|
||||||
};
|
};
|
||||||
const collect_form = () => {
|
const collect_form = () => {
|
||||||
@ -94,6 +97,7 @@ const collect_form = () => {
|
|||||||
usrs_env.user.email = usrs_elem.form.email.value;
|
usrs_env.user.email = usrs_elem.form.email.value;
|
||||||
usrs_env.user.description = usrs_elem.form.description.value;
|
usrs_env.user.description = usrs_elem.form.description.value;
|
||||||
usrs_env.user.roles = usrs_elem.form.roles.value;
|
usrs_env.user.roles = usrs_elem.form.roles.value;
|
||||||
|
usrs_env.user.openids = usrs_elem.form.openids.value;
|
||||||
usrs_env.user.items = usrs_elem.form.items.value;
|
usrs_env.user.items = usrs_elem.form.items.value;
|
||||||
usrs_env.user.status = usrs_elem.form.status.value;
|
usrs_env.user.status = usrs_elem.form.status.value;
|
||||||
usrs_elem.form.isadmin.checked ?
|
usrs_elem.form.isadmin.checked ?
|
||||||
@ -111,7 +115,8 @@ const edit_usr = async (id) => {
|
|||||||
if (usrs_env.modal.show) {
|
if (usrs_env.modal.show) {
|
||||||
const res = await get_user('id',id);
|
const res = await get_user('id',id);
|
||||||
if (res.status && res.data.id == id) {
|
if (res.status && res.data.id == id) {
|
||||||
usrs_env.user = res.data;
|
usrs_env.user = res.data;
|
||||||
|
usrs_env.openids = res.openids;
|
||||||
fill_form();
|
fill_form();
|
||||||
usrs_env.modal.show();
|
usrs_env.modal.show();
|
||||||
}
|
}
|
||||||
@ -140,7 +145,7 @@ const on_search = (el) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (usrs_elem.count_select) {
|
if (usrs_elem.count_select) {
|
||||||
if (count_select == total) {
|
if (count_select === total) {
|
||||||
usrs_elem.count_select.innerHTML='';
|
usrs_elem.count_select.innerHTML='';
|
||||||
} else {
|
} else {
|
||||||
usrs_elem.count_select.innerHTML=`${count_select} of`;
|
usrs_elem.count_select.innerHTML=`${count_select} of`;
|
||||||
@ -215,9 +220,12 @@ const table_sort = (col) => {
|
|||||||
case 'isadmin':
|
case 'isadmin':
|
||||||
col_rows.push({ky: data[6], tr:it})
|
col_rows.push({ky: data[6], tr:it})
|
||||||
break;
|
break;
|
||||||
|
case 'openids':
|
||||||
|
col_rows.push({ky: data[7], tr:it})
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (col_rows.length == 0) { return; }
|
if (col_rows.length === 0) { return; }
|
||||||
const is_asc = !usrs_env.cols[col].asc;
|
const is_asc = !usrs_env.cols[col].asc;
|
||||||
usrs_env.cols[col].asc = is_asc;
|
usrs_env.cols[col].asc = is_asc;
|
||||||
if (is_asc) {
|
if (is_asc) {
|
||||||
@ -272,7 +280,7 @@ const alert_info = (task,message) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const post_fetch = async (source,url = '',source_data) => {
|
const post_fetch = async (source,url = '',source_data) => {
|
||||||
if (url == '') { return }
|
if (url === '') { return }
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(source_data),
|
body: JSON.stringify(source_data),
|
||||||
@ -283,19 +291,19 @@ const post_fetch = async (source,url = '',source_data) => {
|
|||||||
alert_danger('hide','');
|
alert_danger('hide','');
|
||||||
alert_info('hide','');
|
alert_info('hide','');
|
||||||
if (response.ok && response.status === 200 ) {
|
if (response.ok && response.status === 200 ) {
|
||||||
if (source == 'get_user') {
|
if (source === 'get_user') {
|
||||||
const name = source_data.name;
|
const name = source_data.name;
|
||||||
const value = source_data.value;
|
const value = `${source_data.value}`;
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data[name] && data[name] == value){
|
if (data.user && data.user[name] && `${data.user[name]}` === value) {
|
||||||
return {status: true, data }
|
return {status: true, data: data.user, openids: data.openids ? data.openids : '' }
|
||||||
} else {
|
} else {
|
||||||
alert_danger('show',`No data found for ${name}`)
|
alert_danger('show',`No data found for ${name}`)
|
||||||
return {status: false, data: {}};
|
return {status: false, data: {}, openids: ''};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const data = await response.text();
|
const data = await response.text();
|
||||||
if (data != '') { alert_info('show',data); }
|
if (data !== '') { alert_info('show',data); }
|
||||||
return {status: true, data }
|
return {status: true, data }
|
||||||
}
|
}
|
||||||
} else if ( response.status === 401 ) {
|
} else if ( response.status === 401 ) {
|
||||||
@ -404,7 +412,7 @@ window.addEventListener('load', () => {
|
|||||||
if (thead[0]) {
|
if (thead[0]) {
|
||||||
[...thead[0].getElementsByTagName('th')].forEach(col => {
|
[...thead[0].getElementsByTagName('th')].forEach(col => {
|
||||||
const th = col.dataset.th;
|
const th = col.dataset.th;
|
||||||
if (th != 'check') {
|
if (th !== 'check') {
|
||||||
usrs_env.cols[th]={asc: false};
|
usrs_env.cols[th]={asc: false};
|
||||||
col.addEventListener('click', (ev) => {
|
col.addEventListener('click', (ev) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user