1import * as common from './common/common.js'; 2import * as auth from './common/auth.js' 3import * as config from './common/config.js'; 4import * as user from './common/user.js'; 5 6function formatDateWithMonthName(dateStr) { 7 // Parse the DD/MM/YYYY format 8 const [day, month, year] = dateStr.split('/'); 9 const date = new Date(`${year}-${month}-${day}`); // Reformat to YYYY-MM-DD for Date() 10 11 // Format to '1 September 2024' 12 return date.toLocaleDateString('th-TH', { 13 day: 'numeric', 14 month: 'long', 15 year: 'numeric' 16 }); 17 } 18 19 20// สำหรัภà¸à¹à¸à¸à¸²à¸¢à¸¸à¸à¸±à¸à¹à¸à¸¡à¸±à¸à¸´ 21// à¹à¸¡à¹à¹à¸à¹à¹à¸à¸·à¹à¸à¸à¸à¸²à¸ à¸à¹à¸à¸à¸à¸±à¸à¹à¸¡à¹à¹à¸«à¹à¸à¹à¸à¸à¸²à¸¢à¸¸à¸à¸±à¸à¹à¸à¸¡à¸±à¸à¸´à¸à¸£à¸±à¸ 22// à¹à¸à¸£à¸²à¸°à¸à¹à¸²à¸à¹à¸à¸à¸²à¸¢à¸¸à¹à¸à¸ à¹à¸à¹à¸ªà¸£à¹à¸à¹à¸¥à¸°à¸à¸·à¹à¸ ๠à¸à¹à¹à¸¡à¹à¹à¸à¹à¸à¸±à¸à¹à¸«à¸¥à¸à¹à¸à¹à¸²à¸£à¸°à¸à¸ 23async function autoRecurring() 24{ 25 let payload_data = await common.isLoggedin(); 26 let { participant_code } = payload_data; 27 let user_data = await user.getUserData({ participant_code }); 28 let conf = await config.getConfig(['register_start_date', 'register_end_date', 'register_year']); 29 let today = new Date(); 30 let curr_date = today.getTime(); 31 let start_date = conf['register_start_date'].split('/').map((data) => parseInt(data)), 32 end_date = conf['register_end_date'].split('/').map((data) => parseInt(data)); 33 start_date = parseInt(start_date[2]) + '-' + start_date[1] + '-' + start_date[0]; 34 end_date = parseInt(end_date[2]) + '-' + end_date[1] + '-' + end_date[0]; 35 start_date = Date.parse(start_date); 36 end_date = Date.parse(end_date); 37 end_date += (16 * 60 * 60 * 1000) + (59 * 60 * 1000) + (59 * 1000); 38 39 let register_year_conf = conf['register_year']; 40 let closed_register = curr_date > end_date; 41 let current_user = user_data[0]; 42 let { registered_date, registered_year } = current_user; 43 let split_register_date = registered_date.trim().split('/').map((data) => parseInt(data)); 44 let register_date = parseInt(split_register_date[2]) + '-' + split_register_date[1] + '-' + split_register_date[0]; 45 register_date = Date.parse(register_date); 46 let issameyear = registered_year == register_year_conf; 47 if(register_date < start_date && !issameyear && closed_register) { // && user_each['user_status']['type_id'] != 2) { 48 let isrenewed = current_user['tracking'].find(data => data['sent_year'] == register_year_conf); 49 if(isrenewed) { 50 await user.autoRecurring(participant_code); 51 } 52 } 53 54 return user_data; 55} 56 57/* 58 isFoundPDPAaccept 59 ====================== 60 Check this member has already accepted the PDPA or not. 61 user_data (optional): the user data accquired from the database. 62*/ 63async function isFoundPDPAaccept(user_data = null) 64{ 65 // If user_data is not defined, get the data from the database. 66 if(!user_data) { 67 let payload_data = await common.isLoggedin(); 68 let { participant_code } = payload_data; 69 user_data = await user.getUserData({ participant_code }); 70 } 71 72 let current_user = user_data[0]; 73 let pdpa = (current_user['accept_pdpa'] != '') ? JSON.parse(current_user['accept_pdpa']) : null; 74 if(pdpa && pdpa.hasOwnProperty('thaineqas')) { 75 return true; 76 } 77} 78 79/* 80 loginSubmitEvent 81 ====================== 82 The event is started after clicking login button. 83*/ 84async function loginSubmitEvent(e) 85{ 86 e.preventDefault(); 87 88 try { 89 let value_list = { 90 'email_txt': 'email', 91 'password_txt': 'password', 92 'permanent_checkbox': 'permanent' 93 }; 94 95 let sent_dict = {}; 96 for(let element_id of Object.keys(value_list)) { 97 let id_type = element_id.split('_'); 98 let obj_type = id_type[id_type.length - 1]; 99 100 if(obj_type == 'checkbox') { 101 sent_dict[element_id] = document.getElementById(element_id).checked; 102 } else 103 sent_dict[element_id] = encodeURIComponent(document.getElementById(element_id).value); 104 } 105 106 // Send the login credential to the server.
107 let status = await auth.login(sent_dict); 108 109 // If the password is not correct. 110 if(!status) { 111 location.href = `?incorrect=true`; 112 return; 113 } 114 115 // Check the status of the page 116 // 1 -> moderator 117 // 0 -> member 118 let ismoderator = document.getElementById('ismoderator_hidden').value; 119 let login_alert = document.getElementById('login_error'); 120 let alert_area = login_alert.querySelector('.alert'); 121 switch(ismoderator) { 122 case '1': 123 // Check whether the member is moderator or super admin 124 // For ordinary member. 125 if(!status['moderator']) { 126 await auth.logout(); 127 alert_area.innerHTML = "สมาà¸à¸´à¸à¸à¸µà¹à¹à¸¡à¹à¹à¸à¹à¹à¸à¹à¸à¸à¸¹à¹à¸à¸¹à¹à¸¥à¸£à¸°à¸à¸ à¸à¸£à¸¸à¸à¸²<a href = '/index.html' class = 'alert-link'>à¸à¸à¸à¸µà¹à¸¥à¸´à¹à¸à¸à¹à¸à¸µà¹</a>à¹à¸à¸."; 128 login_alert.style.display = ''; 129 return; 130 } else { 131 // For moderator or admin. 132 if(status['login'] === true) { 133 // Check PDPA status 134 if(await isFoundPDPAaccept()) 135 location.href = '/admin/information.html'; 136 else 137 location.href = `/pdpa_page.html?type=login`; // Moderator 138 return; 139 } 140 } 141 break; 142 143 case '0': 144 // Check whether the member is moderator or super admin 145 if(status['moderator']) { 146 await auth.logout(); 147 alert_area.innerHTML = "สมาà¸à¸´à¸à¸à¸µà¹à¹à¸à¹à¸à¸à¸¹à¹à¸à¸¹à¹à¸¥à¸£à¸°à¸à¸ à¸à¸£à¸¸à¸à¸²<a href = '/admin/' class = 'alert-link'>à¸à¸à¸à¸µà¹à¸¥à¸´à¹à¸à¸à¹à¸à¸µà¹</a>à¹à¸à¸."; 148 login_alert.style.display = ''; 149 return; 150 } else { 151 // For ordinary member. 152 if(status['login'] === true) { 153 // Check PDPA status 154 let user_data; 155 // user_data = await autoRecurring(); 156 if(await isFoundPDPAaccept(user_data)) 157 location.href = '/information.html' 158 else 159 location.href = `/pdpa_page.html?type=login`; 160 return; 161 } 162 } 163 break; 164 } 165 } catch(error) { 166 console.error(error); 167 await common.messageBox('à¸à¸à¸à¸±à¸à¸«à¸²à¸£à¸°à¸«à¸§à¹à¸²à¸à¸à¸²à¸£à¹à¸à¹à¸²à¸ªà¸¹à¹à¸£à¸°à¸à¸'); 168 } 169 170 location.href = `?incorrect=true`; 171} 172 173/* 174 onPageLoaded 175 ====================== 176 The event is started after the page finished loading. 177*/ 178async function onPageLoaded(event) 179{ 180 // Check the logged in status whether the user is logged in or not. 181 let loggedin = await common.isLoggedin(); 182 if(loggedin) { 183 // If the user is logged in, redirect to the specified page. 184 // user_type == 0 for member 185 // user_type == 1 for moderator, and user_type == 2 for super admin 186 if(loggedin['login']) { 187 location.href = (loggedin['user_type'] == 0) ? `/information.html` : `/admin/information.html`; 188 } 189 } 190 191 // Check the date that it is enabled for registration or recurring or not. 192 // start -> register_start_date 193 // end -> register_end_date 194 // registration by the link only -> enable_register_by_link 195 try { 196 // Load Configuration from the database. 197 let today = new Date(); 198 let conf = await config.getConfig(['register_start_date', 199 'register_end_date', 200 'register_year', 201 'enable_register_by_link']); 202 203 let start_date = conf['register_start_date'].split('/'), 204 end_date = conf['register_end_date'].split('/'); 205 206 start_date = parseInt(start_date[2]) + '-' + start_date[1] + '-' + start_date[0]; 207 end_date = parseInt(end_date[2]) + '-' + end_date[1] + '-' + end_date[0]; 208 209 let curr_date = today.getTime(); 210 start_date = Date.parse(start_date); 211 end_date = Date.parse(end_date); 212 end_date += (16 * 60 * 60 * 1000) + (59 * 60 * 1000) + (59 * 1000); 213 214 // Check the current date is in the range of the registration date or not. 215 // Moreover, it should be checked that the register is allowed only from clicking the link or not. 216 let register_info = document.getElementById('registered_info');
217 if (conf['enable_register_by_link'] == '1') { 218 register_info.style.display = ''; 219 register_info.querySelector('.alert').innerText = 'à¸à¸à¸°à¸à¸µà¹à¸¢à¸±à¸à¹à¸¡à¹à¹à¸à¹à¹à¸à¸´à¸à¹à¸«à¹à¸ªà¸¡à¸±à¸à¸£à¸ªà¸¡à¸²à¸à¸´à¸à¹à¸«à¸¡à¹ หรืà¸à¸à¹à¸à¸à¸²à¸¢à¸¸à¸ªà¸¡à¸²à¸à¸´à¸'; 220 document.getElementById('register_div').style.display = 'none'; 221 } else if (curr_date < start_date || curr_date > end_date) { 222 register_info.style.display = ''; 223 const start = formatDateWithMonthName(conf['register_start_date']); 224 const end = formatDateWithMonthName(conf['register_end_date']); 225 const year = Number(conf['register_year']) + 543; 226 register_info.querySelector('.alert').innerText = 227 `à¸à¸à¸°à¸à¸µà¹à¸¢à¸±à¸à¹à¸¡à¹à¹à¸à¹à¹à¸à¸´à¸à¹à¸«à¹à¸ªà¸¡à¸±à¸à¸£à¸ªà¸¡à¸²à¸à¸´à¸à¹à¸«à¸¡à¹ หรืà¸à¸à¹à¸à¸à¸²à¸¢à¸¸à¸ªà¸¡à¸²à¸à¸´à¸ (à¸à¸°à¹à¸à¸´à¸à¸£à¸±à¸à¸ªà¸¡à¸±à¸à¸£à¸ªà¸¡à¸²à¸à¸´à¸à¸à¸à¸à¸à¸µ ${year} à¹à¸à¸§à¸±à¸à¸à¸µà¹ ${start} - ${end})`; 228 document.getElementById('register_div').style.display = 'none'; 229 } else { 230 register_info.style.display = ''; 231 const start = formatDateWithMonthName(conf['register_start_date']); 232 const end = formatDateWithMonthName(conf['register_end_date']); 233 const year = Number(conf['register_year']) + 543; 234 register_info.querySelector('.alert').innerText = 235 `สามารà¸à¸ªà¸¡à¸±à¸à¸£à¸ªà¸¡à¸²à¸à¸´à¸à¹à¸«à¸¡à¹ หรืà¸à¸à¹à¸à¸à¸²à¸¢à¸¸à¸ªà¸¡à¸²à¸à¸´à¸ à¸à¸£à¸°à¸à¸³à¸à¸µ ${year} (ระหวà¹à¸²à¸à¸§à¸±à¸à¸à¸µà¹ ${start} - ${end})`; 236 } 237 } catch(error) { 238 console.error("[*] No limitation of registeration verification."); 239 console.error(error); 240 } 241 242 // If the password is incorrect. Show the login error. 243 let param = common.getparam('incorrect'); 244 let pass_incorrect = (param) ? (param == 'true') : false; 245 let login_alert = document.getElementById('login_error'); 246 247 if(pass_incorrect) { 248 let alert_area = login_alert.querySelector('.alert'); 249 alert_area.innerText = "à¸à¸µà¹à¸¡à¸¥ หรืà¸à¸£à¸«à¸±à¸ªà¸à¹à¸²à¸à¹à¸¡à¹à¸à¸¹à¸à¸à¹à¸à¸"; 250 login_alert.style.display = ''; 251 } else 252 login_alert.style.display = 'none'; 253} 254 255window.addEventListener('DOMContentLoaded', onPageLoaded); 256document.getElementById('login_form').addEventListener('submit', loginSubmitEvent);
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.