feat: complete registration invitation and auth redesign

This commit is contained in:
richjohnrambo
2026-08-19 00:30:11 +08:00
parent e063e7879e
commit 219ecadf4c
47 changed files with 9014 additions and 224 deletions
+3 -10
View File
@@ -27,7 +27,7 @@ func genDb(data *Data, p2pDel bool, tenantID types.TenantID) {
// Add authentication record
authHandler := store.Store.GetAuthHandler("basic")
authHandler.Init([]byte(`{"add_to_tags": true}`), "basic")
authHandler.Init([]byte(`{"add_to_tags": false}`), "basic")
nameIndex := make(map[string]string, len(data.Users))
@@ -40,12 +40,13 @@ func genDb(data *Data, p2pDel bool, tenantID types.TenantID) {
}
user := types.User{
TenantID: tenantID,
Username: uu.Username,
Phone: uu.Tel,
State: state,
Access: types.DefaultAccess{
Auth: types.ModeCAuth,
Anon: types.ModeNone,
},
Tags: uu.Tags,
Public: parsePublic(&uu.Public, data.datapath),
}
if !uu.Trusted.IsZero() {
@@ -53,14 +54,6 @@ func genDb(data *Data, p2pDel bool, tenantID types.TenantID) {
}
user.CreatedAt = getCreatedTime(uu.CreatedAt)
user.Tags = append(user.Tags, "basic:"+uu.Username)
if uu.Email != "" {
user.Tags = append(user.Tags, "email:"+uu.Email)
}
if uu.Tel != "" {
user.Tags = append(user.Tags, "tel:"+uu.Tel)
}
// store.Users.Create will subscribe user to !me topic but won't create a !me topic
if _, err := store.Users.Create(tenantID, &user, uu.Private); err != nil {
log.Fatal(err)
+3 -3
View File
@@ -321,17 +321,17 @@ func main() {
if userId.IsZero() {
log.Fatalf("Must specify a valid user ID '%s' to promote to ROOT", *makeRoot)
}
login, _, _, _, err := store.Users.GetAuthRecord(tenantID, userId, "basic")
login, _, _, _, err := store.Users.GetAuthRecord(tenantID, userId)
if err != nil {
log.Fatalln("Failed to read user authentication record", err)
}
tenantAdapter, ok := adapter.(interface {
TenantAuthUpdRecord(types.TenantID, types.Uid, string, string, auth.Level, []byte, time.Time) error
TenantAuthUpdateRecord(types.TenantID, types.Uid, string, auth.Level, []byte, time.Time) error
})
if !ok {
log.Fatalln("Configured adapter does not support tenant authentication")
}
if err = tenantAdapter.TenantAuthUpdRecord(tenantID, userId, "basic", "basic:"+login,
if err = tenantAdapter.TenantAuthUpdateRecord(tenantID, userId, login,
auth.LevelRoot, nil, time.Time{}); err != nil {
log.Fatalln("Failed to promote user to ROOT", err)
}