Compare commits

...

8 Commits

Author SHA1 Message Date
f24dcae19f Started main page ui 2023-07-17 20:14:00 +01:00
3761fc1b1e Fixed sql error 2023-07-17 17:42:33 +01:00
b704db1ba1 Login page functionality 2023-07-17 17:42:12 +01:00
b3d846c6f4 Styled login ui 2023-07-17 17:10:16 +01:00
f5f19f6dd4 Basic frontend login ui 2023-07-17 16:52:39 +01:00
af171b3344 index.html 2023-07-16 19:46:52 +01:00
3b9df825cd Started frontend 2023-07-16 18:44:56 +01:00
eb62c78624 Started frontend 2023-07-16 18:43:58 +01:00
5 changed files with 86 additions and 1 deletions

8
frontend/index.css Normal file
View File

@@ -0,0 +1,8 @@
.loginSpacer {
height: 33%;
}
#menu {
width: 100%;
padding: 5%;
}

40
frontend/index.html Normal file
View 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
View 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", "");
}
}

BIN
main

Binary file not shown.

13
main.go
View File

@@ -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")
}