1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 00:50:12 +00:00

form: fix contact details/profile application when using email

confirmation

my rewrite of account-creation stuff had a massive oversight of email
confirmation, the steps done after account creation (email and contact
method storage, referral stuff) were not done on the email confirmation
path. This has been factored out to PostNewUserFromIvnite, and the
ConfirmationKeys store now includes the newUserDTO and the list of
completeContactMethods.
This commit is contained in:
Harvey Tindall 2024-10-11 16:38:19 +01:00
parent 71922212d9
commit ea57d657fe
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 53 additions and 34 deletions

View File

@ -110,11 +110,7 @@ func (app *appContext) NewUserFromInvite(gc *gin.Context) {
gc.JSON(200, validation) gc.JSON(200, validation)
return return
} }
completeContactMethods := make([]struct { completeContactMethods := make([]ContactMethodKey, len(app.contactMethods))
Verified bool
PIN string
User ContactMethodUser
}, len(app.contactMethods))
for i, cm := range app.contactMethods { for i, cm := range app.contactMethods {
completeContactMethods[i].PIN = cm.PIN(req) completeContactMethods[i].PIN = cm.PIN(req)
if completeContactMethods[i].PIN == "" { if completeContactMethods[i].PIN == "" {
@ -168,13 +164,16 @@ func (app *appContext) NewUserFromInvite(gc *gin.Context) {
return return
} }
if app.ConfirmationKeys == nil { if app.ConfirmationKeys == nil {
app.ConfirmationKeys = map[string]map[string]newUserDTO{} app.ConfirmationKeys = map[string]map[string]ConfirmationKey{}
} }
cKeys, ok := app.ConfirmationKeys[req.Code] cKeys, ok := app.ConfirmationKeys[req.Code]
if !ok { if !ok {
cKeys = map[string]newUserDTO{} cKeys = map[string]ConfirmationKey{}
}
cKeys[key] = ConfirmationKey{
newUserDTO: req,
completeContactMethods: completeContactMethods,
} }
cKeys[key] = req
app.confirmationKeysLock.Lock() app.confirmationKeysLock.Lock()
app.ConfirmationKeys[req.Code] = cKeys app.ConfirmationKeys[req.Code] = cKeys
app.confirmationKeysLock.Unlock() app.confirmationKeysLock.Unlock()
@ -223,10 +222,32 @@ func (app *appContext) NewUserFromInvite(gc *gin.Context) {
} }
app.checkInvite(req.Code, true, req.Username) app.checkInvite(req.Code, true, req.Username)
app.PostNewUserFromInvite(nu, ConfirmationKey{newUserDTO: req, completeContactMethods: completeContactMethods}, profile, invite)
/*responseFunc, logFunc, success := app.NewUser(req, false, gc)
if !success {
logFunc()
responseFunc(gc)
return
}*/
code := 200
for _, val := range validation {
if !val {
code = 400
}
}
gc.JSON(code, validation)
// These don't need to complete anytime soon
// wg.Wait()
}
// PostNewUserFromInvite attaches user details (e.g. contact method details) to a new user once they've been created from an invite.
func (app *appContext) PostNewUserFromInvite(nu NewUserData, req ConfirmationKey, profile *Profile, invite Invite) {
nonEmailContactMethodEnabled := false nonEmailContactMethodEnabled := false
for i, c := range completeContactMethods { for i, c := range req.completeContactMethods {
if c.Verified { if c.Verified {
c.User.SetAllowContactFromDTO(req) c.User.SetAllowContactFromDTO(req.newUserDTO)
if c.User.AllowContact() { if c.User.AllowContact() {
nonEmailContactMethodEnabled = true nonEmailContactMethodEnabled = true
} }
@ -308,12 +329,12 @@ func (app *appContext) NewUserFromInvite(gc *gin.Context) {
// FIXME: figure these out in a nicer way? this relies on the current ordering, // FIXME: figure these out in a nicer way? this relies on the current ordering,
// which may not be fixed. // which may not be fixed.
if discordEnabled { if discordEnabled {
discordUser = completeContactMethods[0].User.(*DiscordUser) discordUser = req.completeContactMethods[0].User.(*DiscordUser)
if telegramEnabled { if telegramEnabled {
telegramUser = completeContactMethods[1].User.(*TelegramUser) telegramUser = req.completeContactMethods[1].User.(*TelegramUser)
} }
} else if telegramEnabled { } else if telegramEnabled {
telegramUser = completeContactMethods[0].User.(*TelegramUser) telegramUser = req.completeContactMethods[0].User.(*TelegramUser)
} }
} }
@ -322,30 +343,13 @@ func (app *appContext) NewUserFromInvite(gc *gin.Context) {
continue continue
} }
// User already created, now we can link contact methods // User already created, now we can link contact methods
err := tps.AddContactMethods(nu.User.ID, req, discordUser, telegramUser) err := tps.AddContactMethods(nu.User.ID, req.newUserDTO, discordUser, telegramUser)
if err != nil { if err != nil {
app.err.Printf(lm.FailedSyncContactMethods, tps.Name(), err) app.err.Printf(lm.FailedSyncContactMethods, tps.Name(), err)
} }
} }
app.WelcomeNewUser(nu.User, expiry) app.WelcomeNewUser(nu.User, expiry)
/*responseFunc, logFunc, success := app.NewUser(req, false, gc)
if !success {
logFunc()
responseFunc(gc)
return
}*/
code := 200
for _, val := range validation {
if !val {
code = 400
}
}
gc.JSON(code, validation)
// These don't need to complete anytime soon
// wg.Wait()
} }
// @Summary Enable/Disable a list of users, optionally notifying them why. // @Summary Enable/Disable a list of users, optionally notifying them why.

View File

@ -132,7 +132,7 @@ type appContext struct {
proxyConfig easyproxy.ProxyConfig proxyConfig easyproxy.ProxyConfig
internalPWRs map[string]InternalPWR internalPWRs map[string]InternalPWR
pwrCaptchas map[string]Captcha pwrCaptchas map[string]Captcha
ConfirmationKeys map[string]map[string]newUserDTO // Map of invite code to jwt to request ConfirmationKeys map[string]map[string]ConfirmationKey // Map of invite code to jwt to request
confirmationKeysLock sync.Mutex confirmationKeysLock sync.Mutex
} }

View File

@ -455,3 +455,14 @@ type CreateBackupDTO struct {
type GetBackupsDTO struct { type GetBackupsDTO struct {
Backups []CreateBackupDTO `json:"backups"` Backups []CreateBackupDTO `json:"backups"`
} }
type ConfirmationKey struct {
newUserDTO
completeContactMethods []ContactMethodKey
}
type ContactMethodKey struct {
Verified bool
PIN string
User ContactMethodUser
}

View File

@ -624,7 +624,7 @@ func (app *appContext) NewUserFromConfirmationKey(invite Invite, key string, lan
"contactMessage": app.config.Section("ui").Key("contact_message").String(), "contactMessage": app.config.Section("ui").Key("contact_message").String(),
}) })
} }
var req newUserDTO var req ConfirmationKey
if app.ConfirmationKeys == nil { if app.ConfirmationKeys == nil {
fail() fail()
return return
@ -666,8 +666,10 @@ func (app *appContext) NewUserFromConfirmationKey(invite Invite, key string, lan
profile = &p profile = &p
} }
// FIXME: Email and contract method linking?????
nu /*wg*/, _ := app.NewUserPostVerification(NewUserParams{ nu /*wg*/, _ := app.NewUserPostVerification(NewUserParams{
Req: req, Req: req.newUserDTO,
SourceType: sourceType, SourceType: sourceType,
Source: source, Source: source,
ContextForIPLogging: gc, ContextForIPLogging: gc,
@ -683,6 +685,8 @@ func (app *appContext) NewUserFromConfirmationKey(invite Invite, key string, lan
} }
app.checkInvite(req.Code, true, req.Username) app.checkInvite(req.Code, true, req.Username)
app.PostNewUserFromInvite(nu, req, profile, invite)
jfLink := app.config.Section("ui").Key("redirect_url").String() jfLink := app.config.Section("ui").Key("redirect_url").String()
if app.config.Section("ui").Key("auto_redirect").MustBool(false) { if app.config.Section("ui").Key("auto_redirect").MustBool(false) {
gc.Redirect(301, jfLink) gc.Redirect(301, jfLink)