客服登陆接口表结构

pull/30/head
陶士涵 4 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 {
models.FindUsers()
account := config.GetAccount()
if account == nil {
account = make(map[string]string)
@ -27,7 +25,13 @@ func CheckPass(username string, password string) string {
}
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 {
account := config.GetAccount()
if account == nil {

@ -1,13 +1,9 @@
package controller
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/tools"
"html/template"
"log"
"net/http"
"time"
)
@ -38,47 +34,36 @@ func LoginCheckPass(c *gin.Context) {
})
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{
"code": 400,
"msg": "验证失败",
"code": 200,
"msg": "验证成功,正在跳转",
"result": gin.H{
"token": token,
"ref_token":refToken,
"create_time":userinfo["create_time"],
},
})
}
}
func ActionLogin(w http.ResponseWriter, r *http.Request) {
html := tools.FileGetContent("html/login.html")
t, _ := template.New("login").Parse(html)
t.Execute(w, nil)
}
return
//验证接口
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)
}
func FindUsers()[]User{
var users []User
DB.Find(&users)
return users
func FindUser(username string)User{
var user User
DB.Where("name = ?", username).First(&user)
return user
}

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

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

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

Loading…
Cancel
Save