Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/api/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ func (a *API) createAccountFromExternalIdentity(tx *storage.Connection, r *http.
return nil, terr
}
emailConfirmationSent = true
} else {
// empty email address is regarded as not verified
return nil, apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeEmailNotConfirmed, "No email address provided by %v. Please add a verified email address to your account at %v and try again.", providerType, providerType)
}

if !config.Mailer.AllowUnverifiedEmailSignIns {
Expand Down
5 changes: 5 additions & 0 deletions internal/api/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (a *API) linkIdentityToUser(r *http.Request, ctx context.Context, tx *stora
return nil, terr
}
if !userData.Metadata.EmailVerified {
if targetUser.GetEmail() == "" {
// empty email address is regarded as not verified
return nil, apierrors.NewUnprocessableEntityError(apierrors.ErrorCodeEmailNotConfirmed, "No email address provided by %v. Please add a verified email address to your account at %v and try again.", providerType, providerType)
}

if terr := a.sendConfirmation(r, tx, targetUser, models.ImplicitFlow); terr != nil {
return nil, terr
}
Expand Down
10 changes: 9 additions & 1 deletion internal/api/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,18 @@ func (a *API) sendEmail(r *http.Request, tx *storage.Connection, u *models.User,
externalURL := getExternalHost(ctx)

if emailActionType != mail.EmailChangeVerification {
if u.GetEmail() != "" && !a.checkEmailAddressAuthorization(u.GetEmail()) {
if u.GetEmail() == "" {
return apierrors.NewInternalServerError("Unable to send email to a user with an empty email address")
}

if !a.checkEmailAddressAuthorization(u.GetEmail()) {
return apierrors.NewBadRequestError(apierrors.ErrorCodeEmailAddressNotAuthorized, "Email address %q cannot be used as it is not authorized", u.GetEmail())
}
} else {
if u.EmailChange == "" {
return apierrors.NewInternalServerError("Unable to change email address of user to an empty value")
}

// first check that the user can update their address to the
// new one in u.EmailChange
if u.EmailChange != "" && !a.checkEmailAddressAuthorization(u.EmailChange) {
Expand Down