新增验证接口返回json信息

pull/30/head
taoshihan1991 5 years ago
parent bd93b64dbb
commit 8b8be890a5

@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/taoshihan1991/imaptool/tmpl" "github.com/taoshihan1991/imaptool/tmpl"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
@ -14,13 +15,15 @@ import (
const PageSize = 20 const PageSize = 20
func main() { func main() {
log.Println("listen on 8080...\r\n访问http://127.0.0.1:8080") log.Println("listen on 8080...\r\ngohttp://127.0.0.1:8080")
//根路径 //根路径
http.HandleFunc("/", index) http.HandleFunc("/", index)
//邮件夹 //邮件夹
http.HandleFunc("/list", list) http.HandleFunc("/list", list)
//登陆界面 //登陆界面
http.HandleFunc("/login", login) http.HandleFunc("/login", login)
//验证接口
http.HandleFunc("/check", check)
//详情界面 //详情界面
http.HandleFunc("/view", view) http.HandleFunc("/view", view)
//监听端口 //监听端口
@ -181,6 +184,28 @@ func login(w http.ResponseWriter, r *http.Request) {
} }
} }
//验证接口
func check(w http.ResponseWriter, r *http.Request) {
email := r.PostFormValue("email")
server := r.PostFormValue("server")
password := r.PostFormValue("password")
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"})
w.Header().Set("content-type","text/json")
if email != "" && server != "" && password != "" {
res := tools.CheckEmailPassword(server, email, password)
if res {
msg, _ = json.Marshal(tools.JsonResult{Code: 200, Msg: "验证成功"})
w.Write(msg)
} else {
w.WriteHeader(400)
w.Write(msg)
}
} else {
w.WriteHeader(400)
w.Write(msg)
}
}
//加密cookie //加密cookie
//func authCookie(){ //func authCookie(){
// //

@ -30,3 +30,7 @@ type MailItem struct {
type MailPageList struct { type MailPageList struct {
MailItems []*MailItem MailItems []*MailItem
} }
type JsonResult struct{
Code int `json:"code"`
Msg string `json:"msg"`
}
Loading…
Cancel
Save