Skip to content

Commit

Permalink
Fix: shiori is a default owner
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Aug 12, 2019
1 parent 0c4d75f commit b6f6864
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/webserver/handler-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ func (h *handler) apiLogin(w http.ResponseWriter, r *http.Request, ps httprouter
checkError(err)

// Prepare function to generate session
genSession := func(ownerMode bool, account model.Account, expTime time.Duration) {
genSession := func(account model.Account, expTime time.Duration) {
// Create session ID
sessionID, err := uuid.NewV4()
checkError(err)

// Save session ID to cache
strSessionID := sessionID.String()
h.SessionCache.Set(strSessionID, ownerMode, expTime)
h.SessionCache.Set(strSessionID, account.Owner, expTime)

// Save user's session IDs to cache as well
// useful for mass logout
Expand Down Expand Up @@ -78,7 +78,10 @@ func (h *handler) apiLogin(w http.ResponseWriter, r *http.Request, ps httprouter
checkError(err)

if len(accounts) == 0 && request.Username == "shiori" && request.Password == "gopher" {
genSession(true, model.Account{}, time.Hour)
genSession(model.Account{
Username: "shiori",
Owner: true,
}, time.Hour)
return
}

Expand All @@ -103,7 +106,7 @@ func (h *handler) apiLogin(w http.ResponseWriter, r *http.Request, ps httprouter
}

// Create session
genSession(account.Owner, account, expTime)
genSession(account, expTime)
}

// apiLogout is handler for POST /api/logout
Expand Down

0 comments on commit b6f6864

Please sign in to comment.