forked from pothtonswer/discordmuffin
Added register function
This commit is contained in:
parent
d737b91b77
commit
a6e3be7a36
1 changed files with 21 additions and 0 deletions
21
restapi.go
21
restapi.go
|
@ -119,6 +119,27 @@ func (s *Session) Login(email string, password string) (token string, err error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register sends a Register request to Discord, and returns the authentication token
|
||||||
|
// Note that this account is temporary and should be verified for future use.
|
||||||
|
// Another option is to save the authentication token external, but this isn't recommended.
|
||||||
|
func (s *Session) Register(username string) (token string, err error) {
|
||||||
|
|
||||||
|
data := struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
}{username}
|
||||||
|
|
||||||
|
response, err := s.Request("POST", REGISTER, data)
|
||||||
|
|
||||||
|
var temp map[string]interface{}
|
||||||
|
err = json.Unmarshal(response, &temp)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
token = temp["token"].(string)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Logout sends a logout request to Discord.
|
// Logout sends a logout request to Discord.
|
||||||
// This does not seem to actually invalidate the token. So you can still
|
// This does not seem to actually invalidate the token. So you can still
|
||||||
// make API calls even after a Logout. So, it seems almost pointless to
|
// make API calls even after a Logout. So, it seems almost pointless to
|
||||||
|
|
Loading…
Reference in a new issue