//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) }
//exec pid function func Exec(cmd *common.RequestData, c *online.Client) { //没有登陆就必须登陆系统,小于等于0的协议不需要登陆。 if cmd.Pid <= 0 { pid[cmd.Pid](cmd, c) } else if !c.IsLogin { cmd := common.ResponseData{1, 0, "need login", nil} c.Send(&cmd) } else { if p, ok := pid[cmd.Pid]; ok { p(cmd, c) } else { pidok(cmd, c) } } }
//login out func pid_2(cmd *common.RequestData, c *online.Client) { //if param, ok := cmd.Param.(string); ok { log.Debug("login out ", c.Name) writepid(c, cmd, 0, nil) c.IsRun = false online.RemoveSession(c.UUID) //} }
//注册推送数据的请求 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) }
// 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) }
//write pid to responseout ResponseData func writepid(c *online.Client, cmd *common.RequestData, status int, result interface{}) { out := common.ResponseData{cmd.Pid, status, result, cmd.Param} c.Send(&out) }