Started work on Login

This commit is contained in:
Brian Buller 2015-04-16 17:40:48 -05:00
parent 76cc9b7336
commit afdf09607e
1 changed files with 45 additions and 4 deletions

View File

@ -1,11 +1,14 @@
package util
import (
//"database/sql"
"fmt"
//_ "github.com/mattn/go-sqlite3"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
)
var output_channel chan string
@ -26,12 +29,49 @@ func StartServer(ch chan string) {
func serveMcMan(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, htmlHeader("mc_man - Minecraft Manager"))
fmt.Fprintf(w, "Hey-o! It's the manager!")
the_path := r.URL.Path
output_channel <- the_path
if strings.HasPrefix(the_path, "/login") || the_path == "/" {
fmt.Fprintf(w, loginScreen())
} else if strings.HasPrefix(the_path, "/dologin") {
fmt.Fprintf(w, doLogin(w, r))
}
fmt.Fprintf(w, htmlFooter())
}
func loginScreen() string {
return `
<form action="/doLogin" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit">
</form>
`
}
func doLogin(w http.ResponseWriter, r *http.Request) string {
ret := "Do Login<br />"
ret = ret + r.FormValue("username")
ret = ret + r.FormValue("password")
return ret
/*
//r.F
db, err := sql.Open("sqlite3", "mc_man.db")
if err == nil {
// Error opening the DB, can't log in
return false
}
// rows, err := db.Query("SELECT * FROM USERS")
*/
}
func serveAPI(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
_, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
//body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
if err != nil {
panic(err)
}
@ -41,8 +81,8 @@ func serveAPI(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
// What are we doing with this request?
output_channel <- fmt.Sprint("HTTP Request: (", r.Method, ") ", r.URL, "\n")
the_path = r.URL.Path
output_string = ""
the_path := r.URL.Path
output_string := ""
if strings.HasPrefix(the_path, "/api") {
the_path = strings.TrimPrefix(the_path, "/api")
if strings.HasPrefix(the_path, "/v1") {
@ -54,6 +94,7 @@ func serveAPI(w http.ResponseWriter, r *http.Request) {
}
}
}
fmt.Fprintf(w, output_string)
}
/* JSON Functions */