aboutsummaryrefslogtreecommitdiffstats
path: root/web.go
diff options
context:
space:
mode:
Diffstat (limited to 'web.go')
-rw-r--r--web.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/web.go b/web.go
index ea9e5cd..5eebc37 100644
--- a/web.go
+++ b/web.go
@@ -76,7 +76,7 @@ func (app *App) callback(w http.ResponseWriter, r *http.Request) {
var state string
app.GetCookie(r, "state", &state)
if state == "" || state != r.FormValue("state") {
- panic(fmt.Errorf("state"))
+ panic(fmt.Errorf("Inconsistent states: %v %v", state, r.FormValue("state")))
}
code := r.FormValue("code")
tok, _ := app.Config.OAuth.Exchange(r.Context(), code)
@@ -86,16 +86,17 @@ func (app *App) callback(w http.ResponseWriter, r *http.Request) {
user := &User{Type: "google"}
json.Unmarshal(p, user)
- s := &UserSession{Id: hex.EncodeToString(genKey(32))}
- var newUser bool
+ newUser := false
if err := app.GetUser(user); err != nil {
newUser = true
if err := app.InsertUser(user); err != nil {
panic(err)
}
}
- s.UserId = user.Id
- s.UserName = user.Name
+
+ s := &UserSession{Id: hex.EncodeToString(genKey(32)),
+ UserId: user.Id,
+ UserName: user.Name}
app.InsertUserSession(s)
app.SetCookie(w, "session", s, 86400*30)
@@ -112,6 +113,7 @@ func (app *App) callback(w http.ResponseWriter, r *http.Request) {
} else if newUser {
http.Redirect(w, r, "/settings", http.StatusTemporaryRedirect)
} else {
+ log.Println("Existing user without lfmauth cookie")
http.Redirect(w, r, "/", http.StatusFound)
}
}