互动
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.

88 lines
1.9 KiB

package ws
import (
"fmt"
"hudongzhuanjia/models"
)
func init() {
N.SetMiddleware(LogicLogin, LoginMid)
}
func LoginMid(c *Client, msg *Message) {
var token string
var ok bool
if token, ok = msg.Data["token"].(string); !ok || token == "" {
_ = c.WriteJson(map[string]interface{}{
"msg": "token不能为空",
"code": 506,
})
return
}
_type, id, err := models.ParseToken(token)
if err != nil {
c.WriteJson(map[string]interface{}{
"msg": "token失效",
"code": 507,
})
return
}
c.Online = true
c.AccountId = id
c.AccountType = _type
c.Id = fmt.Sprintf("%s:%d", c.AccountType, c.AccountId)
//claims, err := ParseAccessToken(msg.Data["token"].(string))
//if err != nil {
// _ = c.WriteJson(map[string]interface{}{
// "msg": "token解析出错, " + err.Error(),
// "code": 507,
// })
// return
//}
//c.Online = true
//c.Id = fmt.Sprintf("%s:%d", claims.AccountType, claims.AccountId)
//c.AccountId = claims.AccountId
//c.AccountType = claims.AccountType
//c.Pid = claims.CustomerPid
if err = c.Register(); err != nil {
_ = c.WriteJson(map[string]interface{}{
"msg": err.Error(),
"code": 404,
})
return
}
//
//if claims.AccountType == IDCustomer {
// if c.Pid == 0 { // 主账号发给子账号
// m := &Message{
// Type: TypeNotice,
// Dest: 0,
// Tag: IDCustomer,
// RoomId: c.RoomId,
// From: c.Id,
// Data: map[string]interface{}{
// "content": "主账号上线",
// },
// }
// c.Send(m)
// } else { // 子账号发给主账号
// m := &Message{
// Type: TypeNotice,
// Dest: claims.CustomerPid,
// Tag: IDCustomer,
// RoomId: c.RoomId,
// From: c.Id,
// Data: map[string]interface{}{
// "content": "子账号上线",
// },
// }
// c.Send(m)
// }
//}
_ = c.WriteJson(map[string]interface{}{
"msg": "登录成功",
"code": 200,
})
}