Compare commits

..
2 Commits
Author SHA1 Message Date
gawells ac872d5127 Display calendar page with name of login, also add in README.md 2026-08-06 20:34:17 -04:00
gawells ec901d97c2 change user endpoint to calandar 2026-08-06 20:25:44 -04:00
6 changed files with 42 additions and 9 deletions
+5
View File
@@ -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
+1
View File
@@ -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 {
+1 -2
View File
@@ -44,10 +44,9 @@ func OAuthCallback(w http.ResponseWriter, r *http.Request) {
return
}
// Store the token securely
if err := TestTokenStore.Save(token); err != nil {
log.Printf("Failed to save token: %v", err)
}
http.Redirect(w, r, "/user", http.StatusTemporaryRedirect)
http.Redirect(w, r, "/calandar", http.StatusTemporaryRedirect)
}
+23 -6
View File
@@ -3,17 +3,21 @@ package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"text/template"
"astraltech.xyz/calendar/v2/auth"
)
func handleUser(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 handleUser(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)
}
+1 -1
View File
@@ -21,7 +21,7 @@ func main() {
AuthRequestFunction: auth.HandleAuthRequest,
})
webserver.ServeWebpage("/callback", auth.OAuthCallback)
webserver.ServeWebpage("/user", handleUser)
webserver.ServeWebpage("/calandar", HandleCalandarEndpoint)
webserver.EnableLogoRoute()
webserver.EnableStaticRoute()
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Astral Calendar</title>
</head>
<body>
Welcome to your calendar {{.DisplayName}}
</body>
</html>