From e043d7a4772e08ce158645199c7dc14908589e51 Mon Sep 17 00:00:00 2001 From: Nikolaus Gotsche Date: Sat, 30 Sep 2017 01:36:55 +0200 Subject: redis functions renaming --- signup.go | 118 -------------------------------------------------------------- 1 file changed, 118 deletions(-) delete mode 100644 signup.go (limited to 'signup.go') diff --git a/signup.go b/signup.go deleted file mode 100644 index 1285c41..0000000 --- a/signup.go +++ /dev/null @@ -1,118 +0,0 @@ -package main - -import "database/sql" -import _ "github.com/go-sql-driver/mysql" - -import "golang.org/x/crypto/bcrypt" - -import "net/http" -//import "fmt" -import "os/exec" - -var db *sql.DB -var err error - -func signupPage(res http.ResponseWriter, req *http.Request) { - if req.Method != "POST" { - http.ServeFile(res, req, "html/signup.html") - return - } - - username := req.FormValue("username") - password := req.FormValue("password") - - var user string - - err := db.QueryRow("SELECT username FROM players WHERE username=?",username).Scan(&user) - - switch { - case err == sql.ErrNoRows: - 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) - Log("ERROR adding user"+username) - //fmt.Println("Error adding User",username) - return - } - res.Write([]byte("User Created Successfully!")) - 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) - } -} - -func loginPage(res http.ResponseWriter, req *http.Request) { - if req.Method != "POST" { - http.ServeFile(res, req, "html/login.html") - return - } - - username := req.FormValue("username") - password := req.FormValue("password") - - var databaseUsername string - var databasePassword string - var databaseUUID string - - err := db.QueryRow("SELECT username, password, uuid FROM players WHERE username=?", username).Scan(&databaseUsername, &databasePassword, &databaseUUID) - - if err != nil { - http.Redirect(res, req, "/login", 301) - 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) - Log(username+" used wrong Password "+password) - //fmt.Println(username," used wrong Password ",password) - return - } - - res.Write([]byte("Hello "+ databaseUsername + "! Your UUID is "+ databaseUUID)) - Log("Successful Login by "+username) - //fmt.Println("Successful Login by",username) -} - -func homePage(res http.ResponseWriter, req *http.Request) { - http.ServeFile(res, req, "html/index.html") -} - -func main() { - db, err = sql.Open("mysql", "hexmaster:waSIdocHneTdUobeRoarscH@tcp(192.168.0.16)/hexmaster") - if err != nil { - panic(err.Error()) - } - defer db.Close() - - err = db.Ping() - if err != nil { - panic(err.Error()) - } - - http.HandleFunc("/signup", signupPage) - http.HandleFunc("/login", loginPage) - http.HandleFunc("/", homePage) - http.ListenAndServe(":8088", nil) -} -- cgit v1.2.3