mirror of
https://github.com/moul/sshportal.git
synced 2024-11-10 09:12:49 +08:00
The default created user now has the same username as the user starting sshportal (was hardcoded admin)
This commit is contained in:
parent
ed42f343d2
commit
b23ee4144d
2 changed files with 16 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
## master (unreleased)
|
||||
|
||||
* No entry
|
||||
* The default created user now has the same username as the user starting sshportal (was hardcoded "admin")
|
||||
|
||||
## v1.7.1 (2018-01-03)
|
||||
|
||||
|
|
17
dbinit.go
17
dbinit.go
|
@ -5,6 +5,8 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-gormigrate/gormigrate"
|
||||
|
@ -522,9 +524,20 @@ func dbInit(db *gorm.DB) error {
|
|||
if err := db.Where("name = ?", "admin").First(&adminRole).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var username string
|
||||
if currentUser, err := user.Current(); err == nil {
|
||||
username = currentUser.Username
|
||||
}
|
||||
if username == "" {
|
||||
username = os.Getenv("USER")
|
||||
}
|
||||
username = strings.ToLower(username)
|
||||
if username == "" {
|
||||
username = "admin" // fallback username
|
||||
}
|
||||
user := User{
|
||||
Name: "admin",
|
||||
Email: "admin@sshportal",
|
||||
Name: username,
|
||||
Email: fmt.Sprintf("%s@localhost", username),
|
||||
Comment: "created by sshportal",
|
||||
Roles: []*UserRole{&adminRole},
|
||||
InviteToken: inviteToken,
|
||||
|
|
Loading…
Reference in a new issue