aboutsummaryrefslogtreecommitdiffstats
path: root/web.go
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2017-06-13 20:42:22 -0400
committerThibaut Horel <thibaut.horel@gmail.com>2017-06-13 20:42:22 -0400
commita64a435757ab96cdd73ae83903242406bbb258f8 (patch)
treebd1d123e195e3d7460e86e1ecd0a46b84d685693 /web.go
parenta38f778312b392614ec0ccf14f9f2790671b63eb (diff)
downloadlastfm-api-a64a435757ab96cdd73ae83903242406bbb258f8.tar.gz
Fix broken login
Diffstat (limited to 'web.go')
-rw-r--r--web.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/web.go b/web.go
index 5dc2e70..0810f76 100644
--- a/web.go
+++ b/web.go
@@ -78,18 +78,22 @@ func (app *App) callback(w http.ResponseWriter, r *http.Request) {
json.Unmarshal(p, user)
s := &UserSession{Id: hex.EncodeToString(genKey(32))}
+ var newUser bool
if err := app.GetUser(user); err != nil {
+ newUser = true
if err := app.InsertUser(user); err != nil {
panic(err)
}
- http.Redirect(w, r, "/settings", http.StatusTemporaryRedirect)
- } else {
- http.Redirect(w, r, "/", http.StatusFound)
}
s.UserId = user.Id
s.UserName = user.Name
app.InsertUserSession(s)
app.SetCookie(w, "session", s, 86400*30)
+ if newUser {
+ http.Redirect(w, r, "/settings", http.StatusTemporaryRedirect)
+ } else {
+ http.Redirect(w, r, "/", http.StatusFound)
+ }
}
func (app *App) settings(w http.ResponseWriter, r *http.Request) {