This commit is contained in:
henry
2021-11-24 09:59:29 +08:00
parent cf91d55ab2
commit f007168919
21 changed files with 360 additions and 93 deletions

View File

@ -3,7 +3,6 @@ package api
import (
account2 "SciencesServer/app/api/enterprise/controller/account"
"SciencesServer/app/basic/api"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
@ -12,7 +11,7 @@ type Account struct{}
type (
accountLoginForm struct {
Mode int `json:"mode" form:"mode" binding:"required"`
Mobile string `json:"mobile" form:"mobile"`
Account string `json:"account" form:"account"`
Captcha string `json:"captcha" form:"captcha"`
Password string `json:"password" form:"password"`
}
@ -37,11 +36,11 @@ func (a *Account) Login(c *gin.Context) {
Captcha: struct {
Mobile string
Captcha string
}{Mobile: form.Mobile, Captcha: form.Captcha},
}{Mobile: form.Account, Captcha: form.Captcha},
Password: struct {
Mobile string
Account string
Password string
}{Mobile: form.Mobile, Password: form.Password},
}{Account: form.Account, Password: form.Password},
})
api.APIResponse(err, data)(c)
}
@ -60,18 +59,20 @@ func (a *Account) Register(c *gin.Context) {
api.APIResponse(err, data)(c)
}
func (a *Account) BindMobile(c *gin.Context) {
func (*Account) Authorize(c *gin.Context) {
}
func (*Account) BindMobile(c *gin.Context) {
//account.NewOther()().BindMobile()
}
func (a *Account) Logout(c *gin.Context) {
handle := api.GetSession()(c)
func (*Account) Logout(c *gin.Context) {
// 因跳过中间键故只能自己去获取token用户信息
//token := c.GetHeader(config.APIRequestToken)
session := new(service.SessionEnterprise)
//session, _ := service.NewAuthToken(token).Auth()
if handle != nil {
session = handle.(*service.SessionEnterprise)
}
err := account2.NewLogout()(session).Launch()
err := account2.NewLogout()(nil).Launch()
api.APIResponse(err)(c)
}

View File

@ -20,7 +20,7 @@ type (
Mobile, Captcha string
}
Password struct {
Mobile, Password string
Account, Password string
}
Platform struct {
OpenID string
@ -88,13 +88,13 @@ RETURNS:
// loginForPassword 密码登陆
func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams, error) {
if !utils.ValidateMobile(params.Password.Mobile) {
if !utils.ValidateMobile(params.Password.Account) {
return nil, errors.New("手机号码格式异常")
}
mUserInstance := model3.NewUserInstance()
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
model2.NewWhere("mobile", params.Password.Mobile), model2.NewWhere("local", local))
model2.NewWhere("mobile", params.Password.Account), model2.NewWhere("local", local))
if err != nil {
return nil, err

View File

@ -13,7 +13,7 @@ type Logout struct {
type LogoutHandle func(enterprise *service.SessionEnterprise) *Logout
func (c *Logout) Launch() error {
if c.UID > 0 {
if c.SessionEnterprise != nil && c.UID > 0 {
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
}
return nil

View File

@ -62,6 +62,7 @@ func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error)
return nil, errors.New("当前手机号码已注册")
}
mUserInstance.Local.Local = c.local
mUserInstance.Source = model2.UserInstanceSourceForLocal
mUserInstance.Password = utils.GetRandomString(12)
mUserInstance.Mobile = params.Mobile
mUserInstance.Password = params.Password

View File

@ -24,7 +24,7 @@ type (
// Expert 专家数据
func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserManageForExpert, error) {
query := orm.GetDB().Table(m.TableName()+" AS m").
db := orm.GetDB().Table(m.TableName()+" AS m").
Select(strings.Join([]string{"m.id", "m.name", "u.mobile", "m.identity_info"}, ",")).
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON m.uid = u.uuid", model.NewUserInstance().TableName())).
Where("m.is_deleted = ?", model.DeleteStatusForNot).
@ -34,13 +34,13 @@ func (m *UserManage) Expert(page, pageSize int, count *int64, where ...*model.Mo
if len(where) > 0 {
for _, v := range where {
query = query.Where(v.Condition, v.Value)
db = db.Where(v.Condition, v.Value)
}
}
if err := query.Count(count).Error; err != nil {
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := query.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
if err := db.Order("m.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil

View File

@ -3,6 +3,7 @@ package api
import (
"SciencesServer/app/api/manage/controller"
"SciencesServer/app/service"
"SciencesServer/config"
"github.com/gin-gonic/gin"
)
@ -77,13 +78,11 @@ func (a *Account) Login(c *gin.Context) {
* }
*/
func (a *Account) Logout(c *gin.Context) {
handle := getSession()(c)
// 因跳过中间键故只能自己去获取token用户信息
token := c.GetHeader(config.APIRequestToken)
session := new(service.Session)
session, _ := service.NewAuthToken(token).Auth()
if handle != nil {
session = handle.(*service.Session)
}
err := controller.NewAccount()(session).Logout()
APIResponse(err)(c)
}

View File

@ -1,7 +1,9 @@
package api
import (
"SciencesServer/app/api/manage/controller/manage"
"SciencesServer/app/basic/api"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
@ -11,7 +13,26 @@ func (*Manage) Company(c *gin.Context) {
}
func (*Manage) CompanyExamine(c *gin.Context) {
}
func (*Manage) Expert(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Status int `json:"status" form:"status"`
api.PageForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := manage.NewInstance()(api.GetSession()(c).(*service.Session), api.GetLocal()(c).(string)).
Expert(form.Name, form.Status, form.Page, form.PageSize)
api.APIResponse(err, data)
}
func (*Manage) ExpertExamine(c *gin.Context) {
}
@ -27,9 +48,13 @@ func (*Menu) Examine(c *gin.Context) {
form := &struct {
api.IDStringForm
Identity int `json:"identity" form:"identity" binding:"required"`
Status int `json:"status" form:"status" binding:"required"`
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := manage.NewExamine()(api.GetSession()(c).(*service.Session), api.GetLocal()(c).(string)).
Launch(form.Convert(), form.Identity, form.Status)
api.APIResponse(err)
}

View File

@ -57,7 +57,9 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
// Logout 退出请求
func (c *Account) Logout() error {
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
if c.Session != nil && c.UID > 0 {
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
}
return nil
}

View File

@ -28,8 +28,10 @@ type ExamineManageInfo struct {
// examineHandle 审核处理
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
config.TenantUserIdentityForCompany: examineCompany,
config.TenantUserIdentityForExpert: examineExpert,
config.TenantUserIdentityForCompany: examineCompany,
config.TenantUserIdentityForExpert: examineExpert,
config.TenantUserIdentityForResearch: examineResearch,
config.TenantUserIdentityForLaboratory: examineLaboratory,
}
func checkManage(IModel model2.IModel, id uint64) error {
@ -56,7 +58,7 @@ func examineCompany(id uint64) (*ExamineManageInfo, error) {
return &ExamineManageInfo{
IModel: mManageCompany.ManageCompany, UID: mManageCompany.UID,
IdentityInfo: &model2.UserIdentityForCompany{
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword,
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword, CreatedAt: time.Now(),
},
}, nil
}
@ -75,6 +77,45 @@ func examineExpert(id uint64) (*ExamineManageInfo, error) {
IModel: mManageExpert.ManageExpert, UID: mManageExpert.UID,
IdentityInfo: &model2.UserIdentityForExpert{
Industry: mManageExpert.Industry, Keyword: mManageExpert.Keyword, Research: mManageExpert.Research,
CreatedAt: time.Now(),
},
}, nil
}
func examineResearch(id uint64) (*ExamineManageInfo, error) {
mManageResearch := model.NewManageResearch()
err := checkManage(mManageResearch.ManageResearch, id)
if err != nil {
return nil, err
} else if mManageResearch.Status != model2.ExamineStatusForOngoing {
return nil, errors.New("当前入住信息已审核")
}
return &ExamineManageInfo{
IModel: mManageResearch.ManageResearch, UID: mManageResearch.UID,
IdentityInfo: &model2.UserIdentityForResearch{
Name: mManageResearch.Name, Industry: mManageResearch.Industry, Keyword: mManageResearch.Keyword,
Research: mManageResearch.Research, CreatedAt: time.Now(),
},
}, nil
}
func examineLaboratory(id uint64) (*ExamineManageInfo, error) {
mManageLaboratory := model.NewManageLaboratory()
err := checkManage(mManageLaboratory.ManageLaboratory, id)
if err != nil {
return nil, err
} else if mManageLaboratory.Status != model2.ExamineStatusForOngoing {
return nil, errors.New("当前入住信息已审核")
}
return &ExamineManageInfo{
IModel: mManageLaboratory.ManageLaboratory, UID: mManageLaboratory.UID,
IdentityInfo: &model2.UserIdentityForLaboratory{
Name: mManageLaboratory.Name, Industry: mManageLaboratory.Industry, Keyword: mManageLaboratory.Keyword,
Research: mManageLaboratory.Research, CreatedAt: time.Now(),
},
}, nil
}
@ -96,7 +137,6 @@ func (c *Examine) Launch(id uint64, identity, status int) error {
if err != nil {
return err
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
if err = model2.Updates(data.IModel, map[string]interface{}{
"status": status, "updated_at": time.Now(),

View File

@ -1,14 +1,91 @@
package manage
import "SciencesServer/app/service"
import (
"SciencesServer/app/api/manage/controller"
"SciencesServer/app/api/manage/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
"gorm.io/gorm"
"strings"
"time"
)
type Instance struct {
*service.Session
gorm.Model
local string
}
type InstanceHandle func(session *service.Session, local string) *Instance
type (
// InstanceForExpert 专家信息
InstanceForExpert struct {
ID string `json:"id"`
Name string `json:"name"`
Industry []string `json:"industry"`
ResearchName string `json:"research_name"`
LaboratoryName string `json:"laboratory_name"`
Address string `json:"address"`
CreatedAt time.Time `json:"created_at"`
}
)
func (c *Instance) Company(name string, status int, page, pageSize int) {
mManageCompany := model.NewManageCompany()
where := make([]*model2.ModelWhere, 0)
if name != "" {
where = append(where, model2.NewWhereLike("name", name))
}
var count int64
mManageCompany.Companys(page, pageSize, &count)
}
// Expert 专家信息
func (c *Instance) Expert(name string, status int, page, pageSize int) (*controller.ReturnPages, error) {
mManageExpert := model.NewManageExpert()
where := make([]*model2.ModelWhere, 0)
if name != "" {
where = append(where, model2.NewWhereLike("name", name))
}
var count int64
out, err := mManageExpert.Experts(page, pageSize, &count, where...)
if err != nil {
return nil, err
}
list := make([]*InstanceForExpert, 0)
for _, v := range out {
industry := make([]string, 0)
for _, v := range strings.Split(v.Industry, ";") {
industry = append(industry, config.GetIndustryInfo(v, "-"))
}
// 研究机构,实验室
researchName := v.LaboratoryName
laboratoryName := ""
if v.LaboratoryName != "" {
researchName = v.ResearchName
laboratoryName = v.LaboratoryName
}
list = append(list, &InstanceForExpert{ID: v.GetEncodeID(), Name: v.Name, Industry: industry,
ResearchName: researchName, LaboratoryName: laboratoryName,
Address: v.FormatBasic(), CreatedAt: v.CreatedAt,
})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
func NewInstance() InstanceHandle {
return func(session *service.Session, local string) *Instance {
return &Instance{

View File

@ -1,11 +1,17 @@
package model
import "SciencesServer/app/common/model"
import (
"SciencesServer/app/common/model"
)
type ManageCompany struct {
*model.ManageCompany
}
func (m *ManageCompany) Companys(page, pageSize int, count *int64, where ...*model.ModelWhere) {
}
func NewManageCompany() *ManageCompany {
return &ManageCompany{}
}

View File

@ -1,11 +1,50 @@
package model
import "SciencesServer/app/common/model"
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type ManageExpert struct {
*model.ManageExpert
}
type ManageExpertInfo struct {
*model.ManageExpert
Name string `json:"name"`
ResearchName string `json:"research_name"`
LaboratoryName string `json:"laboratory_name"`
}
// Experts 专家信息
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
mUserInstance := model.NewUserInstance()
mSysTenant := model.NewSysTenant()
db := orm.GetDB().Table(m.TableName()+" AS e").
Select("e.*", "u.name", "l.name AS laboratory_name", "r.name AS research_name").
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON e.uid = u.uuid", mUserInstance.TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.tenant_id = l.id", mSysTenant.TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.parent_id = r.id", mSysTenant.TableName())).
Where("")
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
out := make([]*ManageExpertInfo, 0)
if err := db.Count(count).Error; err != nil {
return nil, err
}
if err := db.Order("e.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewManageExpert() *ManageExpert {
return &ManageExpert{model.NewManageExpert()}
}

View File

@ -21,7 +21,6 @@ type (
Job string `json:"job" form:"job"`
Title string `json:"title" form:"title"`
WorkAt string `json:"work_at" form:"work_at"`
Keyword string `json:"keyword" form:"keyword"`
Research string `json:"research" form:"research"` // 研究方向
}
// IdentityForResearch 研究机构
@ -32,9 +31,9 @@ type (
}
// IdentityForLaboratory 实验室
IdentityForLaboratory struct {
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
Longitude float64 `json:"longitude" form:"longitude"` // 经度
Latitude float64 `json:"latitude" form:"latitude"` // 纬度
Research map[int]string `json:"research" form:"research"` // 研究领域方向
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
Longitude float64 `json:"longitude" form:"longitude"` // 经度
Latitude float64 `json:"latitude" form:"latitude"` // 纬度
Research string `json:"research" form:"research"` // 研究领域方向
}
)

View File

@ -1,7 +1,9 @@
package model
import (
"SciencesServer/config"
"SciencesServer/utils"
"strings"
)
type Gender struct {
@ -108,6 +110,23 @@ type Area struct {
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
}
func (m *Area) FormatBasic() string {
address := make([]string, 0)
address = append(address, config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province])
if m.City != "" {
address = append(address, config.SettingAreaInfo[m.Province][m.City])
}
if m.District != "" {
address = append(address, config.SettingAreaInfo[m.City][m.District])
}
return strings.Join(address, "-")
}
func (m *Area) FormatDetail() string {
return m.FormatBasic() + "" + m.Address
}
// Position 坐标信息
type Position struct {
Longitude float64 `json:"longitude"` // 经度

View File

@ -10,23 +10,34 @@ import (
type UserInstance struct {
Model
Local
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
UUID uint64 `gorm:"column:-;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
Source UserInstanceSource `gorm:"column:source;type:tinyint(1);default:1;comment:账号来源" json:"source"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
AccountStatus
ModelDeleted
ModelAt
}
// UserInstanceSource 账号来源
type UserInstanceSource int
const (
// UserInstanceSourceForLocal 本地注册
UserInstanceSourceForLocal UserInstanceSource = iota + 1
// UserInstanceSourceForWechat 微信登陆
UserInstanceSourceForWechat
)
func (m *UserInstance) TableName() string {
return "user_instance"
}
func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
m.NewPassword()
m.SetPasswordAttribute()
snowflake, _ := utils.NewSnowflake(1)
m.UUID = uint64(snowflake.GetID())
m.Status = AccountStatusForEnable
@ -34,7 +45,7 @@ func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
return nil
}
func (m *UserInstance) NewPassword() {
func (m *UserInstance) SetPasswordAttribute() {
m.Salt = utils.GetRandomString(8)
m.Password = utils.HashString([]byte(utils.Md5String(m.Password, m.Salt)))
}

View File

@ -32,14 +32,32 @@ type IUserIdentity interface {
type (
// UserIdentityForCompany 公司信息
UserIdentityForCompany struct {
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
CreatedAt time.Time `json:"created_at"`
}
// UserIdentityForExpert 专家信息
UserIdentityForExpert struct {
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
CreatedAt time.Time `json:"created_at"`
}
// UserIdentityForResearch 研究机构信息
UserIdentityForResearch struct {
Name string `json:"name"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
CreatedAt time.Time `json:"created_at"`
}
// UserIdentityForLaboratory 实验室信息
UserIdentityForLaboratory struct {
Name string `json:"name"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
CreatedAt time.Time `json:"created_at"`
}
)
@ -53,6 +71,16 @@ func (this *UserIdentityForExpert) Analysis(src string) interface{} {
return this
}
func (this *UserIdentityForResearch) Analysis(src string) interface{} {
utils.FromJSON(src, this)
return this
}
func (this *UserIdentityForLaboratory) Analysis(src string) interface{} {
utils.FromJSON(src, this)
return this
}
type UserManageSelected int
const (

47
app/service/authToken.go Normal file
View File

@ -0,0 +1,47 @@
package service
import (
"SciencesServer/config"
cache2 "SciencesServer/serve/cache"
"SciencesServer/utils"
"errors"
"fmt"
"time"
)
type AuthToken struct {
Token string `json:"token"`
}
func (this *AuthToken) Auth() (*Session, error) {
tokenInfo := utils.JWTDecrypt(this.Token)
if tokenInfo == nil || len(tokenInfo) <= 0 {
return nil, errors.New("Token无效")
}
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
expTime := time.Unix(expTimestamp, 0)
ok := expTime.After(time.Now())
if !ok {
return nil, errors.New("Token过期")
}
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
if cache == "" {
return nil, errors.New("用户未登录或已退出")
}
session := new(Session)
_ = session.UnmarshalBinary([]byte(cache))
if !config.SettingInfo.MultipleLogin && session.Token != this.Token {
return nil, errors.New("登录失效,已在其他地方登录!")
}
return session, nil
}
func NewAuthToken(token string) *AuthToken {
return &AuthToken{
Token: token,
}
}

View File

@ -68,4 +68,4 @@ upload:
log:
file: log/logs.log
least_day: 7
level: info # debug | info | warn | error
level: debug # debug | info | warn | error

View File

@ -11,6 +11,7 @@ import (
func registerAPI(app *gin.Engine) {
apiPrefix := "/api"
g := app.Group(apiPrefix)
// 登录验证
g.Use(NeedLogin(AddSkipperURL([]string{
apiPrefix + "/captcha",

View File

@ -4,13 +4,9 @@ import (
"SciencesServer/app/service"
"SciencesServer/config"
"SciencesServer/serve/cache"
cache2 "SciencesServer/serve/cache"
"SciencesServer/utils"
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
"net/http"
)
// SkipperURL 跳过验证
@ -41,34 +37,10 @@ func NeedLogin(skipperURL ...SkipperURL) gin.HandlerFunc {
c.Abort()
return
}
tokenInfo := utils.JWTDecrypt(token)
session, err := service.NewAuthToken(token).Auth()
if tokenInfo == nil || len(tokenInfo) <= 0 {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Token无效"})
c.Abort()
return
}
expTimestamp := utils.StringToInt64(fmt.Sprintf("%v", tokenInfo["exp"]))
expTime := time.Unix(expTimestamp, 0)
ok := expTime.After(time.Now())
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"message": "Token过期"})
c.Abort()
return
}
cache, _ := cache2.Cache.HGet(config.RedisKeyForAccount, fmt.Sprintf("%v", tokenInfo[config.TokenForUID]))
if cache == "" {
c.JSON(http.StatusUnauthorized, gin.H{"message": "用户未登录或已退出"})
c.Abort()
return
}
session := new(service.Session)
_ = session.UnmarshalBinary([]byte(cache))
if !config.SettingInfo.MultipleLogin && session.Token != token {
c.JSON(http.StatusUnauthorized, gin.H{"message": "登录失效,已在其他地方登录!"})
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"message": err.Error()})
c.Abort()
return
}

View File

@ -42,18 +42,18 @@ func (this *Logger) Load() {
func (this *Logger) Init(option *Option) *Logger {
this.Option = option
logger = log.New()
logger.SetFormatter(&log.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
logger.SetReportCaller(true)
logger.AddHook(NewHook(this.File, 0, this.LeastDay))
_logger := log.New()
_logger.SetFormatter(&log.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
_logger.SetReportCaller(true)
_logger.AddHook(NewHook(this.File, 0, this.LeastDay))
if this.IsStdout {
logger.SetOutput(io.MultiWriter(os.Stdout))
_logger.SetOutput(io.MultiWriter(os.Stdout))
}
logger.SetFormatter(formatter(true))
logger.SetLevel(this.level())
_logger.SetFormatter(formatter(true))
_logger.SetLevel(this.level())
this.Logger = logger
this.Logger = _logger
return this
}