-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthenticate.go
49 lines (40 loc) · 1.07 KB
/
authenticate.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
package transifex_app_go_client
import (
"errors"
"os"
"github.com/hemantasapkota/djangobot"
)
func (t *TransifexAppClient) Authenticate() error {
var err error
username := os.Getenv("TRANSIFEX_USER")
if len(username) == 0 {
return errors.New("the environmental variable TRANSIFEX_USER is not set")
}
password := os.Getenv("TRANSIFEX_PASSWORD")
if len(password) == 0 {
return errors.New("the environmental variable TRANSIFEX_PASSWORD is not set")
}
t.bot = djangobot.With("https://app.transifex.com/signin/?next=/home/").
ForHost("app.transifex.com").
SetUsername(username).
SetPassword(password).
LoadCookies()
if t.bot.Error != nil {
return t.bot.Error
}
t.agent, err = t.bot.Set("next", "/home/").
X("csrfmiddlewaretoken", t.bot.Cookie("csrftoken").Value).
X("identification", t.bot.Username).
X("password", t.bot.Password).
X("remember_me", "True").
X("next", "/home/").
Login()
if err != nil {
return err
}
sessionid := t.bot.Cookie("sessionid").Value
if sessionid == "" {
return errors.New("authentication failed")
}
return nil
}