Skip to content

Instantly share code, notes, and snippets.

@albertoleal
Created December 11, 2014 15:20
Show Gist options
  • Select an option

  • Save albertoleal/2ccae3e0acc704f87b71 to your computer and use it in GitHub Desktop.

Select an option

Save albertoleal/2ccae3e0acc704f87b71 to your computer and use it in GitHub Desktop.

Revisions

  1. albertoleal created this gist Dec 11, 2014.
    23 changes: 23 additions & 0 deletions login.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    func (a *Auth) Login(email, password string) string {
    url, err := GetURL("/api/login")
    if err != nil {
    return err.Error()
    }
    b := bytes.NewBufferString(`{"email":"` + email + `", "password":"` + password + `"}`)
    req, err := http.NewRequest("POST", url, b)
    if err != nil {
    return err.Error()
    }

    client := NewClient(&http.Client{})
    response, err := client.Do(req)
    if err != nil {
    httpEr := err.(*httpErr.HTTPError)
    return httpEr.Message
    }

    var token = map[string]interface{}{}
    parseBody(response.Body, &token)
    writeToken(token["token_type"].(string) + " " + token["token"].(string))
    return "Welcome! You've signed in successfully."
    }