mirror of
https://github.com/moul/sshportal.git
synced 2025-09-09 06:04:34 +08:00
Allow to set the first invite token (for testing)
This commit is contained in:
parent
f97c9f2878
commit
2261d27c94
2 changed files with 7 additions and 2 deletions
7
db.go
7
db.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -183,12 +184,16 @@ func dbInit(db *gorm.DB) error {
|
|||
db.Table("users").Count(&count)
|
||||
if count == 0 {
|
||||
// if no admin, create an account for the first connection
|
||||
inviteToken := RandStringBytes(16)
|
||||
if os.Getenv("SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN") != "" {
|
||||
inviteToken = os.Getenv("SSHPORTAL_DEFAULT_ADMIN_INVITE_TOKEN")
|
||||
}
|
||||
user := User{
|
||||
Name: "Administrator",
|
||||
Email: "admin@sshportal",
|
||||
Comment: "created by sshportal",
|
||||
IsAdmin: true,
|
||||
InviteToken: RandStringBytes(16),
|
||||
InviteToken: inviteToken,
|
||||
Groups: []*UserGroup{&defaultUserGroup},
|
||||
}
|
||||
db.Create(&user)
|
||||
|
|
2
main.go
2
main.go
|
@ -191,7 +191,7 @@ func server(c *cli.Context) error {
|
|||
// handle invite "links"
|
||||
if strings.HasPrefix(username, "invite:") {
|
||||
inputToken := strings.Split(username, ":")[1]
|
||||
if len(inputToken) == 16 {
|
||||
if len(inputToken) > 0 {
|
||||
db.Where("invite_token = ?", inputToken).First(&user)
|
||||
}
|
||||
if user.ID > 0 {
|
||||
|
|
Loading…
Add table
Reference in a new issue