go-roblox/session.go
2017-01-07 00:20:45 -05:00

39 lines
802 B
Go

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
username string
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
}