save oauth user_id and link users and accounts
This commit is contained in:
+3
-24
@@ -93,15 +93,12 @@ func NewServer(
|
||||
s.mux.HandleFunc("GET /login", s.loginPage)
|
||||
s.mux.HandleFunc("GET /login/callback", s.loginCallback)
|
||||
s.mux.HandleFunc("GET /logout", s.logoutPage)
|
||||
s.mux.Handle("POST /accounts", s.authenticate(http.HandlerFunc(s.createAccount)))
|
||||
|
||||
// TODO: eliminate once no longer used.
|
||||
s.mux.HandleFunc("POST /login", s.login)
|
||||
|
||||
// TODO: when a user is created, we should make an account for them that is associated with their openid subject.
|
||||
// - then this can go away
|
||||
s.mux.HandleFunc("POST /accounts", s.createAccount)
|
||||
|
||||
// TODO: test the new auth middleware
|
||||
// TODO: get rid of this, once we're confident this isn't needed...
|
||||
s.mux.Handle("GET /test-auth", s.authenticate(http.HandlerFunc(s.testAuthEndpoint)))
|
||||
|
||||
// webpage content
|
||||
@@ -116,6 +113,7 @@ func NewServer(
|
||||
})))
|
||||
s.mux.Handle("GET /styles/", http.StripPrefix("/styles", http.FileServer(http.Dir(contentDir+"/styles"))))
|
||||
|
||||
// TODO: put auth on individual templates, somehow...
|
||||
s.mux.HandleFunc("GET /", s.serveTemplates)
|
||||
|
||||
return s
|
||||
@@ -125,22 +123,3 @@ func NewServer(
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.mux.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// POST /accounts
|
||||
func (s *Server) createAccount(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
email := r.FormValue("email")
|
||||
if email == "" {
|
||||
http.Error(w, "no email provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
acct, err := s.accts.CreateAccount(ctx, email)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("failed to create account: %v", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
//http.Redirect(w, r, fmt.Sprintf("/site/accounts/%d", acct.ID), http.StatusSeeOther)
|
||||
http.Redirect(w, r, fmt.Sprintf("/accounts/%d", acct.ID), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user