Display calendar page with name of login, also add in README.md
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user