You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/controller/login.go

46 lines
1.3 KiB

package controller
import (
"encoding/json"
"fmt"
"github.com/taoshihan1991/imaptool/tools"
"html/template"
"net/http"
)
//登陆界面
func ActionLogin(w http.ResponseWriter, r *http.Request){
html := tools.FileGetContent("html/login.html")
t, _ := template.New("login").Parse(html)
t.Execute(w, nil)
}
//验证接口
func LoginCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "text/json;charset=utf-8;")
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"})
authType := r.PostFormValue("type")
password := r.PostFormValue("password")
switch authType {
case "local":
username := r.PostFormValue("username")
if AuthLocal(username,password){
msg, _ = json.Marshal(tools.JsonResult{Code: 200, Msg: "验证成功,正在跳转..."})
w.Write(msg)
return
}
default:
email := r.PostFormValue("email")
server := r.PostFormValue("server")
if email != "" && server != "" && password != "" {
res := tools.CheckEmailPassword(server, email, password)
if res {
msg, _ = json.Marshal(tools.JsonResult{Code: 200, Msg: "验证成功,正在跳转..."})
auth := fmt.Sprintf("%s|%s|%s", server, email, password)
tools.SetCookie("auth", auth, &w)
w.Write(msg)
return
}
}
}
w.Write(msg)
}