Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 2022-07-15 23:36:38 -05:00
parent 99cd67d90b
commit 35b5a2250f
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
7 changed files with 55 additions and 8 deletions

View File

@ -19,6 +19,13 @@ func (a *App) login(w http.ResponseWriter, r *http.Request) {
} }
http.Redirect(w, r, a.Domain, http.StatusFound) 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) { func (a *App) loginCallback(w http.ResponseWriter, r *http.Request) {
user, err := gothic.CompleteUserAuth(w, r) user, err := gothic.CompleteUserAuth(w, r)

View File

@ -54,6 +54,7 @@ func New(app App) *chi.Mux {
r.Route("/auth", func(r chi.Router) { r.Route("/auth", func(r chi.Router) {
r.Get("/login", app.login) r.Get("/login", app.login)
r.Get("/logout", app.logout)
r.Get("/callback", app.loginCallback) r.Get("/callback", app.loginCallback)
}) })
}) })

View File

@ -22,6 +22,7 @@ type Store struct {
} }
type Info struct { type Info struct {
User string
Org string Org string
Token string Token string
} }
@ -96,12 +97,23 @@ func (s *Store) CompleteAuth(w http.ResponseWriter, r *http.Request, token strin
} }
sess.Values[infoKey] = &Info{ sess.Values[infoKey] = &Info{
User: profile.UserName,
Org: org, Org: org,
Token: token, Token: token,
} }
return s.Store.Save(r, w, sess) 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) { func (s *Store) Repos(r *http.Request) ([]*gitea.Repository, error) {
info, err := s.Info(r) info, err := s.Info(r)
if err != nil { if err != nil {

View File

@ -1,11 +1,19 @@
:root {
--border-radius: 10px;
}
.form-input { .form-input {
border-radius: 10px; border-radius: var(--border-radius);
margin: 1em 0; margin: 1em 0;
} }
.form-head { .form-head {
border: black solid thin; border: black solid thin;
border-top-left-radius: 10px; border-top-left-radius: var(--border-radius);
border-top-right-radius: 10px; border-top-right-radius: var(--border-radius);
padding: 0 1em; padding: 0 1em;
}
.btn {
border-radius: var(--border-radius);
} }

View File

@ -23,6 +23,7 @@ require(["vs/editor/editor.main"], function () {
let $editor = monaco.editor.create(elem, { let $editor = monaco.editor.create(elem, {
language: 'text', language: 'text',
theme: 'vs-dark', theme: 'vs-dark',
fontSize: "12px"
}); });
elem.classList.remove("loading", "loading-lg"); elem.classList.remove("loading", "loading-lg");
let $filename = $filenames[idx]; let $filename = $filenames[idx];
@ -30,8 +31,15 @@ require(["vs/editor/editor.main"], function () {
"filename": $filename, "filename": $filename,
"editor": $editor "editor": $editor
}); });
$filename.addEventListener('change', () => { $filename.addEventListener('keyup', () => {
monaco.editor.setModelLanguage($editor.getModel(), $filename.value.split(".").pop()); let value = $editor.getValue();
$editor.getModel().dispose();
let $model = monaco.editor.createModel(
value,
undefined,
monaco.Uri.file($filename.value)
)
$editor.setModel($model);
}); });
}) })

View File

@ -15,13 +15,15 @@
<section class="navbar-section"> <section class="navbar-section">
<a href="{{.Domain}}" class="navbar-brand mr-2">Gistea</a> <a href="{{.Domain}}" class="navbar-brand mr-2">Gistea</a>
<a href="{{.GiteaURL}}" class="btn btn-link">Back to Gitea</a> <a href="{{.GiteaURL}}" class="btn btn-link">Back to Gitea</a>
{{if .Session}}<a href="/" class="btn btn-link">Your gists</a>{{end}} {{if .Session}}<a href="{{.Domain}}/{{.Session.User}}" class="btn btn-link">Your gists</a>{{end}}
</section> </section>
{{if not .Session}}
<section class="navbar-section"> <section class="navbar-section">
{{if .Session}}
<a href="{{.Domain}}/_/auth/logout" class="navbar-brand mr-2">Logout</a>
{{else}}
<a href="{{.Domain}}/_/auth/login" class="navbar-brand mr-2">Login</a> <a href="{{.Domain}}/_/auth/login" class="navbar-brand mr-2">Login</a>
{{end}}
</section> </section>
{{end}}
</header> </header>
<div class="divider"></div> <div class="divider"></div>
{{tmpl .Page .}} {{tmpl .Page .}}

View File

@ -15,5 +15,14 @@
</div> </div>
</div> </div>
</div> </div>
<br/>
<div class="container">
<div class="columns">
<div class="column col-6 col-mx-auto">
<button class="btn">Add File</button>
<button class="btn btn-success float-right">Create Gist</button>
</div>
</div>
</div>
<script type="text/javascript" src="https://unpkg.com/monaco-editor@latest/min/vs/loader.js"></script> <script type="text/javascript" src="https://unpkg.com/monaco-editor@latest/min/vs/loader.js"></script>
<script src="{{.Domain}}/_/js/monaco.js"></script> <script src="{{.Domain}}/_/js/monaco.js"></script>