Skip to content

Commit

Permalink
Send registration email on user autoregistration
Browse files Browse the repository at this point in the history
When users login and are autoregistered send email notification.

Fix go-gitea#16178

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jul 24, 2021
1 parent 5d2e11e commit 79e29e8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions services/auth/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/mailer"

gouuid "github.com/google/uuid"
)
Expand Down Expand Up @@ -112,5 +113,7 @@ func (r *ReverseProxy) newUser(req *http.Request) *models.User {
return nil
}

mailer.SendRegisterNotifyMail(user)

return user
}
8 changes: 7 additions & 1 deletion services/auth/source/ldap/source_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/services/mailer"
)

// Authenticate queries if login/password is valid against the LDAP directory pool,
Expand Down Expand Up @@ -84,8 +85,13 @@ func (source *Source) Authenticate(user *models.User, login, password string) (*
}

err := models.CreateUser(user)
if err != nil {
return user, err
}

mailer.SendRegisterNotifyMail(user)

if err == nil && isAttributeSSHPublicKeySet && models.AddPublicKeysBySource(user, source.loginSource, sr.SSHPublicKey) {
if isAttributeSSHPublicKeySet && models.AddPublicKeysBySource(user, source.loginSource, sr.SSHPublicKey) {
err = models.RewriteAllPublicKeys()
}

Expand Down
10 changes: 9 additions & 1 deletion services/auth/source/pam/source_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth/pam"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/mailer"

"github.com/google/uuid"
)
Expand Down Expand Up @@ -58,5 +59,12 @@ func (source *Source) Authenticate(user *models.User, login, password string) (*
LoginName: login, // This is what the user typed in
IsActive: true,
}
return user, models.CreateUser(user)

if err := models.CreateUser(user); err != nil {
return user, err
}

mailer.SendRegisterNotifyMail(user)

return user, nil
}
10 changes: 9 additions & 1 deletion services/auth/source/smtp/source_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/mailer"
)

// Authenticate queries if the provided login/password is authenticates against the SMTP server
Expand Down Expand Up @@ -67,5 +68,12 @@ func (source *Source) Authenticate(user *models.User, login, password string) (*
LoginName: login,
IsActive: true,
}
return user, models.CreateUser(user)

if err := models.CreateUser(user); err != nil {
return user, err
}

mailer.SendRegisterNotifyMail(user)

return user, nil
}
4 changes: 4 additions & 0 deletions services/auth/sspi_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/auth/source/sspi"
"code.gitea.io/gitea/services/mailer"

gouuid "github.com/google/uuid"
"github.com/quasoft/websspi"
Expand Down Expand Up @@ -197,6 +198,9 @@ func (s *SSPI) newUser(username string, cfg *sspi.Source) (*models.User, error)
if err := models.CreateUser(user); err != nil {
return nil, err
}

mailer.SendRegisterNotifyMail(user)

return user, nil
}

Expand Down

0 comments on commit 79e29e8

Please sign in to comment.