-
Notifications
You must be signed in to change notification settings - Fork 2
/
user.go
72 lines (60 loc) · 1.6 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package steamuser
import (
"fmt"
"net/http"
"github.com/vincentserpoul/mangosteam"
"github.com/vincentserpoul/mangosteam/auth"
)
// User represents a steam user
type User struct {
SteamID mangosteam.SteamID `json:"steam_id"`
Username string `json:"username"`
Password string
APIKey string
Email string
SteamLogin string
SteamLoginSecure string
auth.SteamGuardAccount
auth.OAuth
}
// Login logs in the bot
func (user *User) Login() error {
isLoggedInclient := user.NewWebSteamClient()
isLoggedIn, err := auth.IsLoggedIn(isLoggedInclient)
if err != nil {
return fmt.Errorf("steamuser Login() : %v", err)
}
if isLoggedIn {
return nil
}
// resetting the login params
user.SteamLogin = ""
user.SteamLoginSecure = ""
client := &http.Client{}
rsaKey, err := auth.GetRSAKey(user.Username)
if err != nil {
return fmt.Errorf("steamuser Login(): %v", err)
}
encryptedPassword, err := auth.EncryptPassword(user.Password, rsaKey)
if err != nil {
return fmt.Errorf("steamuser Login(): %v", err)
}
steamGuardCode, err := user.GenerateSteamGuardCode()
if err != nil {
return fmt.Errorf("steamuser Login(): %v", err)
}
user.OAuth, err = auth.DoLogin(
client,
user.Username,
encryptedPassword,
rsaKey.Timestamp,
"", "", "", steamGuardCode,
)
if err != nil {
return fmt.Errorf("steamuser Login(): %v error %v", user.Username, err)
}
user.SteamID = user.OAuth.SteamID
user.SteamLogin = user.SteamID.String() + "||" + user.OAuth.Token
user.SteamLoginSecure = user.SteamID.String() + "||" + user.OAuth.TokenSecure
return nil
}