Compare commits
8 Commits
a85e63a327
...
f24dcae19f
| Author | SHA1 | Date | |
|---|---|---|---|
|
f24dcae19f
|
|||
|
3761fc1b1e
|
|||
|
b704db1ba1
|
|||
|
b3d846c6f4
|
|||
|
f5f19f6dd4
|
|||
|
af171b3344
|
|||
|
3b9df825cd
|
|||
|
eb62c78624
|
8
frontend/index.css
Normal file
8
frontend/index.css
Normal file
@@ -0,0 +1,8 @@
|
||||
.loginSpacer {
|
||||
height: 33%;
|
||||
}
|
||||
|
||||
#menu {
|
||||
width: 100%;
|
||||
padding: 5%;
|
||||
}
|
||||
40
frontend/index.html
Normal file
40
frontend/index.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>GiacPoints</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/picnic">
|
||||
<link rel="stylesheet" href="/frontend/index.css">
|
||||
</head>
|
||||
<body>
|
||||
<script src="/frontend/index.js"></script>
|
||||
<div id="login" class="flex three" style="height: 100%">
|
||||
<div class="fourth two-fifth-1000"></div>
|
||||
<div class="flex one half fifth-1000" style="height: 100%">
|
||||
<div class="loginSpacer"></div>
|
||||
<article class="card" style="padding: 5%">
|
||||
<label for="name">Name</label> <br>
|
||||
<input type="text" id="name"> <br>
|
||||
<label for="password">Password</label> <br>
|
||||
<input type="password" id="password"> <br>
|
||||
<input type="submit" value="Login" style="width: 100%" onclick="login()" id="loginSubmit"> <br>
|
||||
</article>
|
||||
<div class="loginSpacer"></div>
|
||||
</div>
|
||||
<div class="fourth two-fifth-1000"></div>
|
||||
</div>
|
||||
<div id="mainPage" style="display: none;">
|
||||
<div id="content">
|
||||
<div id="tasks"></div>
|
||||
<div id="history"></div>
|
||||
<div id="addTask"></div>
|
||||
</div>
|
||||
<div id="menu" class="flex three">
|
||||
<button class="third">Tasks</button>
|
||||
<button class="third">History</button>
|
||||
<button class="third">Add Task</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
26
frontend/index.js
Normal file
26
frontend/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
async function login() {
|
||||
// this.preventDefault();
|
||||
// get login details
|
||||
let name = document.getElementById("name").value;
|
||||
let password = document.getElementById("password").value;
|
||||
// request login
|
||||
let response = await fetch("/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
password: password
|
||||
})
|
||||
});
|
||||
// if failed red button
|
||||
// else switch screen
|
||||
if (response.status !== 200) {
|
||||
document.getElementById("loginSubmit").classList.add("error");
|
||||
} else {
|
||||
// switch screen
|
||||
document.getElementById("login").setAttribute("style", "display: none;");
|
||||
document.getElementById("mainPage").setAttribute("style", "");
|
||||
}
|
||||
}
|
||||
13
main.go
13
main.go
@@ -58,15 +58,17 @@ func login(c *gin.Context) {
|
||||
checkErr(err)
|
||||
defer stmt.Close()
|
||||
var user loginOutput
|
||||
err = stmt.QueryRow(userData.Name).Scan(&user.Name, &user.Password, &user.UID, &user.Role)
|
||||
err = stmt.QueryRow(userData.Name).Scan(&user.UID, &user.Name, &user.Password, &user.Role)
|
||||
if err != nil {
|
||||
// search failed user not real
|
||||
c.IndentedJSON(http.StatusNotFound, userData)
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
if user.Password != userData.Password {
|
||||
// user not real
|
||||
c.IndentedJSON(http.StatusNotFound, userData)
|
||||
panic(err)
|
||||
return
|
||||
} else {
|
||||
// user is in
|
||||
@@ -161,12 +163,21 @@ func addTask(c *gin.Context) {
|
||||
|
||||
func main() {
|
||||
router := gin.Default()
|
||||
|
||||
// api routes
|
||||
router.POST("/login", login)
|
||||
router.POST("/completeTask", completeTask)
|
||||
router.POST("/addTask", addTask)
|
||||
router.GET("/getTasks", getTasks)
|
||||
router.GET("/getHistory", getHistory)
|
||||
|
||||
// page routes
|
||||
router.LoadHTMLGlob("frontend/*")
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "index.html", gin.H{})
|
||||
})
|
||||
router.Static("/frontend", "./frontend")
|
||||
|
||||
router.Run("localhost:8080")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user