Przeglądaj źródła

changed something in login

litpooh 3 lat temu
rodzic
commit
0a9652062d
2 zmienionych plików z 14 dodań i 5 usunięć
  1. 4 4
      files/login.html
  2. 10 1
      main.go

+ 4 - 4
files/login.html

@@ -1,4 +1,3 @@
-<!DOCTYPE html>
 <html>
     <head>
         <title>Login</title>
@@ -19,11 +18,12 @@
         url: "/login",
         data: {password: password},
         success: function(value){
-            if (value == "true"){
-                 alert("You have logged in");
+          var response = JSON.parse(value)
+            if (response.Matched == true){
+                 alert("Sucess! You have logged in!");
                  window.location='/logout.html' 
             }else{
-                alert("Incorrect Password");
+                alert("Incorrect Password!");
             }
         }
       });

+ 10 - 1
main.go

@@ -15,10 +15,16 @@ type Status struct {
 	LoggedIn bool
 }
 
+type Password struct {
+	Matched bool
+}
+
 func loginHandler(rw http.ResponseWriter, req *http.Request) {
 	if req.Method == "GET" {
 		password := req.FormValue("password")
 		log.Println("The typed password is:" + password)
+		var typed Password
+
 		if password == "admin" {
 			log.Println("Password is correct")
 
@@ -34,11 +40,14 @@ func loginHandler(rw http.ResponseWriter, req *http.Request) {
 				return
 			}
 
-			rw.Write([]byte("true"))
+			typed.Matched = true
 			log.Println("Logged in")
 		} else {
+			typed.Matched = false
 			log.Println("WRONG password!!")
 		}
+		send_message, _ := json.Marshal(typed)
+		rw.Write(send_message)
 	}
 }