aboutsummaryrefslogtreecommitdiffstats
path: root/services/mailer/mail_team_invite.go
diff options
context:
space:
mode:
authorJack Hay <jack@allspice.io>2023-08-31 12:26:13 -0400
committerGitHub <noreply@github.com>2023-08-31 16:26:13 +0000
commitc0ab7070e56f1de390d2e7d6a95083137041a572 (patch)
tree8c96429af9c281db82022f61564fa5c7760ddd54 /services/mailer/mail_team_invite.go
parent3cae50e841bf1551d82fe9ae3fe5c88627029c24 (diff)
downloadgitea-c0ab7070e56f1de390d2e7d6a95083137041a572.tar.gz
gitea-c0ab7070e56f1de390d2e7d6a95083137041a572.zip
Update team invitation email link (#26550)
Co-authored-by: Kyle D <kdumontnu@gmail.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
Diffstat (limited to 'services/mailer/mail_team_invite.go')
-rw-r--r--services/mailer/mail_team_invite.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/services/mailer/mail_team_invite.go b/services/mailer/mail_team_invite.go
index b6f47ee921..1403923c79 100644
--- a/services/mailer/mail_team_invite.go
+++ b/services/mailer/mail_team_invite.go
@@ -6,6 +6,8 @@ package mailer
import (
"bytes"
"context"
+ "fmt"
+ "net/url"
org_model "code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
@@ -33,6 +35,22 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod
locale := translation.NewLocale(inviter.Language)
+ // check if a user with this email already exists
+ user, err := user_model.GetUserByEmail(ctx, invite.Email)
+ if err != nil && !user_model.IsErrUserNotExist(err) {
+ return err
+ } else if user != nil && user.ProhibitLogin {
+ return fmt.Errorf("login is prohibited for the invited user")
+ }
+
+ inviteRedirect := url.QueryEscape(fmt.Sprintf("/org/invite/%s", invite.Token))
+ inviteURL := fmt.Sprintf("%suser/sign_up?redirect_to=%s", setting.AppURL, inviteRedirect)
+
+ if err == nil && user != nil {
+ // user account exists
+ inviteURL = fmt.Sprintf("%suser/login?redirect_to=%s", setting.AppURL, inviteRedirect)
+ }
+
subject := locale.Tr("mail.team_invite.subject", inviter.DisplayName(), org.DisplayName())
mailMeta := map[string]any{
"Inviter": inviter,
@@ -40,6 +58,7 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod
"Team": team,
"Invite": invite,
"Subject": subject,
+ "InviteURL": inviteURL,
// helper
"locale": locale,
"Str2html": templates.Str2html,