Example #1
0
func SecretHandler(rw http.ResponseWriter, req *http.Request) {
	if !Basic(rw, req) {
		return
	}
	vars := mux.Vars(req)
	msgtype := vars["msgtype"]
	if req.Method != "POST" && msgtype == "" {
		// 获取用户信息
		err := config.LoadSecretOption()
		if err != nil {
			fmt.Fprint(rw, `{"errno": 1, "error":"`, "读取秘钥配置数据失败", `"}`)
			return
		}
		// 设置模板数据
		filter.SetData(req, map[string]interface{}{"config": config.SecretOption})
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/trade/secret.html")
		return
	} else {
		config.SecretOption["username"] = req.FormValue("username")
		config.SecretOption["password"] = req.FormValue("password")

		config.SecretOption["huobi_access_key"] = req.FormValue("huobi_access_key")
		config.SecretOption["huobi_secret_key"] = req.FormValue("huobi_secret_key")

		config.SecretOption["ok_partner"] = req.FormValue("ok_partner")
		config.SecretOption["ok_secret_key"] = req.FormValue("ok_secret_key")

		config.SecretOption["smtp_username"] = req.FormValue("smtp_username")
		config.SecretOption["smtp_password"] = req.FormValue("smtp_password")
		config.SecretOption["smtp_host"] = req.FormValue("smtp_host")
		config.SecretOption["smtp_addr"] = req.FormValue("smtp_addr")

		// 更新个人信息
		err := config.SaveSecretOption()
		if err != nil {
			fmt.Fprint(rw, `{"errno": 1, "error":"`, "写入秘钥配置数据失败", `"}`)
			return
		}

		fmt.Fprint(rw, `{"errno": 0, "msg":"更新秘钥配置成功!"}`)

		go email.TriggerTrender("btcrobot测试邮件,您能收到这封邮件说明您的SMTP配置成功,来自星星的机器人")
	}
}
Example #2
0
func SecretHandler(rw http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	msgtype := vars["msgtype"]
	if req.Method != "POST" && msgtype == "" {
		// 获取用户信息
		err := config.LoadSecretOption()
		if err != nil {
			fmt.Fprint(rw, `{"errno": 1, "error":"`, "读取秘钥配置数据失败", `"}`)
			return
		}
		// 设置模板数据
		filter.SetData(req, map[string]interface{}{"config": config.SecretOption})
		req.Form.Set(filter.CONTENT_TPL_KEY, "/template/trade/secret.html")
		return
	} else {
		config.SecretOption["access_key"] = req.FormValue("access_key")
		config.SecretOption["secret_key"] = req.FormValue("secret_key")

		config.SecretOption["email"] = req.FormValue("email")
		config.SecretOption["password"] = req.FormValue("password")

		config.SecretOption["smtp_username"] = req.FormValue("smtp_username")
		config.SecretOption["smtp_password"] = req.FormValue("smtp_password")
		config.SecretOption["smtp_host"] = req.FormValue("smtp_host")
		config.SecretOption["smtp_addr"] = req.FormValue("smtp_addr")

		// 更新个人信息
		err := config.SaveSecretOption()
		if err != nil {
			fmt.Fprint(rw, `{"errno": 1, "error":"`, "写入秘钥配置数据失败", `"}`)
			return
		}

		fmt.Fprint(rw, `{"errno": 0, "msg":"更新秘钥配置成功!"}`)
	}
}