2017-03-11 07:15:15 -05:00
|
|
|
package ofxgo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2017-04-08 08:57:31 -04:00
|
|
|
"fmt"
|
2017-03-22 20:59:40 -04:00
|
|
|
"github.com/aclindsa/go/src/encoding/xml"
|
2017-03-11 07:15:15 -05:00
|
|
|
)
|
|
|
|
|
2017-03-11 07:18:02 -05:00
|
|
|
type SignonRequest struct {
|
|
|
|
XMLName xml.Name `xml:"SONRQ"`
|
2017-03-16 11:14:58 -04:00
|
|
|
DtClient Date `xml:"DTCLIENT"` // Current time on client, overwritten in Client.Request()
|
2017-04-12 21:40:42 -04:00
|
|
|
UserID String `xml:"USERID"`
|
2017-03-11 07:18:02 -05:00
|
|
|
UserPass String `xml:"USERPASS,omitempty"`
|
|
|
|
UserKey String `xml:"USERKEY,omitempty"`
|
|
|
|
Language String `xml:"LANGUAGE"` // Defaults to ENG
|
|
|
|
Org String `xml:"FI>ORG"`
|
|
|
|
Fid String `xml:"FI>FID"`
|
2017-04-12 21:40:42 -04:00
|
|
|
AppID String `xml:"APPID"` // Overwritten in Client.Request()
|
2017-03-16 11:13:21 -04:00
|
|
|
AppVer String `xml:"APPVER"` // Overwritten in Client.Request()
|
2017-03-11 07:18:02 -05:00
|
|
|
ClientUID UID `xml:"CLIENTUID,omitempty"`
|
2017-03-11 07:15:15 -05:00
|
|
|
}
|
|
|
|
|
2017-03-11 07:18:02 -05:00
|
|
|
func (r *SignonRequest) Name() string {
|
2017-03-11 07:15:15 -05:00
|
|
|
return "SONRQ"
|
|
|
|
}
|
|
|
|
|
2017-03-11 07:18:02 -05:00
|
|
|
func (r *SignonRequest) Valid() (bool, error) {
|
2017-04-12 21:40:42 -04:00
|
|
|
if len(r.UserID) < 1 || len(r.UserID) > 32 {
|
2017-03-11 07:15:15 -05:00
|
|
|
return false, errors.New("SONRQ>USERID invalid length")
|
|
|
|
}
|
|
|
|
if (len(r.UserPass) == 0) == (len(r.UserKey) == 0) {
|
|
|
|
return false, errors.New("One and only one of SONRQ>USERPASS and USERKEY must be supplied")
|
|
|
|
}
|
|
|
|
if len(r.UserPass) > 32 {
|
|
|
|
return false, errors.New("SONRQ>USERPASS invalid length")
|
|
|
|
}
|
|
|
|
if len(r.UserKey) > 64 {
|
|
|
|
return false, errors.New("SONRQ>USERKEY invalid length")
|
|
|
|
}
|
|
|
|
if len(r.Language) == 0 {
|
|
|
|
r.Language = "ENG"
|
|
|
|
} else if len(r.Language) != 3 {
|
2017-04-08 08:57:31 -04:00
|
|
|
return false, fmt.Errorf("SONRQ>LANGUAGE invalid length: \"%s\"\n", r.Language)
|
2017-03-11 07:15:15 -05:00
|
|
|
}
|
2017-04-12 21:40:42 -04:00
|
|
|
if len(r.AppID) < 1 || len(r.AppID) > 5 {
|
2017-03-11 07:15:15 -05:00
|
|
|
return false, errors.New("SONRQ>APPID invalid length")
|
|
|
|
}
|
2017-03-16 11:13:21 -04:00
|
|
|
if len(r.AppVer) < 1 || len(r.AppVer) > 4 {
|
2017-03-11 07:15:15 -05:00
|
|
|
return false, errors.New("SONRQ>APPVER invalid length")
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2017-03-11 07:18:02 -05:00
|
|
|
type SignonResponse struct {
|
|
|
|
XMLName xml.Name `xml:"SONRS"`
|
|
|
|
Status Status `xml:"STATUS"`
|
2017-03-11 21:13:06 -05:00
|
|
|
DtServer Date `xml:"DTSERVER"`
|
2017-03-11 07:18:02 -05:00
|
|
|
UserKey String `xml:"USERKEY,omitempty"`
|
2017-03-29 05:31:01 -04:00
|
|
|
TsKeyExpire *Date `xml:"TSKEYEXPIRE,omitempty"`
|
2017-03-11 07:18:02 -05:00
|
|
|
Language String `xml:"LANGUAGE"`
|
2017-03-29 05:31:01 -04:00
|
|
|
DtProfUp *Date `xml:"DTPROFUP,omitempty"`
|
|
|
|
DtAcctUp *Date `xml:"DTACCTUP,omitempty"`
|
2017-03-11 07:18:02 -05:00
|
|
|
Org String `xml:"FI>ORG"`
|
|
|
|
Fid String `xml:"FI>FID"`
|
|
|
|
SessCookie String `xml:"SESSCOOKIE,omitempty"`
|
|
|
|
AccessKey String `xml:"ACCESSKEY,omitempty"`
|
2017-03-11 07:15:15 -05:00
|
|
|
}
|
|
|
|
|
2017-03-11 07:18:02 -05:00
|
|
|
func (r *SignonResponse) Name() string {
|
2017-03-11 07:15:15 -05:00
|
|
|
return "SONRS"
|
|
|
|
}
|
|
|
|
|
2017-03-11 07:18:02 -05:00
|
|
|
func (r *SignonResponse) Valid() (bool, error) {
|
2017-03-11 07:15:15 -05:00
|
|
|
if len(r.Language) != 3 {
|
2017-04-08 08:57:31 -04:00
|
|
|
return false, fmt.Errorf("SONRS>LANGUAGE invalid length: \"%s\"\n", r.Language)
|
2017-03-11 07:15:15 -05:00
|
|
|
}
|
|
|
|
return r.Status.Valid()
|
|
|
|
}
|