コード例 #1
0
ファイル: templating.go プロジェクト: kevinhuo88888/o3erp
func prepareMessage(userLoginId string, args ...interface{}) map[string]string {

	m := make(map[string]string)
	labels := []string{}
	for index := range args {
		s := strings.Split(args[index].(string), ":")
		labels = append(labels, s[1])
		m[s[0]] = s[1]
	}

	labelMap, err := helper.RunThriftService(helper.GetMessageMapFunction(userLoginId, labels))
	if err != nil {
		log.Println("error: ", err)
	}

	for key, value := range m {
		m[key] = labelMap[value]
	}

	return m
}
コード例 #2
0
ファイル: login.go プロジェクト: kevinhuo88888/o3erp
func LoginHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	userLoginId := r.FormValue("email")
	password := r.FormValue("password")
	if userLoginId != "" && password != "" {

		msg, err := helper.RunThriftService(helper.GetLoginFunction(userLoginId, password))
		if err != nil {
			log.Println("error: ", err)
		} else {
			log.Println("success: ", msg, err)
		}
		if msg["responseMessage"] == "success" {
			// Get a session. We're ignoring the error resulted from decoding an
			// existing session: Get() always returns a session, even if empty.
			session, _ := sessions.SessionStore.Get(r, "session-name")

			// Set some session values.
			log.Println("partyId:", msg["partyId"])
			session.Values[sessions.PARTY_ID] = msg["partyId"]
			session.Values[sessions.USER_LOGIN_ID] = userLoginId
			// Save it.
			session.Save(r, w)

			// redirect to dashboard
			http.Redirect(w, r, "/dashboard", http.StatusFound)
			return
		}

	}

	fmt.Println("login credential incorrect")
	// redirect to login
	http.Redirect(w, r, "/login", http.StatusFound)
	return

}