Functional web interface
This commit is contained in:
@@ -1,71 +0,0 @@
|
|||||||
/* http://meyerweb.com/eric/tools/css/reset/
|
|
||||||
v2.0 | 20110126
|
|
||||||
License: none (public domain)
|
|
||||||
*/
|
|
||||||
|
|
||||||
html, body, div, span, applet, object, iframe,
|
|
||||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
|
||||||
a, abbr, acronym, address, big, cite, code,
|
|
||||||
del, dfn, em, img, ins, kbd, q, s, samp,
|
|
||||||
small, strike, strong, sub, sup, tt, var,
|
|
||||||
b, u, i, center,
|
|
||||||
dl, dt, dd, ol, ul, li,
|
|
||||||
fieldset, form, label, legend,
|
|
||||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
|
||||||
article, aside, canvas, details, embed,
|
|
||||||
figure, figcaption, footer, header, hgroup,
|
|
||||||
menu, nav, output, ruby, section, summary,
|
|
||||||
time, mark, audio, video {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
border: 0;
|
|
||||||
font-size: 100%;
|
|
||||||
font: inherit;
|
|
||||||
vertical-align: baseline;
|
|
||||||
}
|
|
||||||
/* HTML5 display-role reset for older browsers */
|
|
||||||
article, aside, details, figcaption, figure,
|
|
||||||
footer, header, hgroup, menu, nav, section {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
ol, ul {
|
|
||||||
list-style: none;
|
|
||||||
}
|
|
||||||
blockquote, q {
|
|
||||||
quotes: none;
|
|
||||||
}
|
|
||||||
blockquote:before, blockquote:after,
|
|
||||||
q:before, q:after {
|
|
||||||
content: '';
|
|
||||||
content: none;
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
border-spacing: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-size: 13px;
|
|
||||||
font-family: 'Open Sans', sans-serif;
|
|
||||||
padding: 0 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
|
||||||
padding: 30px 0;
|
|
||||||
font-size: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
header h1 {
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{{ define "footer" }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- /.container -->
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
{{ end }}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{{ define "base" }}
|
{{ define "header" }}
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
@@ -14,6 +14,11 @@
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
padding-top: 50px;
|
padding-top: 50px;
|
||||||
|
}
|
||||||
|
.vcenter {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
float: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
@@ -46,17 +51,9 @@
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="container-fluid">
|
||||||
<div class="starter-template">
|
|
||||||
<h1>Gidbig</h1>
|
<h1>Gidbig</h1>
|
||||||
<p class="lead">{{ template "content" . }}</p>
|
<p class="lead">{{ template "sessionHandler" . }}</p>
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<!-- /.container -->
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
{{ define "content" }}
|
{{ define "sessionHandler" }}
|
||||||
<a href="/discordLogin">Login with Discord</a>
|
<a href="/discordLogin">Login with Discord</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{{ define "content" }}
|
{{ define "sessionHandler" }}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function playSound() {
|
function playSound(cmd, sndnm) {
|
||||||
var data = {
|
var data = {
|
||||||
command: "!bsth",
|
command: cmd,
|
||||||
soundname: "unmoeglich"
|
soundname: sndnm
|
||||||
};
|
};
|
||||||
$.post("/playsound", data, function(data, success) {});
|
$.post("/playsound", data, function(data, success) {});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<a href="/logout">Logout</a><br/>
|
<a href="/logout">Logout</a><br/>
|
||||||
<a href="javascript:playSound()">Play sound</a> {{ end }}
|
{{ end }}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<div class="row">
|
||||||
|
{{ range . }}
|
||||||
|
<div class="col-sm-3 text-center">{{ .Itemtext }}<br/><a class="btn btn-primary" href="javascript:playSound('{{ .Itemcommand }}', '{{ .Itemsoundname }}')" role="button">Play!</a></div>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
+48
-7
@@ -14,7 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultLayout = "templates/layout.html"
|
header = "templates/header.html"
|
||||||
|
footer = "templates/footer.html"
|
||||||
templateDir = "templates/"
|
templateDir = "templates/"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,10 +38,17 @@ var (
|
|||||||
store *sessions.CookieStore
|
store *sessions.CookieStore
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SoundItem struct {
|
||||||
|
Itemcommand string
|
||||||
|
Itemsoundname string
|
||||||
|
Itemtext string
|
||||||
|
}
|
||||||
|
|
||||||
// startWebServer
|
// startWebServer
|
||||||
func startWebServer(port string, ci string, cs string, redirectURL string) {
|
func startWebServer(port string, ci string, cs string, redirectURL string) {
|
||||||
tmpls["home.html"] = template.Must(template.ParseFiles(templateDir+"home.html", defaultLayout))
|
tmpls["home.html"] = template.Must(template.ParseFiles(templateDir+"home.html", header, footer))
|
||||||
tmpls["internal.html"] = template.Must(template.ParseFiles(templateDir+"internal.html", defaultLayout))
|
tmpls["internal.html"] = template.Must(template.ParseFiles(templateDir+"internal.html", header, footer))
|
||||||
|
tmpls["itemrow.html"] = template.Must(template.ParseFiles(templateDir + "itemrow.html"))
|
||||||
store = sessions.NewCookieStore([]byte(cs))
|
store = sessions.NewCookieStore([]byte(cs))
|
||||||
discordOauthConfig.ClientID = ci
|
discordOauthConfig.ClientID = ci
|
||||||
discordOauthConfig.ClientSecret = cs
|
discordOauthConfig.ClientSecret = cs
|
||||||
@@ -52,8 +60,6 @@ func startWebServer(port string, ci string, cs string, redirectURL string) {
|
|||||||
r.HandleFunc("/discordLogin", handlediscordLogin)
|
r.HandleFunc("/discordLogin", handlediscordLogin)
|
||||||
r.HandleFunc("/discordCallback", handlediscordCallback)
|
r.HandleFunc("/discordCallback", handlediscordCallback)
|
||||||
r.HandleFunc("/playsound", handlePlaySound)
|
r.HandleFunc("/playsound", handlePlaySound)
|
||||||
|
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
http.ListenAndServe(":"+port, nil)
|
http.ListenAndServe(":"+port, nil)
|
||||||
}
|
}
|
||||||
@@ -79,10 +85,45 @@ func handlePlaySound(w http.ResponseWriter, r *http.Request) {
|
|||||||
func handleMain(w http.ResponseWriter, r *http.Request) {
|
func handleMain(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := store.Get(r, "session-name")
|
session, _ := store.Get(r, "session-name")
|
||||||
if session.Values["discordUsername"] != nil {
|
if session.Values["discordUsername"] != nil {
|
||||||
tmpls["internal.html"].ExecuteTemplate(w, "base", map[string]interface{}{})
|
err := tmpls["internal.html"].ExecuteTemplate(w, "header", map[string]interface{}{})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmpls["home.html"].ExecuteTemplate(w, "base", map[string]interface{}{})
|
var si [4]SoundItem
|
||||||
|
cnt := 0
|
||||||
|
for _, sc := range COLLECTIONS {
|
||||||
|
for _, snd := range sc.Sounds {
|
||||||
|
si[cnt%4].Itemcommand = "!" + sc.Prefix
|
||||||
|
si[cnt%4].Itemsoundname = snd.Name
|
||||||
|
si[cnt%4].Itemtext = si[cnt%4].Itemcommand + " " + si[cnt%4].Itemsoundname
|
||||||
|
if cnt != 0 && cnt%4 == 3 {
|
||||||
|
err = tmpls["itemrow.html"].Execute(w, si)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cnt++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cnt%4 != 0 {
|
||||||
|
err = tmpls["itemrow.html"].Execute(w, si)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tmpls["internal.html"].ExecuteTemplate(w, "footer", map[string]interface{}{})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tmpls["home.html"].ExecuteTemplate(w, "header", map[string]interface{}{})
|
||||||
|
tmpls["home.html"].ExecuteTemplate(w, "footer", map[string]interface{}{})
|
||||||
}
|
}
|
||||||
func handleLogout(w http.ResponseWriter, r *http.Request) {
|
func handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||||
cookie := &http.Cookie{
|
cookie := &http.Cookie{
|
||||||
|
|||||||
Reference in New Issue
Block a user