go-roblox/session.go

39 lines
802 B
Go
Raw Normal View History

2017-01-07 05:20:45 +00:00
package roblox
import (
"fmt"
"net/http"
"net/http/cookiejar"
"net/url"
)
// Session struct for roblox login session data and members
type Session struct {
ID string
2017-01-07 08:48:57 +00:00
Username string
2017-01-07 05:20:45 +00:00
client *http.Client
}
// New create a new session and logs in with provided data
func New(user string, pass string, id string) (*Session, error) {
cookieJar, _ := cookiejar.New(nil)
client := &http.Client{
Jar: cookieJar,
}
v := url.Values{}
v.Set("username", user)
v.Set("password", pass)
v.Set("submitLogin", "Log In")
v.Set("ReturnUrl", "")
session := Session{id, user, client}
resp, err := client.PostForm("https://www.roblox.com/newlogin", v)
if resp.StatusCode != 200 {
return &session, fmt.Errorf("Messaged send failed. Status %d", resp.StatusCode)
}
return &session, err
}