diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2017-09-26 02:50:04 +0200 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2017-09-26 02:50:04 +0200 |
| commit | 3fd5c25226ecaed13687ab59d12b1dbb2a2f1344 (patch) | |
| tree | c0167216a9cc22eadc0907e40aa8b69bee434924 | |
| parent | 4a0b4a5c406e3b9da7d4f10d14ec87c3c173a4db (diff) | |
New Logger
| -rw-r--r-- | log.go | 30 | ||||
| -rw-r--r-- | signup.go | 20 |
2 files changed, 44 insertions, 6 deletions
@@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "time" + "os" +) + +var loud bool = true + +func Log(text string) { + //text := "Test" + f, err := os.OpenFile("loghexfool", os.O_APPEND|os.O_WRONLY, 0600) + if err != nil { + panic(err) + } + + defer f.Close() + full := time.Now().String() + text + if _, err = f.WriteString(full+"\n"); err != nil { + panic(err) + } + if loud { + fmt.Println(full) + } +} + +//func main() { +// Log("test2") +//} @@ -6,7 +6,7 @@ import _ "github.com/go-sql-driver/mysql" import "golang.org/x/crypto/bcrypt" import "net/http" -import "fmt" +//import "fmt" import "os/exec" var db *sql.DB @@ -30,25 +30,30 @@ func signupPage(res http.ResponseWriter, req *http.Request) { hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { http.Error(res, "Server Error creating Password. Unable to create account! You Fool...", 500) + Log("ERROR 500") return } newuuid, uiderr := exec.Command("uuidgen").Output() if uiderr != nil{ http.Error(res, "Server Error creating UUID. Unable to create account! You Fool...", 500) + Log("ERROR 500") return } _, err = db.Exec("INSERT INTO players(username, password, uuid) VALUES(?, ?, ?)", username, hashedPassword, newuuid) if err != nil { http.Error(res, "Server Error Inserting User. Unable to create account! You Fool...", 500) - fmt.Println("Error adding User",username) + Log("ERROR adding user"+username) + //fmt.Println("Error adding User",username) return } res.Write([]byte("User Created Successfully!")) - fmt.Println("Successfully Created User",username,newuuid) + Log("Successfully Created User"+username+string(newuuid)) + //fmt.Println("Successfully Created User",username,newuuid) return case err != nil: http.Error(res, "Server Error! Something fucked up", 500) + Log("ERROR Something fucked up") return default: http.Redirect(res, req, "/", 301) @@ -72,19 +77,22 @@ func loginPage(res http.ResponseWriter, req *http.Request) { if err != nil { http.Redirect(res, req, "/login", 301) - fmt.Println("Failed Login atempt by",username) + Log("Failed Login atempt by "+username) + //fmt.Println("Failed Login atempt by",username) return } err = bcrypt.CompareHashAndPassword([]byte(databasePassword), []byte(password)) if err != nil { http.Redirect(res, req, "/login", 301) - fmt.Println(username," used wrong Password ",password) + Log(username+" used wrong Password "+password) + //fmt.Println(username," used wrong Password ",password) return } res.Write([]byte("Hello "+ databaseUsername + "! Your UUID is "+ databaseUUID)) - fmt.Println("Successful Login by",username) + Log("Successful Login by "+username) + //fmt.Println("Successful Login by",username) } func homePage(res http.ResponseWriter, req *http.Request) { |
