Beispiel #1
0
//key login in
func pid_3(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "UID", "Key") {
		return
	}

	login := cmd.GetString("UID")
	pwd := cmd.GetString("Key")

	loginSuccess := false
	//log.Info("pid -3 uid=key", login, pwd)
	//check session
	if name, key, ok := online.GetSession(login); ok && key == pwd {
		c.Name = name
		c.Key = key
		loginSuccess = true
		//log.Info("get session success", key)
	}

	//check
	re := make(map[string]interface{})
	if loginSuccess {
		c.IsLogin = true
		re["LoginState"] = 0
		re["Message"] = "login success"
		re["UID"] = c.UUID
		re["Key"] = c.Key
	} else {
		re["LoginState"] = -1
		re["Message"] = "login failed"
	}
	online.Set(c)
	writepid(c, cmd, 0, re)
}
Beispiel #2
0
//数据库write操作
func pid4(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "Id", "Param") {
		return
	}
	id := cmd.GetString("Id")
	m := make(map[string]interface{})
	err := rpc.ExecSqlParamName(id, m)
	if err != nil {
		log.Error(err.Error())
		writePrror("db error", cmd, c)
		return
	}
	writepid(c, cmd, 0, nil)
}
Beispiel #3
0
//数据库read操作
func pid3(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "Id", "Param") {
		return
	}
	id := cmd.GetString("Id")
	m := make(map[string]interface{})
	col, rows, err := rpc.BySqlParamName(id, m)
	if err != nil {
		log.Error(err.Error())
		writePrror("db error", cmd, c)
		return
	}
	dp := new(common.OutputParam)
	dp.RowMap = col
	dp.Rows = rows
	dp.Time = time.Now()
	writepid(c, cmd, 0, dp)
}
Beispiel #4
0
// login in
func pid_1(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "Login", "Password") {
		return
	}

	login := cmd.GetString("Login")
	pwd := cmd.GetString("Password")
	c.Name = login
	log.Infof("user %s login", c.Name, common.IsDebug)
	loginSuccess := false
	if common.IsDebug { //调试时直接登陆,不验证密码
		loginSuccess = true
	} else {
		param := make(map[string]interface{})
		param["login"] = login
		_, epwd, err := rpc.BySqlParamName("login", param)
		if err != nil {
			log.Error(err.Error())
		}
		if err == nil && len(epwd) > 0 {
			loginSuccess = epwd[0][0] == pwd //需要对密码进行加密再进行比较
		}
	}

	//check
	re := make(map[string]interface{})
	if loginSuccess {
		c.IsLogin = true
		c.Key = common.HashString(c.UUID + ":" + c.Name)
		online.SetSession(c.UUID, c.Name, c.Key)
		re["LoginState"] = 0
		re["Message"] = "login success"
		re["UID"] = c.UUID
		re["Key"] = c.Key
		online.Set(c)
	} else {
		re["LoginState"] = -1
		re["Message"] = "login failed"
	}
	writepid(c, cmd, 0, re)
}
Beispiel #5
0
// test service
func pid0(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "Test") {
		return
	}

	test := cmd.GetInt("Test")
	var result interface{}
	switch test {
	case 0:
		result = true
	case 1:
		result = time.Now().Format(common.TimeFormat)
	case 2:
		result = time.Since(now).String()
	case 3:
		result = now.Format(common.TimeFormat)
	default:
		result = fmt.Sprintf("not surport %d", test)
	}
	writepid(c, cmd, 0, result)
}
Beispiel #6
0
//注册推送数据的请求
func pid2(cmd *common.RequestData, c *online.Client) {
	if checkParamError(cmd, c, "DataKey", "DataRange", "Id", "LimitId", "OrderBy", "OrderKey", "OutputKey", "TimeRange") {
		return
	}
	dp := new(common.DataParam)
	dp.DataKey = cmd.GetString("DataKey")
	dp.DataRange = cmd.GetInt("DataRange")
	dp.Id = cmd.GetString("Id")
	dp.LimitId = cmd.GetStringArray("LimitId")
	dp.OrderBy = cmd.GetInt("OrderBy")
	dp.OrderKey = cmd.GetString("OrderKey")
	dp.OutputKey = cmd.GetStringArray("OutputKey")
	dp.FillKey = cmd.GetString("FillKey")
	dp.TimeRange = cmd.GetInt("TimeRange")
	c.AddRequest(dp)
	//同时直接返回一次数据,否则界面会有空白期
	tm := &common.TimeMessage{Time: online.GetCurrentTime()}
	c.Processing(tm)
}