客服登陆接口表结构

pull/30/head
陶士涵 5 years ago
parent 1149bd1d22
commit 059a9fdb56

@ -0,0 +1,10 @@
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL DEFAULT '',
`password` varchar(50) NOT NULL DEFAULT '',
`nickname` varchar(50) NOT NULL DEFAULT '',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8

@ -7,8 +7,6 @@ import (
) )
func CheckPass(username string, password string) string { func CheckPass(username string, password string) string {
models.FindUsers()
account := config.GetAccount() account := config.GetAccount()
if account == nil { if account == nil {
account = make(map[string]string) account = make(map[string]string)
@ -27,7 +25,13 @@ func CheckPass(username string, password string) string {
} }
return "" return ""
} }
func CheckKefuPass(username string, password string) (models.User,bool) {
info:=models.FindUser(username)
if info.Name==""||info.Password!=tools.Md5(password){
return info,false
}
return info,true
}
func AuthLocal(username string, password string) string { func AuthLocal(username string, password string) string {
account := config.GetAccount() account := config.GetAccount()
if account == nil { if account == nil {

@ -1,13 +1,9 @@
package controller package controller
import ( import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
"html/template"
"log" "log"
"net/http"
"time" "time"
) )
@ -38,47 +34,36 @@ func LoginCheckPass(c *gin.Context) {
}) })
return return
} }
case "kefulogin":
info,ok:=CheckKefuPass(username, password)
userinfo:= make(map[string]interface{})
if !ok{
c.JSON(200, gin.H{
"code": 400,
"msg": "验证失败",
})
return
}
userinfo["name"] = info.Name
userinfo["type"] = "kefu"
userinfo["create_time"] = time.Now().Unix()
token, _ := tools.MakeToken(userinfo)
userinfo["ref_token"]=true
refToken, _ := tools.MakeToken(userinfo)
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 400, "code": 200,
"msg": "验证失败", "msg": "验证成功,正在跳转",
"result": gin.H{
"token": token,
"ref_token":refToken,
"create_time":userinfo["create_time"],
},
}) })
} return
}
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")
sessionId := AuthLocal(username, password)
if sessionId != "" {
tools.SetCookie("session_id", sessionId, &w)
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) c.JSON(200, gin.H{
"code": 400,
"msg": "验证失败",
})
} }

@ -17,8 +17,8 @@ func CreateUser(name string,password string){
} }
DB.Create(user) DB.Create(user)
} }
func FindUsers()[]User{ func FindUser(username string)User{
var users []User var user User
DB.Find(&users) DB.Where("name = ?", username).First(&user)
return users return user
} }

@ -43,10 +43,6 @@ func main() {
mux.HandleFunc("/", controller.ActionIndex) mux.HandleFunc("/", controller.ActionIndex)
//邮件夹 //邮件夹
mux.HandleFunc("/list", controller.ActionFolder) mux.HandleFunc("/list", controller.ActionFolder)
//登陆界面
//mux.HandleFunc("/login", controller.ActionLogin)
//验证接口
mux.HandleFunc("/check", controller.LoginCheck)
//邮件夹接口 //邮件夹接口
mux.HandleFunc("/folders", controller.FoldersList) mux.HandleFunc("/folders", controller.FoldersList)
//新邮件夹接口 //新邮件夹接口

@ -53,7 +53,7 @@
<template> <template>
<h1 class="h3 mb-3 font-weight-normal">登录页</h1> <h1 class="h3 mb-3 font-weight-normal">登录页</h1>
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane label="本地认证" name="first"> <el-tab-pane label="管理员登陆" name="first">
<el-form :model="localAuth" :rules="rules" ref="localAuth"> <el-form :model="localAuth" :rules="rules" ref="localAuth">
<el-form-item prop="username"> <el-form-item prop="username">
<el-input v-model="localAuth.username" placeholder="用户名"></el-input> <el-input v-model="localAuth.username" placeholder="用户名"></el-input>
@ -66,35 +66,16 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="IMAP认证" name="second"> <el-tab-pane label="客服登陆" name="second">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm"> <el-form :model="kefuForm" :rules="rules" ref="kefuForm">
<el-form-item prop="server"> <el-form-item prop="username">
<el-input v-model="ruleForm.server" placeholder="IMAP服务器如imap.sina.net:143"></el-input> <el-input v-model="kefuForm.username" placeholder="用户名"></el-input>
</el-form-item>
<el-form-item prop="email">
<el-input v-model="ruleForm.email" placeholder="邮箱地址"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input v-model="ruleForm.password" placeholder="密码"></el-input>
</el-form-item>
<el-form-item>
<el-button :loading="loading" type="primary" @click="submitForm('ruleForm')">IMAP验证</el-button>
</el-form-item>
</el-form>
</el-tab-pane>
<el-tab-pane label="MYSQL认证" name="third">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm">
<el-form-item prop="server">
<el-input v-model="ruleForm.server" placeholder="MYSQL服务地址"></el-input>
</el-form-item>
<el-form-item prop="email">
<el-input v-model="ruleForm.email" placeholder="MYSQL用户名"></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input v-model="ruleForm.password" placeholder="MYSQL密码"></el-input> <el-input v-model="kefuForm.password" placeholder="密码"></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button :loading="loading" type="primary" @click="submitForm('ruleForm')">MYSQL验证</el-button> <el-button :loading="loading" type="primary" @click="kefuLogin('kefuForm')">客服登陆</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-tab-pane> </el-tab-pane>
@ -128,6 +109,10 @@
email:'', email:'',
password:'', password:'',
}, },
kefuForm:{
username:'',
password:'',
},
rules: { rules: {
server: [ server: [
{ required: true, message: 'IMAP服务器如"imap.sina.net:143"包含端口号', trigger: 'blur' }, { required: true, message: 'IMAP服务器如"imap.sina.net:143"包含端口号', trigger: 'blur' },
@ -145,33 +130,36 @@
}, },
methods: { methods: {
//提交表单 //提交表单
submitForm(formName){ kefuLogin(formName){
let _this=this; let _this=this;
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (!valid) {
var data={} return false;
data.server=_this.ruleForm.server; } else {
data.email=_this.ruleForm.email; let data = {};
data.password=_this.ruleForm.password; data.type="kefulogin";
_this.loading=true; data.username = _this.kefuForm.username;
$.post("/check",data,function(data){ data.password = _this.kefuForm.password;
if(data.code==200){ _this.loading = true;
_this.$message({ $.post("/check", data, function (data) {
message: data.msg, if (data.code == 200) {
type: 'success' _this.$message({
}); message: data.msg,
//window.location.href="/"; type: 'success'
}else{ });
_this.$message({ localStorage.setItem("token",data.result.token);
message: data.msg, localStorage.setItem("ref_token",data.result.ref_token);
type: 'error' localStorage.setItem("create_time",data.result.create_time);
}); window.location.href="/main";
} } else {
_this.loading=false; _this.$message({
}); message: data.msg,
} else { type: 'error'
return false; });
} }
_this.loading = false;
});
}
}); });
}, },
//重置表单 //重置表单

@ -128,6 +128,12 @@
_this.mysql.server=data.result.Server; _this.mysql.server=data.result.Server;
_this.mysql.port=data.result.Port; _this.mysql.port=data.result.Port;
} }
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
} }
}); });

Loading…
Cancel
Save