Compare commits
1 commit
main
...
s7evink/te
Author | SHA1 | Date | |
---|---|---|---|
97e7edce5f |
|
@ -167,6 +167,7 @@ type UserRoomserverAPI interface {
|
||||||
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
QueryCurrentState(ctx context.Context, req *QueryCurrentStateRequest, res *QueryCurrentStateResponse) error
|
||||||
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
QueryMembershipsForRoom(ctx context.Context, req *QueryMembershipsForRoomRequest, res *QueryMembershipsForRoomResponse) error
|
||||||
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
|
PerformAdminEvacuateUser(ctx context.Context, req *PerformAdminEvacuateUserRequest, res *PerformAdminEvacuateUserResponse) error
|
||||||
|
PerformJoin(ctx context.Context, req *PerformJoinRequest, res *PerformJoinResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type FederationRoomserverAPI interface {
|
type FederationRoomserverAPI interface {
|
||||||
|
|
|
@ -19,6 +19,10 @@ type UserAPI struct {
|
||||||
// The Account database stores the login details and account information
|
// The Account database stores the login details and account information
|
||||||
// for local users. It is accessed by the UserAPI.
|
// for local users. It is accessed by the UserAPI.
|
||||||
AccountDatabase DatabaseOptions `yaml:"account_database,omitempty"`
|
AccountDatabase DatabaseOptions `yaml:"account_database,omitempty"`
|
||||||
|
|
||||||
|
// Users who register on this homeserver will automatically
|
||||||
|
// be joined to the rooms listed under this option.
|
||||||
|
AutoJoinRooms []string `yaml:"auto_join_rooms"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultOpenIDTokenLifetimeMS = 3600000 // 60 minutes
|
const DefaultOpenIDTokenLifetimeMS = 3600000 // 60 minutes
|
||||||
|
|
|
@ -54,6 +54,7 @@ type UserInternalAPI struct {
|
||||||
KeyAPI keyapi.UserKeyAPI
|
KeyAPI keyapi.UserKeyAPI
|
||||||
RSAPI rsapi.UserRoomserverAPI
|
RSAPI rsapi.UserRoomserverAPI
|
||||||
PgClient pushgateway.Client
|
PgClient pushgateway.Client
|
||||||
|
Cfg *config.UserAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *UserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error {
|
func (a *UserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error {
|
||||||
|
@ -174,11 +175,53 @@ func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.P
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postRegisterJoinRooms(a.Cfg, acc, a.RSAPI)
|
||||||
|
|
||||||
res.AccountCreated = true
|
res.AccountCreated = true
|
||||||
res.Account = acc
|
res.Account = acc
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func postRegisterJoinRooms(cfg *config.UserAPI, acc *api.Account, rsAPI rsapi.UserRoomserverAPI) {
|
||||||
|
// POST register behaviour: check if the user is a normal user.
|
||||||
|
// If the user is a normal user, add user to room specified in the configuration "auto_join_rooms".
|
||||||
|
if acc.AccountType != api.AccountTypeAppService && acc.AppServiceID == "" {
|
||||||
|
for room := range cfg.AutoJoinRooms {
|
||||||
|
userID := userutil.MakeUserID(acc.Localpart, cfg.Matrix.ServerName)
|
||||||
|
err := addUserToRoom(context.Background(), rsAPI, cfg.AutoJoinRooms[room], acc.Localpart, userID)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"user_id": userID,
|
||||||
|
"room": cfg.AutoJoinRooms[room],
|
||||||
|
}).WithError(err).Errorf("user failed to auto-join room")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add user to a room. This function currently working for auto_join_rooms config,
|
||||||
|
// which can add a newly registered user to a specified room.
|
||||||
|
func addUserToRoom(
|
||||||
|
ctx context.Context,
|
||||||
|
rsAPI rsapi.UserRoomserverAPI,
|
||||||
|
roomID string,
|
||||||
|
username string,
|
||||||
|
userID string,
|
||||||
|
) error {
|
||||||
|
addGroupContent := make(map[string]interface{})
|
||||||
|
// This make sure the user's username can be displayed correctly.
|
||||||
|
// Because the newly-registered user doesn't have an avatar,
|
||||||
|
// the avatar_url is not needed.
|
||||||
|
addGroupContent["displayname"] = username
|
||||||
|
joinReq := rsapi.PerformJoinRequest{
|
||||||
|
RoomIDOrAlias: roomID,
|
||||||
|
UserID: userID,
|
||||||
|
Content: addGroupContent,
|
||||||
|
}
|
||||||
|
joinRes := rsapi.PerformJoinResponse{}
|
||||||
|
return rsAPI.PerformJoin(ctx, &joinReq, &joinRes)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *UserInternalAPI) PerformPasswordUpdate(ctx context.Context, req *api.PerformPasswordUpdateRequest, res *api.PerformPasswordUpdateResponse) error {
|
func (a *UserInternalAPI) PerformPasswordUpdate(ctx context.Context, req *api.PerformPasswordUpdateRequest, res *api.PerformPasswordUpdateResponse) error {
|
||||||
if err := a.DB.SetPassword(ctx, req.Localpart, req.Password); err != nil {
|
if err := a.DB.SetPassword(ctx, req.Localpart, req.Password); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -82,6 +82,7 @@ func NewInternalAPI(
|
||||||
RSAPI: rsAPI,
|
RSAPI: rsAPI,
|
||||||
DisableTLSValidation: cfg.PushGatewayDisableTLSValidation,
|
DisableTLSValidation: cfg.PushGatewayDisableTLSValidation,
|
||||||
PgClient: pgClient,
|
PgClient: pgClient,
|
||||||
|
Cfg: cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
receiptConsumer := consumers.NewOutputReceiptEventConsumer(
|
receiptConsumer := consumers.NewOutputReceiptEventConsumer(
|
||||||
|
|
Loading…
Reference in a new issue