-
Notifications
You must be signed in to change notification settings - Fork 263
/
init.go
48 lines (42 loc) · 1.21 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package service
import (
"fmt"
"github.com/ixre/go2o/core/domain/interface/registry"
"github.com/ixre/go2o/core/infrastructure/domain"
"github.com/ixre/go2o/core/service/impl"
"github.com/ixre/gof/crypto"
"github.com/ixre/gof/util"
"log"
"strings"
)
/**
* Copyright (C) 2007-2020 56X.NET,All rights reserved.
*
* name : init.go
* author : jarrysix (jarrysix#gmail.com)
* date : 2020-11-14 11:35
* description :
* history :
*/
func sysInit() {
repo := impl.Repos.GetRegistryRepo()
initJWTSecret(repo)
initSuperLoginToken(repo)
}
func initSuperLoginToken(repo registry.IRegistryRepo) {
value, _ := repo.GetValue(registry.SysSuperLoginToken)
if strings.TrimSpace(value) == "" {
pwd := util.RandString(8)
log.Println(fmt.Sprintf("[ Go2o][ Info]: the initial super pwd is '%s', it only show first time. plese save it.", pwd))
token := domain.Sha1("master" + crypto.Md5([]byte(pwd)))
_ = repo.UpdateValue(registry.SysSuperLoginToken, token)
}
}
// 初始化jwt密钥
func initJWTSecret(repo registry.IRegistryRepo) {
value, _ := repo.GetValue(registry.SysJWTSecret)
if strings.TrimSpace(value) == "" {
_, privateKey, _ := crypto.GenRsaKeys(2048)
_ = repo.UpdateValue(registry.SysJWTSecret, privateKey)
}
}