Allow to set the first invite token (for testing)

This commit is contained in:
Manfred Touron 2017-11-15 11:24:48 +01:00
parent f97c9f2878
commit 2261d27c94
2 changed files with 7 additions and 2 deletions

7
db.go
View file

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

View file

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