mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-04 10:03:11 +03:00
use const for key values
This commit is contained in:
parent
c05bad8d41
commit
172c39f781
1 changed files with 10 additions and 5 deletions
|
@ -8,25 +8,30 @@ import (
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
userActivitypubPrivpem = "activitypub_privpem"
|
||||||
|
userActivitypubPubpem = "activitypub_pubpem"
|
||||||
|
)
|
||||||
|
|
||||||
// GetKeyPair function
|
// GetKeyPair function
|
||||||
func GetKeyPair(user *user_model.User) (pub, priv string, err error) {
|
func GetKeyPair(user *user_model.User) (pub, priv string, err error) {
|
||||||
var settings map[string]*user_model.Setting
|
var settings map[string]*user_model.Setting
|
||||||
if settings, err = user_model.GetUserSettings(user.ID, []string{"activitypub_privpem", "activitypub_pubpem"}); err != nil {
|
if settings, err = user_model.GetUserSettings(user.ID, []string{userActivitypubPrivpem, userActivitypubPubpem}); err != nil {
|
||||||
return
|
return
|
||||||
} else if len(settings) == 0 {
|
} else if len(settings) == 0 {
|
||||||
if priv, pub, err = GenerateKeyPair(); err != nil {
|
if priv, pub, err = GenerateKeyPair(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = user_model.SetUserSetting(user.ID, "activitypub_privpem", priv); err != nil {
|
if err = user_model.SetUserSetting(user.ID, userActivitypubPrivpem, priv); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = user_model.SetUserSetting(user.ID, "activitypub_pubpem", pub); err != nil {
|
if err = user_model.SetUserSetting(user.ID, userActivitypubPubpem, pub); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
priv = settings["activitypub_privpem"].SettingValue
|
priv = settings[userActivitypubPrivpem].SettingValue
|
||||||
pub = settings["activitypub_pubpem"].SettingValue
|
pub = settings[userActivitypubPubpem].SettingValue
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue