Made it easier to configure.

Seperated admins from super admins.
This commit is contained in:
Azareal 2016-12-02 08:07:56 +00:00
parent 74ec4ec869
commit 509082fad3
5 changed files with 23 additions and 11 deletions

View File

@ -21,10 +21,15 @@ go install github.com/go-sql-driver/mysql
go install golang.org/x/crypto/bcrypt 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 # TO-DO
@ -35,6 +40,8 @@ More moderation features.
Fix the login system. It broke during the switch in frameworks. 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 an alert system.
Add a report feature. Add a report feature.

6
src/config.go Normal file
View File

@ -0,0 +1,6 @@
package main
// Database details
var dbuser = "root"
var dbpassword = "password"
var dbname = "grosolo"

View File

@ -32,13 +32,10 @@ var custom_pages map[string]string = make(map[string]string)
var templates = template.Must(template.ParseGlob("templates/*")) var templates = template.Must(template.ParseGlob("templates/*"))
func init_database(err error) { func init_database(err error) {
user := "root" if(dbpassword != ""){
password := "password" dbpassword = ":" + dbpassword
if(password != ""){
password = ":" + password
} }
dbname := "grosolo" db, err = sql.Open("mysql",dbuser + dbpassword + "@tcp(127.0.0.1:3306)/" + dbname)
db, err = sql.Open("mysql",user + password + "@tcp(127.0.0.1:3306)/" + dbname)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -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 pause

View File

@ -12,6 +12,7 @@ type User struct
Name string Name string
Group int Group int
Is_Admin bool Is_Admin bool
Is_Super_Admin bool
Session string Session string
Loggedin bool Loggedin bool
} }
@ -36,7 +37,7 @@ func SetPassword(uid int, password string) (error) {
} }
func SessionCheck(w http.ResponseWriter, r *http.Request) (User) { 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 err error
var cookie *http.Cookie var cookie *http.Cookie
@ -60,7 +61,7 @@ func SessionCheck(w http.ResponseWriter, r *http.Request) (User) {
log.Print("Session: " + user.Session) log.Print("Session: " + user.Session)
// Is this session valid..? // 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 { if err == sql.ErrNoRows {
log.Print("Couldn't find the user session") log.Print("Couldn't find the user session")
return user return user
@ -68,6 +69,7 @@ func SessionCheck(w http.ResponseWriter, r *http.Request) (User) {
log.Print(err) log.Print(err)
return user return user
} }
user.Is_Admin = user.Is_Super_Admin
user.Loggedin = true user.Loggedin = true
log.Print("Logged in") log.Print("Logged in")
log.Print("ID: " + strconv.Itoa(user.ID)) log.Print("ID: " + strconv.Itoa(user.ID))