mirror of
https://github.com/jesperh1/csgo-hub-backend.git
synced 2025-05-16 17:28:12 +01:00
Merge pull request #2 from jesperbakhandskemager/development
Development
This commit is contained in:
commit
768199c990
BIN
csgo-hub-backend
Executable file
BIN
csgo-hub-backend
Executable file
Binary file not shown.
@ -9,7 +9,7 @@
|
|||||||
{{if .DiscordName}}
|
{{if .DiscordName}}
|
||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
<ul>
|
<ul>
|
||||||
<li style="float:right"><img alt="avatar" src="https://cdn.discordapp.com/avatars/{{.DiscordAvatar}}.png?size=100" width="50" height="50px"></li>
|
<li style="float:right"><img alt="avatar" src="{{.DiscordAvatar}}" width="50" height="50px"></li>
|
||||||
<li style="float:right"><a class="active" href="#">{{.DiscordName}}</a></li>
|
<li style="float:right"><a class="active" href="#">{{.DiscordName}}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
21
main.go
21
main.go
@ -151,13 +151,22 @@ func CreateToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Fprintf(w, "Bad request")
|
fmt.Fprintf(w, "Bad request")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var dbToken string
|
||||||
|
query := `SELECT token FROM tokens where discord_id = ?`
|
||||||
|
_ = db.QueryRow(query, discord).Scan(&dbToken)
|
||||||
|
|
||||||
_, err = db.Exec(`INSERT INTO tokens(discord_id, token) VALUES (?, ?)`, discord, token)
|
if dbToken != "" {
|
||||||
if err != nil {
|
token = dbToken
|
||||||
log.Println(err)
|
}
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
fmt.Fprintf(w, "Bad request")
|
if token != dbToken {
|
||||||
return
|
_, err = db.Exec(`INSERT INTO tokens(discord_id, token) VALUES (?, ?)`, discord, token)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
fmt.Fprintf(w, "Bad request")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(token)
|
json.NewEncoder(w).Encode(token)
|
||||||
|
10
steam.go
10
steam.go
@ -66,7 +66,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 959336363172442152/1ce1214a9540ff02cedc0acd0ad37d1f.png
|
// 959336363172442152/1ce1214a9540ff02cedc0acd0ad37d1f.png
|
||||||
req, err := http.NewRequest("GET", "https://discord.com/api/v9/users/"+discordId, nil)
|
req, _ := http.NewRequest("GET", "https://discord.com/api/v9/users/"+discordId, nil)
|
||||||
req.Header.Add("Authorization", bearer)
|
req.Header.Add("Authorization", bearer)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
@ -82,7 +82,13 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
var discord DiscordUser
|
var discord DiscordUser
|
||||||
json.Unmarshal(body, &discord)
|
json.Unmarshal(body, &discord)
|
||||||
tmpl := IndexStruct{DiscordName: discord.Username, DiscordAvatar: discord.Id + "/" + discord.Avatar}
|
var discordAvatarURL string
|
||||||
|
if discord.Avatar == "" {
|
||||||
|
discordAvatarURL = "https://csgohub.xyz/assets/empty-avatar.png"
|
||||||
|
} else {
|
||||||
|
discordAvatarURL = "https://cdn.discordapp.com/avatars/" + discord.Id + "/" + discord.Avatar + ".png?size=100"
|
||||||
|
}
|
||||||
|
tmpl := IndexStruct{DiscordName: discord.Username, DiscordAvatar: discordAvatarURL}
|
||||||
log.Println(token)
|
log.Println(token)
|
||||||
expiration := time.Now().Add(time.Hour)
|
expiration := time.Now().Add(time.Hour)
|
||||||
cookie := http.Cookie{Name: "token", Value: token, Expires: expiration}
|
cookie := http.Cookie{Name: "token", Value: token, Expires: expiration}
|
||||||
|
Loading…
Reference in New Issue
Block a user