1/* 2 login 3 =============== 4 Login the user. parameters 5 - email_txt : "" 6 - password_txt : "" 7 - permanent_checkbox : "" to keep the user logged in. 8*/ 9export async function login(config) 10{ 11 try { 12 let value_list = {'email_txt': 'email', 'password_txt': 'password', 'permanent_checkbox': 'permanent'}; 13 let formdata = []; 14 for(let [element_id, dict_id] of Object.entries(value_list)) { 15 if(!config.hasOwnProperty(element_id)) continue; 16 formdata.push(`${ dict_id }=${ config[element_id] }`); 17 } 18 19 let res = await fetch('/login', { 20 headers: { 21 'Accept': 'application/x-www-form-urlencoded', 22 "Content-Type": "application/x-www-form-urlencoded" 23 }, 24 method: 'POST', 25 body: formdata.join('&') 26 }); 27 28 if(!res) return null; 29 let status = JSON.parse(await res.text()); 30 return status; 31 } catch(error) { 32 console.error(error); 33 } 34 35 return null; 36} 37/* 38 Logout 39 =============== 40 Logout the member. 41*/ 42export async function logout() 43{ 44 try { 45 let response = await fetch('/logout', { 46 method: 'POST' 47 }); 48 49 let ret = JSON.parse(await response.text()); 50 if(ret['logout']) { 51 return ret['logout']; 52 } 53 } catch(error) { 54 console.error(error); 55 } 56 57 return false; 58} 59/* 60 Forgetpass 61 =============== 62 Provide an email to send the forget password email. 63*/ 64export async function forgetpass(email) 65{ 66 try { 67 let response = await fetch('/forgetpass', { 68 headers: { 69 'Accept': 'application/x-www-form-urlencoded', 70 "Content-Type": "application/x-www-form-urlencoded" 71 }, 72 method: 'POST', 73 body: new URLSearchParams({ email }).toString() 74 }); 75 76 let ret = JSON.parse(await response.text()); 77 return { 78 forgetpass: ret['forgetpass'] === true, 79 reason: ret['reason'] || (ret['forgetpass'] ? 'sent' : 'unknown_error') 80 }; 81 } catch(error) { 82 console.error(error); 83 } 84 85 return { 86 forgetpass: false, 87 reason: 'network_error' 88 }; 89} 90 91/* 92 Reset the password. 93 =============== 94 Provide token and password to reset for the user. 95*/ 96export async function resetpass(token, password) 97{ 98 try { 99 let response = await fetch('/resetpass', { 100 headers: { 101 'Accept': 'application/x-www-form-urlencoded', 102 "Content-Type": "application/x-www-form-urlencoded" 103 }, 104 method: 'POST', 105 body: `token=${ encodeURIComponent(token) }&password=${ encodeURIComponent(password) }` 106 }); 107 108 let ret = JSON.parse(await response.text()); 109 return ret['resetpass']; 110 } catch(error) { 111 console.error(error); 112 } 113 114 return false; 115} 116 117/* 118 Change the password. 119 =============== 120 Provice current password and password to change the password for the current user. 121*/ 122export async function changepass(participant_code, current_password, password) 123{ 124 try { 125 let response = await fetch('/changepass', { 126 headers: { 127 'Accept': 'application/x-www-form-urlencoded', 128 "Content-Type": "application/x-www-form-urlencoded" 129 }, 130 method: 'POST', 131 body: `participant_code=${ participant_code }¤t_password=${ current_password }&password=${ password }` 132 }); 133 134 let ret = JSON.parse(await response.text()); 135 return ret['changepass']; 136 } catch(error) { 137 console.error(error); 138 } 139 140 return false; 141} 142 143 144/* 145 refreshToken. 146 =============== 147 Refresh Access token 148*/ 149export async function refreshToken(token = '') 150{ 151 try { 152 let response = await fetch('/refreshtoken', { 153 headers: { 154 'Accept': 'application/x-www-form-urlencoded', 155 "Content-Type": "application/x-www-form-urlencoded" 156 }, 157 method: 'POST' 158 }); 159 160 let refreshed = JSON.parse(await response.text()); 161 162 if(refreshed['refreshtoken'] == false) 163 return ''; 164 else 165 return refreshed['token']; 166 } catch(error){ 167 console.error('[*] Invalid Login Response'); 168 } 169 170 return ''; 171}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.