2018-10-27 03:21:02 +00:00
|
|
|
package install
|
2017-01-10 06:51:28 +00:00
|
|
|
|
2017-06-06 08:47:33 +00:00
|
|
|
import (
|
2017-09-03 04:50:31 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-03-24 02:07:30 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2017-06-06 08:47:33 +00:00
|
|
|
)
|
2017-01-10 06:51:28 +00:00
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
var adapters = make(map[string]InstallAdapter)
|
|
|
|
|
|
|
|
type InstallAdapter interface {
|
|
|
|
Name() string
|
|
|
|
DefaultPort() string
|
2020-03-24 02:07:30 +00:00
|
|
|
SetConfig(dbHost, dbUsername, dbPassword, dbName, dbPort string)
|
2018-10-27 03:21:02 +00:00
|
|
|
InitDatabase() error
|
|
|
|
TableDefs() error
|
|
|
|
InitialData() error
|
|
|
|
CreateAdmin() error
|
|
|
|
|
|
|
|
DBHost() string
|
|
|
|
DBUsername() string
|
|
|
|
DBPassword() string
|
|
|
|
DBName() string
|
|
|
|
DBPort() string
|
2017-01-10 06:51:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
func Lookup(name string) (InstallAdapter, bool) {
|
|
|
|
adap, ok := adapters[name]
|
|
|
|
return adap, ok
|
2017-10-14 07:39:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
func createAdmin() error {
|
|
|
|
fmt.Println("Creating the admin user")
|
2021-04-07 14:23:11 +00:00
|
|
|
hashedPassword, salt, e := BcryptGeneratePassword("password")
|
|
|
|
if e != nil {
|
|
|
|
return e
|
2017-01-12 02:55:08 +00:00
|
|
|
}
|
2017-01-10 06:51:28 +00:00
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
// Build the admin user query
|
2021-04-07 14:23:11 +00:00
|
|
|
adminUserStmt, e := qgen.Builder.SimpleInsert("users", "name, password, salt, email, group, is_super_admin, active, createdAt, lastActiveAt, lastLiked, oldestItemLikedCreatedAt, message, last_ip", "'Admin',?,?,'admin@localhost',1,1,1,UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),'',''")
|
|
|
|
if e != nil {
|
|
|
|
return e
|
2017-01-10 06:51:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
// Run the admin user query
|
2021-04-07 14:23:11 +00:00
|
|
|
_, e = adminUserStmt.Exec(hashedPassword, salt)
|
|
|
|
return e
|
2017-06-06 08:47:33 +00:00
|
|
|
}
|