diff --git a/router/oauth.go b/router/oauth.go index 4940a49..e67176d 100644 --- a/router/oauth.go +++ b/router/oauth.go @@ -19,6 +19,13 @@ func (a *App) login(w http.ResponseWriter, r *http.Request) { } http.Redirect(w, r, a.Domain, http.StatusFound) } +func (a *App) logout(w http.ResponseWriter, r *http.Request) { + if err := a.store.Logout(w, r); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + http.Redirect(w, r, a.Domain, http.StatusFound) +} func (a *App) loginCallback(w http.ResponseWriter, r *http.Request) { user, err := gothic.CompleteUserAuth(w, r) diff --git a/router/router.go b/router/router.go index 03b37a8..bb5f993 100644 --- a/router/router.go +++ b/router/router.go @@ -54,6 +54,7 @@ func New(app App) *chi.Mux { r.Route("/auth", func(r chi.Router) { r.Get("/login", app.login) + r.Get("/logout", app.logout) r.Get("/callback", app.loginCallback) }) }) diff --git a/router/session/session.go b/router/session/session.go index dbb9674..cc1526f 100644 --- a/router/session/session.go +++ b/router/session/session.go @@ -22,6 +22,7 @@ type Store struct { } type Info struct { + User string Org string Token string } @@ -96,12 +97,23 @@ func (s *Store) CompleteAuth(w http.ResponseWriter, r *http.Request, token strin } sess.Values[infoKey] = &Info{ + User: profile.UserName, Org: org, Token: token, } return s.Store.Save(r, w, sess) } +func (s *Store) Logout(w http.ResponseWriter, r *http.Request) error { + sess, err := s.Store.Get(r, sessionCookie) + if err != nil { + return err + } + sess.Options.MaxAge = -1 + sess.Values = make(map[any]any) + return s.Store.Save(r, w, sess) +} + func (s *Store) Repos(r *http.Request) ([]*gitea.Repository, error) { info, err := s.Info(r) if err != nil { diff --git a/static/css/gistea.css b/static/css/gistea.css index 245e0b9..4d7d058 100644 --- a/static/css/gistea.css +++ b/static/css/gistea.css @@ -1,11 +1,19 @@ +:root { + --border-radius: 10px; +} + .form-input { - border-radius: 10px; + border-radius: var(--border-radius); margin: 1em 0; } .form-head { border: black solid thin; - border-top-left-radius: 10px; - border-top-right-radius: 10px; + border-top-left-radius: var(--border-radius); + border-top-right-radius: var(--border-radius); padding: 0 1em; +} + +.btn { + border-radius: var(--border-radius); } \ No newline at end of file diff --git a/static/js/monaco.js b/static/js/monaco.js index 7dc8560..4e99f9b 100644 --- a/static/js/monaco.js +++ b/static/js/monaco.js @@ -23,6 +23,7 @@ require(["vs/editor/editor.main"], function () { let $editor = monaco.editor.create(elem, { language: 'text', theme: 'vs-dark', + fontSize: "12px" }); elem.classList.remove("loading", "loading-lg"); let $filename = $filenames[idx]; @@ -30,8 +31,15 @@ require(["vs/editor/editor.main"], function () { "filename": $filename, "editor": $editor }); - $filename.addEventListener('change', () => { - monaco.editor.setModelLanguage($editor.getModel(), $filename.value.split(".").pop()); + $filename.addEventListener('keyup', () => { + let value = $editor.getValue(); + $editor.getModel().dispose(); + let $model = monaco.editor.createModel( + value, + undefined, + monaco.Uri.file($filename.value) + ) + $editor.setModel($model); }); }) diff --git a/static/templates/base.tmpl b/static/templates/base.tmpl index db70389..0acb3d8 100644 --- a/static/templates/base.tmpl +++ b/static/templates/base.tmpl @@ -15,13 +15,15 @@ - {{if not .Session}} - {{end}}
{{tmpl .Page .}} diff --git a/static/templates/new.tmpl b/static/templates/new.tmpl index 3e6d8ab..adf7c75 100644 --- a/static/templates/new.tmpl +++ b/static/templates/new.tmpl @@ -15,5 +15,14 @@ +
+
+
+
+ + +
+
+