diff --git a/README.md b/README.md index 0f99ea1b..2d62f1c0 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,15 @@ go install github.com/go-sql-driver/mysql go install golang.org/x/crypto/bcrypt -go run errors.go main.go pages.go post.go routes.go topic.go user.go utils.go +Tweak the config.go file and put your database details in there. -The last command is run whenever you want to start-up an instance of the software. +# Run the program + +go run errors.go main.go pages.go post.go routes.go topic.go user.go utils.go config.go + +Alternatively, you could run the run.bat batch file on Windows. + # TO-DO @@ -35,6 +40,8 @@ More moderation features. Fix the login system. It broke during the switch in frameworks. +Fix the bug where errors are sent off in raw HTML rather than formatted HTML. + Add an alert system. Add a report feature. diff --git a/src/config.go b/src/config.go new file mode 100644 index 00000000..e9c0d2b7 --- /dev/null +++ b/src/config.go @@ -0,0 +1,6 @@ +package main + +// Database details +var dbuser = "root" +var dbpassword = "password" +var dbname = "grosolo" diff --git a/src/main.go b/src/main.go index 4af13003..d3bb8eb3 100644 --- a/src/main.go +++ b/src/main.go @@ -32,13 +32,10 @@ var custom_pages map[string]string = make(map[string]string) var templates = template.Must(template.ParseGlob("templates/*")) func init_database(err error) { - user := "root" - password := "password" - if(password != ""){ - password = ":" + password + if(dbpassword != ""){ + dbpassword = ":" + dbpassword } - dbname := "grosolo" - db, err = sql.Open("mysql",user + password + "@tcp(127.0.0.1:3306)/" + dbname) + db, err = sql.Open("mysql",dbuser + dbpassword + "@tcp(127.0.0.1:3306)/" + dbname) if err != nil { log.Fatal(err) } diff --git a/src/run.bat b/src/run.bat index 1ec803bf..2ad8939a 100644 --- a/src/run.bat +++ b/src/run.bat @@ -1,2 +1,2 @@ -go run errors.go main.go pages.go post.go routes.go topic.go user.go utils.go +go run errors.go main.go pages.go post.go routes.go topic.go user.go utils.go config.go pause \ No newline at end of file diff --git a/src/user.go b/src/user.go index b20534b3..0d3f0086 100644 --- a/src/user.go +++ b/src/user.go @@ -12,6 +12,7 @@ type User struct Name string Group int Is_Admin bool + Is_Super_Admin bool Session string Loggedin bool } @@ -36,7 +37,7 @@ func SetPassword(uid int, password string) (error) { } func SessionCheck(w http.ResponseWriter, r *http.Request) (User) { - user := User{0,"",0,false,"",false} + user := User{0,"",0,false,false,"",false} var err error var cookie *http.Cookie @@ -60,7 +61,7 @@ func SessionCheck(w http.ResponseWriter, r *http.Request) (User) { log.Print("Session: " + user.Session) // Is this session valid..? - err = get_session_stmt.QueryRow(user.ID,user.Session).Scan(&user.ID, &user.Name, &user.Group, &user.Is_Admin, &user.Session) + err = get_session_stmt.QueryRow(user.ID,user.Session).Scan(&user.ID, &user.Name, &user.Group, &user.Is_Super_Admin, &user.Session) if err == sql.ErrNoRows { log.Print("Couldn't find the user session") return user @@ -68,6 +69,7 @@ func SessionCheck(w http.ResponseWriter, r *http.Request) (User) { log.Print(err) return user } + user.Is_Admin = user.Is_Super_Admin user.Loggedin = true log.Print("Logged in") log.Print("ID: " + strconv.Itoa(user.ID))