-
Notifications
You must be signed in to change notification settings - Fork 3
/
welcome_controller.go
37 lines (31 loc) · 980 Bytes
/
welcome_controller.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
package handlers
import (
"html/template"
"log"
"net/http"
"github.com/boratanrikulu/lirik.app/internal/handlers/helpers"
"github.com/boratanrikulu/lirik.app/pkg/spotify"
)
type WelcomePageData struct {
SpotifyAuthLink string
}
func WelcomeGet(w http.ResponseWriter, r *http.Request) {
accessTokenCookie, _ := r.Cookie("AccessToken")
refreshTokenCookie, _ := r.Cookie("RefreshToken")
if accessTokenCookie != nil || refreshTokenCookie != nil {
http.Redirect(w, r, "/spotify", http.StatusSeeOther)
return
}
files := helpers.GetTemplateFiles("./views/welcome.html")
tmpl := template.Must(template.ParseFiles(files...))
authLink, state, err := spotify.S.GetRequestAuthorizationLink()
if err != nil {
log.Println("Somethings are wrong. We are working on it.")
helpers.ErrorPage([]string{"Somethings are wrong. We are working on it."}, w)
return
}
helpers.SetStateCookie(state, w)
_ = tmpl.Execute(w, WelcomePageData{
SpotifyAuthLink: authLink,
})
}