diff --git a/chatState.go b/chatState.go index 6a8f500..e90542d 100644 --- a/chatState.go +++ b/chatState.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "time" ) //chat state that we might be use for collecting infomation from user @@ -49,6 +50,17 @@ func getCurrentState(openID string, procedure string) (result chatState, err err } //we don't check Expire, we give the caller full control on //how to deal wiht expired session + + //check whether state is for the correct openID and procedure + if result.OpenID != openID { + err = errors.New("Error: State for " + openID + " is actually for " + result.OpenID) + return + } + + if result.Procedure != procedure { + err = errors.New("Error: Proecdure for " + procedure + " is actually for " + result.Procedure) + return + } return } @@ -126,7 +138,7 @@ func stopProcedure(openID, procedure string) { func processProcedureState(state chatState) (err error) { //send what we need to send if isExpired(state.Expire) { - return errors.New("State has expired " + stae.Name) + return errors.New("State has expired " + state.Name) } //mark we have sent. @@ -152,6 +164,6 @@ func getProcedureInit(openID, procedure string) initProcedureFunction { func initTestEcho(openid string) (r chatState) { r.Name = openid - r.Expire = 0 + r.Expire = int32(time.Now().Unix() + 100) return }