summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2017-09-26 02:50:04 +0200
committerNikolaus Gotsche <n@softwarefools.com>2017-09-26 02:50:04 +0200
commit3fd5c25226ecaed13687ab59d12b1dbb2a2f1344 (patch)
treec0167216a9cc22eadc0907e40aa8b69bee434924
parent4a0b4a5c406e3b9da7d4f10d14ec87c3c173a4db (diff)
New Logger
-rw-r--r--log.go30
-rw-r--r--signup.go20
2 files changed, 44 insertions, 6 deletions
diff --git a/log.go b/log.go
new file mode 100644
index 0000000..365989b
--- /dev/null
+++ b/log.go
@@ -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")
+//}
diff --git a/signup.go b/signup.go
index 43d08fb..1285c41 100644
--- a/signup.go
+++ b/signup.go
@@ -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) {