示例#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)
}
示例#2
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)
}