Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update team invitation email link #26550

Merged
merged 22 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c220423
update url for email invitation
jackHay22 Aug 16, 2023
4b4b030
Merge branch 'main' into jh/feat-email-invite-link
kdumontnu Aug 21, 2023
80dc1bc
Merge branch 'main' into jh/feat-email-invite-link
jackHay22 Aug 22, 2023
35c0deb
return error for user with prohibited login
jackHay22 Aug 23, 2023
9f18774
Merge branch 'main' into jh/feat-email-invite-link
jackHay22 Aug 23, 2023
4aa72a1
Check that user is not nil before ProhibitLogin
jackHay22 Aug 23, 2023
d55a191
Merge branch 'main' into jh/feat-email-invite-link
kdumontnu Aug 24, 2023
b947704
Merge branch 'main' into jh/feat-email-invite-link
GiteaBot Aug 24, 2023
743dbc8
Merge branch 'main' into jh/feat-email-invite-link
GiteaBot Aug 24, 2023
68c58ac
Merge branch 'main' into jh/feat-email-invite-link
GiteaBot Aug 24, 2023
61bf1e7
account activation should obey the redirect cookie
jackHay22 Aug 24, 2023
27d8590
signup -> login redirect should use redirect_to if available
jackHay22 Aug 24, 2023
3e6edfe
Merge branch 'main' into jh/feat-email-invite-link
jackHay22 Aug 24, 2023
079febe
update comment
jackHay22 Aug 24, 2023
f6be26e
add integration tests for login and sign up redirects
jackHay22 Aug 30, 2023
a3f1dee
linting fix
jackHay22 Aug 30, 2023
472ba2f
add more integration tests for invites
jackHay22 Aug 30, 2023
ebab62c
Merge branch 'main' into jh/feat-email-invite-link
jackHay22 Aug 30, 2023
6846f4e
cleanup
jackHay22 Aug 30, 2023
9de9041
construct invite url outside of template
jackHay22 Aug 31, 2023
3453d5b
Merge branch 'main' into jh/feat-email-invite-link
kdumontnu Aug 31, 2023
bbf905b
Merge branch 'main' into jh/feat-email-invite-link
GiteaBot Aug 31, 2023
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
5 changes: 5 additions & 0 deletions routers/web/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ func SignUp(ctx *context.Context) {
// Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration

redirectTo := ctx.FormString("redirect_to")
if len(redirectTo) > 0 {
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
}

ctx.HTML(http.StatusOK, tplSignUp)
}

Expand Down
13 changes: 13 additions & 0 deletions services/mailer/mail_team_invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package mailer
import (
"bytes"
"context"
"fmt"

org_model "code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -33,13 +34,25 @@ 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")
}

userAccountExists := err == nil && user != nil
lunny marked this conversation as resolved.
Show resolved Hide resolved

subject := locale.Tr("mail.team_invite.subject", inviter.DisplayName(), org.DisplayName())
mailMeta := map[string]any{
"Inviter": inviter,
"Organization": org,
"Team": team,
"Invite": invite,
"Subject": subject,
// user to determine whether to link to sign-up or login
"UserAccountExists": userAccountExists,
// helper
"locale": locale,
"Str2html": templates.Str2html,
Expand Down
9 changes: 7 additions & 2 deletions templates/mail/team_invite.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no">
</head>
{{$invite_url := printf "%sorg/invite/%s" AppUrl (QueryEscape .Invite.Token)}}
<body>
<p>{{.locale.Tr "mail.team_invite.text_1" (DotEscape .Inviter.DisplayName) (DotEscape .Team.Name) (DotEscape .Organization.DisplayName) | Str2html}}</p>
<p>{{.locale.Tr "mail.team_invite.text_2"}}</p><p><a href="{{$invite_url}}">{{$invite_url}}</a></p>
{{if .UserAccountExists}}
{{$login_url := printf "%suser/login?redirect_to=%s" AppUrl (QueryEscape (printf "/org/invite/%s" .Invite.Token))}}
<p>{{.locale.Tr "mail.team_invite.text_2"}}</p><p><a href="{{$login_url}}">{{$login_url}}</a></p>
{{else}}
{{$signup_url := printf "%suser/sign_up?redirect_to=%s" AppUrl (QueryEscape (printf "/org/invite/%s" .Invite.Token))}}
<p>{{.locale.Tr "mail.team_invite.text_2"}}</p><p><a href="{{$signup_url}}">{{$signup_url}}</a></p>
{{end}}
jackHay22 marked this conversation as resolved.
Show resolved Hide resolved
<p>{{.locale.Tr "mail.link_not_working_do_paste"}}</p>
<p>{{.locale.Tr "mail.team_invite.text_3" .Invite.Email}}</p>

Expand Down