parent
df43420cd1
commit
750fbdf96d
@ -1,17 +1,34 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/taoshihan1991/imaptool/tmpl"
|
||||
"github.com/taoshihan1991/imaptool/tools"
|
||||
"net/http"
|
||||
)
|
||||
func ActionMain(w http.ResponseWriter, r *http.Request){
|
||||
sessionId:=tools.GetCookie(r,"session_id")
|
||||
info:=AuthCheck(sessionId)
|
||||
if len(info)==0{
|
||||
|
||||
func ActionMain(w http.ResponseWriter, r *http.Request) {
|
||||
sessionId := tools.GetCookie(r, "session_id")
|
||||
info := AuthCheck(sessionId)
|
||||
if len(info) == 0 {
|
||||
http.Redirect(w, r, "/login", 302)
|
||||
return
|
||||
}
|
||||
render:=tmpl.NewRender(w)
|
||||
render.Display("main",render)
|
||||
render := tmpl.NewRender(w)
|
||||
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
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/taoshihan1991/imaptool/tools"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type CommonHtml struct{
|
||||
Header template.HTML
|
||||
Nav template.HTML
|
||||
Left template.HTML
|
||||
Bottom template.HTML
|
||||
Rw http.ResponseWriter
|
||||
type CommonHtml struct {
|
||||
Header template.HTML
|
||||
Nav template.HTML
|
||||
Left template.HTML
|
||||
Bottom template.HTML
|
||||
Rw http.ResponseWriter
|
||||
}
|
||||
func NewRender(rw http.ResponseWriter)*CommonHtml{
|
||||
obj:=new(CommonHtml)
|
||||
obj.Rw=rw
|
||||
|
||||
func NewRender(rw http.ResponseWriter) *CommonHtml {
|
||||
obj := new(CommonHtml)
|
||||
obj.Rw = rw
|
||||
header := tools.FileGetContent("html/header.html")
|
||||
nav := tools.FileGetContent("html/nav.html")
|
||||
obj.Header=template.HTML(header)
|
||||
obj.Nav=template.HTML(nav)
|
||||
obj.Header = template.HTML(header)
|
||||
obj.Nav = template.HTML(nav)
|
||||
return obj
|
||||
}
|
||||
func (obj *CommonHtml)SetLeft(file string){
|
||||
leftStr := tools.FileGetContent("html/"+file+".html")
|
||||
obj.Left=template.HTML(leftStr)
|
||||
func (obj *CommonHtml) SetLeft(file string) {
|
||||
leftStr := tools.FileGetContent("html/" + file + ".html")
|
||||
obj.Left = template.HTML(leftStr)
|
||||
}
|
||||
func (obj *CommonHtml)SetBottom(file string){
|
||||
str := tools.FileGetContent("html/"+file+".html")
|
||||
obj.Bottom=template.HTML(str)
|
||||
func (obj *CommonHtml) SetBottom(file string) {
|
||||
str := tools.FileGetContent("html/" + file + ".html")
|
||||
obj.Bottom = template.HTML(str)
|
||||
}
|
||||
func (obj *CommonHtml)Display(file string,data interface{}){
|
||||
if data==nil{
|
||||
data=obj
|
||||
func (obj *CommonHtml) Display(file string, data interface{}) {
|
||||
if data == nil {
|
||||
data = obj
|
||||
}
|
||||
main := tools.FileGetContent("html/"+file+".html")
|
||||
main := tools.FileGetContent("html/" + file + ".html")
|
||||
t, _ := template.New(file).Parse(main)
|
||||
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
|
||||
|
||||
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