MCPcopy Create free account
hub / github.com/daodst/chat / PerformAccountCreation

Method PerformAccountCreation

userapi/internal/api.go:91–138  ·  view source on GitHub ↗
(ctx context.Context, req *api.PerformAccountCreationRequest, res *api.PerformAccountCreationResponse)

Source from the content-addressed store, hash-verified

89}
90
91func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.PerformAccountCreationRequest, res *api.PerformAccountCreationResponse) error {
92 acc, err := a.DB.CreateAccount(ctx, req.Localpart, req.Password, req.AppServiceID, req.AccountType)
93 if err != nil {
94 if errors.Is(err, sqlutil.ErrUserExists) { // This account already exists
95 switch req.OnConflict {
96 case api.ConflictUpdate:
97 break
98 case api.ConflictAbort:
99 return &api.ErrorConflict{
100 Message: err.Error(),
101 }
102 }
103 }
104 // account already exists
105 res.AccountCreated = false
106 res.Account = &api.Account{
107 AppServiceID: req.AppServiceID,
108 Localpart: req.Localpart,
109 ServerName: a.ServerName,
110 UserID: fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName),
111 AccountType: req.AccountType,
112 }
113 return nil
114 }
115
116 // Inform the SyncAPI about the newly created push_rules
117 if err = a.SyncProducer.SendAccountData(acc.UserID, eventutil.AccountData{
118 Type: "m.push_rules",
119 }); err != nil {
120 util.GetLogger(ctx).WithFields(logrus.Fields{
121 "user_id": acc.UserID,
122 }).WithError(err).Warn("failed to send account data to the SyncAPI")
123 }
124
125 if req.AccountType == api.AccountTypeGuest {
126 res.AccountCreated = true
127 res.Account = acc
128 return nil
129 }
130
131 if err = a.DB.SetDisplayName(ctx, req.Localpart, req.Localpart); err != nil {
132 return err
133 }
134
135 res.AccountCreated = true
136 res.Account = acc
137 return nil
138}
139
140func (a *UserInternalAPI) PerformPasswordUpdate(ctx context.Context, req *api.PerformPasswordUpdateRequest, res *api.PerformPasswordUpdateResponse) error {
141 if err := a.DB.SetPassword(ctx, req.Localpart, req.Password); err != nil {

Callers

nothing calls this directly

Calls 3

SendAccountDataMethod · 0.80
SetDisplayNameMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected