From b78b4a136d5d1b90504c84ac94b30e42036bd625 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Tue, 19 May 2020 19:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=92=8C=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.go | 6 +- static/html/login.html | 130 ++++++++++++++++++++++++++++++++++ tmpl/login.go | 156 ++++++++++++++++++++--------------------- tools/cookie.go | 8 ++- 4 files changed, 217 insertions(+), 83 deletions(-) create mode 100644 static/html/login.html diff --git a/server.go b/server.go index 33092e7..d49b715 100644 --- a/server.go +++ b/server.go @@ -191,11 +191,13 @@ func check(w http.ResponseWriter, r *http.Request) { password := r.PostFormValue("password") msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"}) - w.Header().Set("content-type","text/json") + w.Header().Set("content-type","text/json;charset=utf-8;") if email != "" && server != "" && password != "" { res := tools.CheckEmailPassword(server, email, password) if res { - msg, _ = json.Marshal(tools.JsonResult{Code: 200, Msg: "验证成功"}) + 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) } else { w.Write(msg) diff --git a/static/html/login.html b/static/html/login.html new file mode 100644 index 0000000..b399bb3 --- /dev/null +++ b/static/html/login.html @@ -0,0 +1,130 @@ + + + + + + + GO-IMAP网页版邮箱imap工具登录页 + + + + + + + + + + +
+ +
+ + + diff --git a/tmpl/login.go b/tmpl/login.go index cf9facc..dae273a 100644 --- a/tmpl/login.go +++ b/tmpl/login.go @@ -7,32 +7,20 @@ import ( func RenderLogin(w http.ResponseWriter, render interface{}) { const html = ` - - - - 邮箱IMAP-登录页 + + GO-IMAP网页版邮箱imap工具登录页 - @@ -87,18 +54,23 @@ func RenderLogin(w http.ResponseWriter, render interface{}) {
@@ -106,42 +78,66 @@ func RenderLogin(w http.ResponseWriter, render interface{}) { new Vue({ el: '#app', data: { - imapEmail:"", - imapServer:"", - imapPass:"", loading:false, + ruleForm:{ + server:'', + email:'', + password:'', + }, + rules: { + server: [ + { required: true, message: 'IMAP服务器如"imap.sina.net:143"包含端口号', trigger: 'blur' }, + ], + email: [ + { required: true, message: '邮箱地址', trigger: 'blur' }, + ], + password: [ + { required: true, message: '邮箱密码', trigger: 'blur' }, + ], + }, }, methods: { - checkEmailPass: function () { - var data={} - data.server=this.imapServer; - data.email=this.imapEmail; - data.password=this.imapPass; - let _this=this; - this.loading=true; - $.post("/check",data,function(data){ - if(data.code==200){ - _this.$message({ - message: data.msg, - type: 'success' - }); - }else{ - _this.$message({ - message: data.msg, - type: 'error' - }); - } - _this.loading=false; - }); - - } + //提交表单 + submitForm(formName){ + let _this=this; + this.$refs[formName].validate((valid) => { + if (valid) { + var data={} + data.server=_this.ruleForm.server; + data.email=_this.ruleForm.email; + data.password=_this.ruleForm.password; + _this.loading=true; + $.post("/check",data,function(data){ + if(data.code==200){ + _this.$message({ + message: data.msg, + type: 'success' + }); + window.location.href="/"; + }else{ + _this.$message({ + message: data.msg, + type: 'error' + }); + } + _this.loading=false; + }); + } else { + return false; + } + }); + }, + //重置表单 + resetForm(formName) { + this.loading=false; + this.$refs[formName].resetFields(); + }, } }) - ` - t, _ := template.New("list").Parse(html) + t, _ := template.New("login").Parse(html) t.Execute(w, render) } diff --git a/tools/cookie.go b/tools/cookie.go index 2d9befa..853c4f9 100644 --- a/tools/cookie.go +++ b/tools/cookie.go @@ -4,7 +4,13 @@ import ( "net/http" "strings" ) - +func SetCookie(name string,value string,w *http.ResponseWriter){ + cookie := http.Cookie{ + Name: name, + Value: value, + } + http.SetCookie(*w, &cookie) +} func GetCookie(r *http.Request, name string) string { cookies := r.Cookies() for _, cookie := range cookies {