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工具登录页
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 邮箱网页版IMAP工具
+
+
+
+
+
+
+
+
+
+
+ 立即登录
+ 重置
+
+
+ © 2020
+
+
+
+
+
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{}) {
-
+
+ 邮箱网页版IMAP工具
+
+
+
+
+
+
+
+
+
+
+ 立即登录
+ 重置
+
+
+ © 2020
@@ -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 {