mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 08:59:31 -05:00
WIP: pwdgen, username
This commit is contained in:
parent
85e09a7ada
commit
a20f535211
2 changed files with 38 additions and 5 deletions
1
go.mod
1
go.mod
|
@ -257,6 +257,7 @@ require (
|
||||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/segmentio/asm v1.2.0 // indirect
|
github.com/segmentio/asm v1.2.0 // indirect
|
||||||
|
github.com/sethvargo/go-password v0.2.0 // indirect
|
||||||
github.com/shopspring/decimal v1.3.1 // indirect
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
|
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
ap "github.com/go-ap/activitypub"
|
ap "github.com/go-ap/activitypub"
|
||||||
|
pwd_gen "github.com/sethvargo/go-password/password"
|
||||||
//f3 "lab.forgefriends.org/friendlyforgeformat/gof3"
|
//f3 "lab.forgefriends.org/friendlyforgeformat/gof3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -189,17 +190,29 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
And depending on implementation check if the person already exists in federated user db.
|
And depending on implementation check if the person already exists in federated user db.
|
||||||
*/
|
*/
|
||||||
email, err := generateUUIDMail(person)
|
email, err := generateUUIDMail(person)
|
||||||
username := getUserName(person)
|
if err != nil {
|
||||||
|
fmt.Errorf("Generate user failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
username, err := getUserName(person)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Generate user failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
password, err := generateRandomPassword()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("Generate password failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
user := &user_model.User{
|
user := &user_model.User{
|
||||||
LowerName: username.ToLower(),
|
LowerName: strings.ToLower(username),
|
||||||
Name: username,
|
Name: username,
|
||||||
Email: email,
|
Email: email,
|
||||||
EmailNotificationsPreference: "disabled",
|
EmailNotificationsPreference: "disabled",
|
||||||
Passwd: generateRandomPassword(),
|
Passwd: password,
|
||||||
MustChangePassword: false,
|
MustChangePassword: false,
|
||||||
LoginName: target,
|
LoginName: target,
|
||||||
Type: UserType.UserTypeRemoteUser,
|
Type: user_model.UserTypeRemoteUser,
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +232,6 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle case of count > 1
|
// TODO: handle case of count > 1
|
||||||
|
|
||||||
// execute star action
|
// execute star action
|
||||||
|
|
||||||
// wait 15 sec.
|
// wait 15 sec.
|
||||||
|
@ -238,3 +250,23 @@ func generateUUIDMail(person ap.Actor) (string, error) {
|
||||||
|
|
||||||
return strings.Join([]string{id, host}, "@"), err
|
return strings.Join([]string{id, host}, "@"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserName(person ap.Actor) (string, error) {
|
||||||
|
if name := person.PreferredUsername.String(); name != "" {
|
||||||
|
return name, nil
|
||||||
|
}
|
||||||
|
if name := person.Name.String(); name != "" {
|
||||||
|
return name, nil
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("Empty name, preferredUsername field")
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateRandomPassword() (string, error) {
|
||||||
|
// Generate a password that is 64 characters long with 10 digits, 10 symbols,
|
||||||
|
// allowing upper and lower case letters, disallowing repeat characters.
|
||||||
|
res, err := pwd_gen.Generate(32, 10, 10, false, false)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue