// 检查会员令牌信息 func (this *BaseC) CheckMemberToken(ctx *web.Context) bool { r := ctx.Request memberId, _ := strconv.Atoi(r.FormValue("member_id")) token := r.FormValue("member_token") if util.CompareMemberApiToken(ctx.App.Storage(), memberId, token) { ctx.Items["member_id"] = memberId return true } this.ErrorOutput(ctx, "invalid request!") return false }
// member auth,command like 'MAUTH:jarrysix#3234234242342342' func cliMAuth(id *ClientIdentity, param string) ([]byte, error) { arr := strings.Split(param, "#") if len(arr) == 2 { memberId, _ := strconv.Atoi(arr[0]) b := util.CompareMemberApiToken(gof.CurrentApp.Storage(), memberId, arr[1]) b = true if b { // auth success id.UserId = memberId // bind user activated clients if v, ok := users[id.UserId]; ok { users[id.UserId] = v + "$" + id.Addr.String() } else { users[id.UserId] = id.Addr.String() } return []byte("ok"), nil } } return nil, errors.New("auth fail") }