From 352e343f51a7a923f50b275f188d82e08d8fa318 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 21 Dec 2015 16:42:06 +0100 Subject: Agree to TOS --- client.go | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'client.go') diff --git a/client.go b/client.go index 4cb0aa9..16644c5 100644 --- a/client.go +++ b/client.go @@ -159,41 +159,40 @@ func (c *Client) parseHeader(r *http.Response) { challenge cert-chain */ -func (c *Client) Register(a *Account) (*Registration, error) { +func (c *Client) Register(a *Account) error { r := &Registration{ Resource: ResNewReg, Contact: a.Contact, } - _, err := c.post(c.Dir.NewReg, a, r) - return r, err -} - -// Agree to TOS -func (c *Client) Agree(a *Account) (*Registration, error) { - tos := c.Link["terms-of-service"] - if tos == "" { - return nil, errors.New("TOS agreed") - } - r := &Registration{ - Resource: ResRegister, - Contact: a.Contact, - Agreement: tos, + resp, err := c.post(c.Dir.NewReg, a, r) + switch resp.StatusCode { + case http.StatusConflict: + // Query Location + r.Resource = ResRegister + _, err = c.post(c.Location, a, r) + fallthrough + case http.StatusCreated: + // Agree to TOS + if tos := c.Link["terms-of-service"]; tos != "" { + r.Resource = ResRegister + r.Agreement = tos + _, err = c.post(c.Location, a, r) + } } - log.Println("TOS", tos) - _, err := c.post(c.Location, a, r) - return r, err + return err } -func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) { +func (c *Client) Authorize(a *Account, domain []string) error { r := &Authorization{ Resource: ResNewAuthz, Identifier: Identifier{ Type: IdentDNS, - Value: domain, + Value: domain[0], }, } _, err := c.post(c.Dir.NewAuthz, a, r) - return r, err + log.Println(r) + return err } func (c Client) String() string { -- cgit v1.2.3