mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
Add Admin account creationg to setup
This commit is contained in:
parent
58b25d1d7e
commit
7197959500
14
setup.go
14
setup.go
|
@ -2,10 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -32,6 +34,14 @@ func Setup() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Sprintf("Problem creating database! %v", err)
|
fmt.Sprintf("Problem creating database! %v", err)
|
||||||
}
|
}
|
||||||
|
// Insert default admin user
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
fmt.Print("Administrator password: ")
|
||||||
|
text, err := reader.ReadString('\n')
|
||||||
|
|
||||||
|
hash, err := bcrypt.GenerateFromPassword(text)
|
||||||
|
|
||||||
|
_, err = db.Exec("INSERT INTO users(id,username,hash,realname,email,permissions) VALUES (0,`admin`,?,`Administrator`,`admin@localhost`,2", hash)
|
||||||
|
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
|
@ -79,11 +89,11 @@ func Setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func LockFile() {
|
func LockFile() {
|
||||||
lock, err := os.Create("run.lockfile")
|
lock, err := os.Create(".lock")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error: %v", err)
|
fmt.Println("Error: %v", err)
|
||||||
}
|
}
|
||||||
lock.Write([]byte("# You can leave this file emtpy, it simply tells Pogo you're set up!"))
|
lock.Write([]byte("This file left intentionally empty"))
|
||||||
defer lock.Close()
|
defer lock.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,16 @@ import (
|
||||||
"github.com/gmemstr/pogo/router"
|
"github.com/gmemstr/pogo/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetPogoVersion() {
|
||||||
|
return "2.0.0"
|
||||||
|
}
|
||||||
|
|
||||||
// Main function that defines routes
|
// Main function that defines routes
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Check if this is the first time Pogo has been run
|
// Check if this is the first time Pogo has been run
|
||||||
// with a lockfile
|
// with a lockfile
|
||||||
|
if _, err := os.Stat(".lock"); os.IsNotExist(err) {
|
||||||
if _, err := os.Stat("run.lockfile"); os.IsNotExist(err) {
|
|
||||||
fmt.Println("This looks like your first time running Pogo,\ngive me a second to set myself up.")
|
fmt.Println("This looks like your first time running Pogo,\ngive me a second to set myself up.")
|
||||||
Setup()
|
Setup()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue