parent
9e481387fb
commit
2596e46821
@ -1,61 +1,33 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"github.com/gin-gonic/gin"
|
||||||
"fmt"
|
"github.com/taoshihan1991/imaptool/models"
|
||||||
"github.com/taoshihan1991/imaptool/config"
|
|
||||||
"github.com/taoshihan1991/imaptool/tmpl"
|
|
||||||
"github.com/taoshihan1991/imaptool/tools"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ActionSetting(w http.ResponseWriter, r *http.Request) {
|
func GetConfigs(c *gin.Context) {
|
||||||
render := tmpl.NewSettingHtml(w)
|
configs:=models.FindConfigs()
|
||||||
render.SetLeft("setting_left")
|
c.JSON(200, gin.H{
|
||||||
render.SetBottom("setting_bottom")
|
"code": 200,
|
||||||
account := config.GetAccount()
|
"msg": "ok",
|
||||||
render.Username = account["Username"]
|
"result":configs,
|
||||||
render.Password = account["Password"]
|
})
|
||||||
render.Display("setting", render)
|
|
||||||
}
|
|
||||||
func SettingAccount(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("content-type", "text/json;charset=utf-8;")
|
|
||||||
|
|
||||||
username := r.PostFormValue("username")
|
|
||||||
password := r.PostFormValue("password")
|
|
||||||
|
|
||||||
isExist, _ := tools.IsFileExist(config.Dir)
|
|
||||||
if !isExist {
|
|
||||||
os.Mkdir(config.Dir, os.ModePerm)
|
|
||||||
}
|
|
||||||
fileConfig := config.AccountConf
|
|
||||||
file, _ := os.OpenFile(fileConfig, os.O_RDWR|os.O_CREATE, os.ModePerm)
|
|
||||||
|
|
||||||
format := `{
|
|
||||||
"Username":"%s",
|
|
||||||
"Password":"%s"
|
|
||||||
}
|
|
||||||
`
|
|
||||||
data := fmt.Sprintf(format, username, password)
|
|
||||||
file.WriteString(data)
|
|
||||||
|
|
||||||
msg, _ := json.Marshal(tools.JsonResult{Code: 200, Msg: "操作成功!"})
|
|
||||||
w.Write(msg)
|
|
||||||
}
|
}
|
||||||
func SettingGetAccount(w http.ResponseWriter, r *http.Request) {
|
func PostConfig(c *gin.Context){
|
||||||
w.Header().Set("content-type", "text/json;charset=utf-8;")
|
key:=c.PostForm("key")
|
||||||
mailServer := tools.GetMailServerFromCookie(r)
|
value:=c.PostForm("value")
|
||||||
|
if key==""||value==""{
|
||||||
if mailServer == nil {
|
c.JSON(200, gin.H{
|
||||||
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"})
|
"code": 400,
|
||||||
w.Write(msg)
|
"msg": "error",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := config.GetAccount()
|
models.UpdateConfig(key,value)
|
||||||
msg, _ := json.Marshal(tools.JsonListResult{
|
|
||||||
JsonResult: tools.JsonResult{Code: 200, Msg: "获取成功"},
|
c.JSON(200, gin.H{
|
||||||
Result: result,
|
"code": 200,
|
||||||
|
"msg": "ok",
|
||||||
|
"result":"",
|
||||||
})
|
})
|
||||||
w.Write(msg)
|
|
||||||
}
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
{{template "header" }}
|
||||||
|
<div id="app" style="width:100%">
|
||||||
|
<template>
|
||||||
|
<el-container v-loading.fullscreen.lock="fullscreenLoading">
|
||||||
|
{{template "setting_left" .}}
|
||||||
|
|
||||||
|
<el-main class="mainMain">
|
||||||
|
|
||||||
|
<el-table
|
||||||
|
:data="configList"
|
||||||
|
border
|
||||||
|
style="width: 100%">
|
||||||
|
<el-table-column
|
||||||
|
prop="conf_name"
|
||||||
|
label="配置参数">
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
prop="conf_key"
|
||||||
|
label="配置key">
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
prop="id"
|
||||||
|
label="操作">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-input @change="setConfigItem(scope.row.conf_key,scope.row.conf_value)" v-model="scope.row.conf_value"></el-input>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-main>
|
||||||
|
|
||||||
|
</el-container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
{{template "setting_bottom" .}}
|
Loading…
Reference in new issue