You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
package middleware
|
|
|
|
import (
|
|
"base/app/lib/bean"
|
|
"base/app/logic/customer"
|
|
"base/app/model"
|
|
"git.oa00.com/go/mysql"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func CustomerAuth(c *gin.Context) {
|
|
if c.GetHeader("debug") == "true" {
|
|
customer := model.Customer{Id: 1}
|
|
if mysql.Db.First(&customer).Error != nil {
|
|
bean.Response.ResultFail(c, 100000, "账号错误")
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Set("customerId", customer.Id)
|
|
c.Set("customer", customer)
|
|
return
|
|
}
|
|
token := c.GetHeader("Customer-Wxapp-Token")
|
|
if token == "" {
|
|
bean.Response.ResultFail(c, 100000, "用户未登录")
|
|
c.Abort()
|
|
return
|
|
}
|
|
customerId, err := customer.LoginLogic.Auth(token)
|
|
if err != nil {
|
|
bean.Response.ResultFail(c, 100000, err.Error())
|
|
c.Abort()
|
|
return
|
|
}
|
|
customer := model.Customer{Id: customerId}
|
|
if mysql.Db.First(&customer).Error != nil {
|
|
bean.Response.ResultFail(c, 100000, "账号错误")
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Set("customerId", customerId)
|
|
c.Set("customer", customer)
|
|
}
|
|
|
|
func CustomerNoAuth(c *gin.Context) {
|
|
token := c.GetHeader("Customer-Wxapp-Token")
|
|
if token != "" {
|
|
customerId, err := customer.LoginLogic.Auth(token)
|
|
if err != nil {
|
|
//bean.Response.ResultFail(c, 100000, err.Error())
|
|
//c.Abort()
|
|
return
|
|
}
|
|
customer := model.Customer{Id: customerId}
|
|
mysql.Db.First(&customer)
|
|
c.Set("customerId", customerId)
|
|
c.Set("customer", customer)
|
|
}
|
|
}
|