diff --git a/README.md b/README.md index f4c02c8..2ef19a5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ A calandar viewer for stalwart calandars **NOTE** while this app uses standard caldav reading it makes assumptions about paths and treats them as if they all come from stalwart + +**TODO** +1. Switch over to a golang caldav library, while I wanted to roll my own CalDAV I am too lazy to read up on the spec so imma just get someone else to do it +2. Fix password login +3. Actually write a UI that looks somewhat decent diff --git a/auth/oauth.go b/auth/oauth.go index ff7e064..d01b2f7 100644 --- a/auth/oauth.go +++ b/auth/oauth.go @@ -10,6 +10,7 @@ import ( // This is all the user info that this script needs type UserInfo struct { Email string `json:"email"` + Name string `json:"name"` } type OAuthProvider struct { diff --git a/main/calandar_endpoint.go b/main/calandar_endpoint.go index 611de58..d57f12e 100644 --- a/main/calandar_endpoint.go +++ b/main/calandar_endpoint.go @@ -3,17 +3,21 @@ package main import ( "context" "encoding/json" - "fmt" "net/http" + "text/template" "astraltech.xyz/calendar/v2/auth" ) -func HandleCalandarEndpoint(w http.ResponseWriter, r *http.Request) { +type CalendarData struct { + DisplayName string +} + +func ParseOAuthLogin(w http.ResponseWriter, r *http.Request) CalendarData { token, err := auth.TestTokenStore.Load() if err != nil { http.Error(w, "Not authenticated", http.StatusUnauthorized) - return + return CalendarData{} } client := auth.DefaultProvider.Config.Client(context.Background(), token) @@ -21,15 +25,28 @@ func HandleCalandarEndpoint(w http.ResponseWriter, r *http.Request) { resp, err := client.Get(auth.DefaultProvider.Provider.UserInfoEndpoint()) if err != nil { http.Error(w, "Failed to fetch user: "+err.Error(), http.StatusInternalServerError) - return + return CalendarData{} } defer resp.Body.Close() var usersInfo auth.UserInfo if err := json.NewDecoder(resp.Body).Decode(&usersInfo); err != nil { http.Error(w, "Failed to decode response", http.StatusInternalServerError) - return + return CalendarData{} + } + return CalendarData{ + DisplayName: usersInfo.Name, + } +} + +func HandleCalandarEndpoint(w http.ResponseWriter, r *http.Request) { + var OauthLogin = true + var data CalendarData + if OauthLogin { + data = ParseOAuthLogin(w, r) } - fmt.Printf("The users email is %s\n", usersInfo.Email) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + tmpl := template.Must(template.ParseFiles("main/pages/calendar.html")) + tmpl.Execute(w, data) } diff --git a/main/pages/calendar.html b/main/pages/calendar.html new file mode 100644 index 0000000..7def65c --- /dev/null +++ b/main/pages/calendar.html @@ -0,0 +1,11 @@ + + + + + + Astral Calendar + + + Welcome to your calendar {{.DisplayName}} + +