Beispiel #1
0
// 检查会员令牌信息
func checkMemberToken(ctx *echo.Context) bool {
	r := ctx.Request()
	sto := gof.CurrentApp.Storage()
	memberId, _ := strconv.Atoi(r.FormValue("member_id"))
	token := r.FormValue("member_token")

	if util.CompareMemberApiToken(sto, memberId, token) {
		ctx.Set("member_id", memberId)
		return true
	}
	return false
}
Beispiel #2
0
// member auth,command like 'MAUTH:jarrysix#3234234242342342'
func memberAuth(s *nc.SocketServer, id *nc.Client, param string) ([]byte, error) {
	var err error
	arr := strings.Split(param, "#")
	if len(arr) == 2 {

		f := func() (int, error) {
			memberId, _ := strconv.Atoi(arr[0])
			authOk := util.CompareMemberApiToken(gof.CurrentApp.Storage(),
				memberId, arr[1])
			if !authOk {
				return memberId, errors.New("auth fail")
			}
			return memberId, nil
		}

		if err = s.UAuth(id.Conn, f); err == nil { //验证成功
			return []byte("ok"), nil
		}
	}
	return nil, err
}