yeungalan před 4 roky
rodič
revize
77e1825841
2 změnil soubory, kde provedl 39 přidání a 4 odebrání
  1. 27 4
      main.go
  2. 12 0
      user.json

+ 27 - 4
main.go

@@ -13,7 +13,7 @@ import (
 	"github.com/valyala/fasttemplate"
 )
 
-//ClientInformationStruct export
+//ClientsInformationStruct export
 type ClientsInformationStruct []struct {
 	ClientID     string   `json:"client-id"`
 	ClientSecret string   `json:"client-secret"`
@@ -23,6 +23,20 @@ type ClientsInformationStruct []struct {
 	Scope        []string `json:"scope"`
 }
 
+//UsersInformationStruct shouldn be exported
+type UsersInformationStruct []struct {
+	Scope []struct {
+		Name  string `json:"name"`
+		Value string `json:"value"`
+	} `json:"scope"`
+	Granted []struct {
+		ClientID struct {
+			Scope  []string `json:"scope"`
+			Status string   `json:"status"`
+		} `json:"client-id"`
+	} `json:"granted"`
+}
+
 func main() {
 	http.HandleFunc("/login", loginHandler)
 	http.HandleFunc("/chklogin", chkloginHandler)
@@ -56,10 +70,15 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
 func chkloginHandler(w http.ResponseWriter, r *http.Request) {
 	// Call ParseForm() to parse the raw query and update r.PostForm and r.Form.
 	if err := r.ParseForm(); err != nil {
-		fmt.Fprintf(w, "ParseForm() err: %v", err)
-		return
+		errHandler(w, r, "Missing post parameter")
+	}
+	data, err := ioutil.ReadFile("./user.json")
+	if err != nil {
+		fmt.Print(err)
 	}
-	fmt.Fprintf(w, "Post from website! r.PostFrom = %v\n", r.PostForm)
+	var UsersInformation UsersInformationStruct
+	err = json.Unmarshal(data, &UsersInformation)
+
 	email := r.FormValue("email")
 	password := r.FormValue("password")
 	fmt.Println(email, password)
@@ -142,6 +161,10 @@ func confirmClientInformation(w http.ResponseWriter, r *http.Request) (string, s
 	return DBClientSecret, DBDomain, DBServiceName, DBServiceImage, responseType, clientID, redirectURI, scope, state, nonce
 }
 
+func confirmUserInfo(w http.ResponseWriter, r *http.Request, username string) {
+
+}
+
 func getGET(w http.ResponseWriter, r *http.Request, name string) string {
 	response, ok := r.URL.Query()[name]
 	if !ok || len(response[0]) < 1 {

+ 12 - 0
user.json

@@ -0,0 +1,12 @@
+[{
+    "scope": [
+        { "name": "email", "value": "admin@link.cuhk.edu.hk" },
+        { "name": "password", "value": "123456" }
+    ],
+    "granted": [{
+        "client-id": {
+            "scope": ["openid", "username"],
+            "status": "trusted"
+        }
+    }]
+}]