code.gs
function doGet() {
return HtmlService.createTemplateFromFile('index')
.evaluate()
.setTitle('Login')
.setFaviconUrl('https://ik.imagekit.io/kmpeld0nh/GoshenN%20(3).png')
.addMetaTag('viewport', 'width=device-width, initial-scale=1')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
/**Include */
function include(filename){
return HtmlService.createHtmlOutputFromFile(filename).getContent()
}
let ss = SpreadsheetApp.openById("1sRyzo2KGpizo_4jZwUMMLfxuJG0WfDpfLBTetcxv9ZE").getSheetByName("pass")
let pass = ss.getRange("A2").getValue()
******************
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.7.28/dist/sweetalert2.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11.7.28/dist/sweetalert2.min.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class='container' id='page' style='display:none'>
<button class="btn btn-primary" onclick="pass()">Login</button>
<?!= include('home'); ?>
</div>
<div class='container' id='pcontent' style='display:none'>
<button class="btn btn-danger" onclick="logout()">Logout</button>
<?!= include ('content'); ?>
</div>
<script>
window.onload = function(){
pass()
}
async function pass(){
const { value: password } = await Swal.fire({
position: 'top',
title: 'กรุณาใส่รหัสผ่าน',
confirmButtonColor: 'red',
confirmButtonText: 'ตกลง',
input: 'password',
// inputLabel: 'เข้าสู่การลบข้อมูล',
inputPlaceholder: 'ใส่รหัสผ่านของคุณ',
inputValidator: (value) => {
if (!value) {
return 'กรุณากรอกรหัสผ่าน(password) ให้ถูกต้อง!'
}
},
inputAttributes: {
maxlength: 10,
autocapitalize: 'off',
autocorrect: 'off'
}
})
if (password==="<?!= pass ?>") {
document.getElementById('page').style.display = 'none';
document.getElementById('pcontent').style.display = 'block';
}else{
await Swal.fire({
position: 'top',
icon: 'error',
title: 'รหัสผ่านไม่ถูกต้อง',
showConfirmButton: false,
timer: 1500
})
pass()
}
}
function logout(){
Swal.fire({
title: 'ออกจากระบบ!',
text: "คุณต้องการออกจากระบบ ใช่หรือไม่?",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: 'ตกลง!',
cancelButtonColor: '#d33',
cancelButtonText: 'ยกเลิก',
}).then((result) => {
if (result.isConfirmed) {
document.getElementById('page').style.display = 'block';
document.getElementById('pcontent').style.display = 'none';
}
})
}
</script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</body>
</html>
********************************
home.html
<center><h1>Home</h1></center>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td colspan="2">Larry the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
**********************
content.html
<center><h1>หน้าที่ 2 เข้าระบบสำเร็จ!!</h1></center>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<!-- หน้า Admin เข้าระบบสำเร็จ!! -->
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Accordion Item #2
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Accordion Item #3
</button>
</h2>
<div id="collapseThree" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
</div>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น
หมายเหตุ: มีเพียงสมาชิกของบล็อกนี้เท่านั้นที่สามารถแสดงความคิดเห็น