parent
df43420cd1
commit
750fbdf96d
@ -1,17 +1,34 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/taoshihan1991/imaptool/tmpl"
|
"github.com/taoshihan1991/imaptool/tmpl"
|
||||||
"github.com/taoshihan1991/imaptool/tools"
|
"github.com/taoshihan1991/imaptool/tools"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
func ActionMain(w http.ResponseWriter, r *http.Request){
|
|
||||||
sessionId:=tools.GetCookie(r,"session_id")
|
func ActionMain(w http.ResponseWriter, r *http.Request) {
|
||||||
info:=AuthCheck(sessionId)
|
sessionId := tools.GetCookie(r, "session_id")
|
||||||
if len(info)==0{
|
info := AuthCheck(sessionId)
|
||||||
|
if len(info) == 0 {
|
||||||
http.Redirect(w, r, "/login", 302)
|
http.Redirect(w, r, "/login", 302)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
render:=tmpl.NewRender(w)
|
render := tmpl.NewRender(w)
|
||||||
render.Display("main",render)
|
render.Display("main", render)
|
||||||
|
}
|
||||||
|
func MainCheckAuth(c *gin.Context) {
|
||||||
|
token := c.Query("token")
|
||||||
|
r := CheckAuth(token)
|
||||||
|
if !r {
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 400,
|
||||||
|
"msg": "验证失败",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 200,
|
||||||
|
"msg": "验证成功",
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,55 @@
|
|||||||
package tmpl
|
package tmpl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/taoshihan1991/imaptool/tools"
|
"github.com/taoshihan1991/imaptool/tools"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommonHtml struct{
|
type CommonHtml struct {
|
||||||
Header template.HTML
|
Header template.HTML
|
||||||
Nav template.HTML
|
Nav template.HTML
|
||||||
Left template.HTML
|
Left template.HTML
|
||||||
Bottom template.HTML
|
Bottom template.HTML
|
||||||
Rw http.ResponseWriter
|
Rw http.ResponseWriter
|
||||||
}
|
}
|
||||||
func NewRender(rw http.ResponseWriter)*CommonHtml{
|
|
||||||
obj:=new(CommonHtml)
|
func NewRender(rw http.ResponseWriter) *CommonHtml {
|
||||||
obj.Rw=rw
|
obj := new(CommonHtml)
|
||||||
|
obj.Rw = rw
|
||||||
header := tools.FileGetContent("html/header.html")
|
header := tools.FileGetContent("html/header.html")
|
||||||
nav := tools.FileGetContent("html/nav.html")
|
nav := tools.FileGetContent("html/nav.html")
|
||||||
obj.Header=template.HTML(header)
|
obj.Header = template.HTML(header)
|
||||||
obj.Nav=template.HTML(nav)
|
obj.Nav = template.HTML(nav)
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
func (obj *CommonHtml)SetLeft(file string){
|
func (obj *CommonHtml) SetLeft(file string) {
|
||||||
leftStr := tools.FileGetContent("html/"+file+".html")
|
leftStr := tools.FileGetContent("html/" + file + ".html")
|
||||||
obj.Left=template.HTML(leftStr)
|
obj.Left = template.HTML(leftStr)
|
||||||
}
|
}
|
||||||
func (obj *CommonHtml)SetBottom(file string){
|
func (obj *CommonHtml) SetBottom(file string) {
|
||||||
str := tools.FileGetContent("html/"+file+".html")
|
str := tools.FileGetContent("html/" + file + ".html")
|
||||||
obj.Bottom=template.HTML(str)
|
obj.Bottom = template.HTML(str)
|
||||||
}
|
}
|
||||||
func (obj *CommonHtml)Display(file string,data interface{}){
|
func (obj *CommonHtml) Display(file string, data interface{}) {
|
||||||
if data==nil{
|
if data == nil {
|
||||||
data=obj
|
data = obj
|
||||||
}
|
}
|
||||||
main := tools.FileGetContent("html/"+file+".html")
|
main := tools.FileGetContent("html/" + file + ".html")
|
||||||
t, _ := template.New(file).Parse(main)
|
t, _ := template.New(file).Parse(main)
|
||||||
t.Execute(obj.Rw, data)
|
t.Execute(obj.Rw, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//登陆界面
|
||||||
|
func PageMain(c *gin.Context) {
|
||||||
|
nav := tools.FileGetContent("html/nav.html")
|
||||||
|
c.HTML(http.StatusOK, "main.html", gin.H{
|
||||||
|
"Nav": template.HTML(nav),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//客服界面
|
||||||
|
func PageChatMain(c *gin.Context) {
|
||||||
|
c.HTML(http.StatusOK, "chat_main.html", nil)
|
||||||
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dgrijalva/jwt-go"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const SECRET = "taoshihan"
|
||||||
|
|
||||||
|
func MakeToken(obj map[string]interface{}) (string, error) {
|
||||||
|
obj["time"] = time.Now().Unix()
|
||||||
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims(obj))
|
||||||
|
tokenString, err := token.SignedString([]byte(SECRET))
|
||||||
|
return tokenString, err
|
||||||
|
}
|
||||||
|
func ParseToken(tokenStr string) map[string]interface{} {
|
||||||
|
token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (i interface{}, e error) {
|
||||||
|
return []byte(SECRET), nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
finToken := token.Claims.(jwt.MapClaims)
|
||||||
|
return finToken
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package session
|
package session
|
||||||
|
|
||||||
func Set(name string,value string){
|
func Set(name string, value string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
func Get(name string){
|
func Get(name string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue