parent
2c1fae79b7
commit
5b5ff2c779
@ -1,11 +1,84 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/taoshihan1991/imaptool/tmpl"
|
||||
"github.com/taoshihan1991/imaptool/tools"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
const configDir = "config/"
|
||||
const configFile=configDir+"account.json"
|
||||
func ActionSetting(w http.ResponseWriter, r *http.Request){
|
||||
render:=tmpl.NewRender(w)
|
||||
render:=tmpl.NewSettingHtml(w)
|
||||
render.SetLeft("setting_left")
|
||||
render.SetBottom("setting_bottom")
|
||||
account:=getAccount()
|
||||
render.Username=account["Username"]
|
||||
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;")
|
||||
mailServer := tools.GetMailServerFromCookie(r)
|
||||
|
||||
if mailServer == nil {
|
||||
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"})
|
||||
w.Write(msg)
|
||||
return
|
||||
}
|
||||
|
||||
username:=r.PostFormValue("username")
|
||||
password:=r.PostFormValue("password")
|
||||
|
||||
isExist,_:=tools.IsFileExist(configDir)
|
||||
if !isExist{
|
||||
os.Mkdir(configDir,os.ModePerm)
|
||||
}
|
||||
fileConfig:=configFile
|
||||
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){
|
||||
w.Header().Set("content-type", "text/json;charset=utf-8;")
|
||||
mailServer := tools.GetMailServerFromCookie(r)
|
||||
|
||||
if mailServer == nil {
|
||||
msg, _ := json.Marshal(tools.JsonResult{Code: 400, Msg: "验证失败"})
|
||||
w.Write(msg)
|
||||
return
|
||||
}
|
||||
result:=getAccount()
|
||||
msg, _ := json.Marshal(tools.JsonListResult{
|
||||
JsonResult: tools.JsonResult{Code: 200, Msg: "获取成功"},
|
||||
Result: result,
|
||||
})
|
||||
w.Write(msg)
|
||||
}
|
||||
func getAccount()map[string]string{
|
||||
var account map[string]string
|
||||
isExist,_:=tools.IsFileExist(configFile)
|
||||
if !isExist{
|
||||
return account
|
||||
}
|
||||
info,err:=ioutil.ReadFile(configFile)
|
||||
if err!=nil{
|
||||
return account
|
||||
}
|
||||
|
||||
err=json.Unmarshal(info,&account)
|
||||
return account
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
<el-menu
|
||||
default-active="4"
|
||||
mode="horizontal">
|
||||
<el-menu-item index="1" class="mainLogo" v-on:click="openIframeUrl('/list')">GO-IMAP</el-menu-item>
|
||||
<el-menu-item index="2" v-on:click="openIframeUrl('/list')">收信<el-badge class="mark" :value="mailTotal" style="margin-bottom: 20px;"/>
|
||||
<el-menu-item class="mainLogo" v-on:click="openUrl('/login')">GO-IMAP</el-menu-item>
|
||||
<el-menu-item index="2" v-on:click="openIframeUrl('/list')">邮箱<el-badge class="mark" :value="mailTotal" style="margin-bottom: 20px;"/>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="3" v-on:click="openIframeUrl('/write')">写信</el-menu-item>
|
||||
<el-menu-item index="4" v-on:click="openIframeUrl('/setting')">设置</el-menu-item>
|
||||
<el-menu-item index="10" v-on:click="openIframeUrl('/logout')">退出</el-menu-item>
|
||||
</el-menu>
|
@ -0,0 +1,14 @@
|
||||
<el-menu default-active="1-3" :default-openeds="openIndex">
|
||||
<el-submenu index="1">
|
||||
<template slot="title">
|
||||
<i class="el-icon-s-custom"></i>
|
||||
<span>账户中心</span>
|
||||
</template>
|
||||
<el-menu-item-group>
|
||||
<el-menu-item index="1-1">设置smtp</el-menu-item>
|
||||
<el-menu-item index="1-2">设置imap</el-menu-item>
|
||||
<el-menu-item index="1-3">设置登陆账号</el-menu-item>
|
||||
<el-menu-item index="1-4" v-on:click="openUrl('/setting_mysql')">设置mysql</el-menu-item>
|
||||
</el-menu-item-group>
|
||||
</el-submenu>
|
||||
</el-menu>
|
@ -0,0 +1,14 @@
|
||||
package tmpl
|
||||
|
||||
import "net/http"
|
||||
|
||||
type SettingHtml struct {
|
||||
*CommonHtml
|
||||
Username,Password string
|
||||
}
|
||||
func NewSettingHtml(w http.ResponseWriter)*SettingHtml{
|
||||
obj:=new(SettingHtml)
|
||||
parent:=NewRender(w)
|
||||
obj.CommonHtml=parent
|
||||
return obj
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package tools
|
||||
|
||||
import "os"
|
||||
|
||||
//判断文件文件夹是否存在
|
||||
func IsFileExist(path string) (bool, error) {
|
||||
fileInfo, err := os.Stat(path)
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
//我这里判断了如果是0也算不存在
|
||||
if fileInfo.Size() == 0 {
|
||||
return false, nil
|
||||
}
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
Loading…
Reference in new issue