mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +00:00 
			
		
		
		
	Send registration email on user autoregistration (#16523)
When users login and are autoregistered send email notification. Fix #16178 * Protect public functions within the mailer by testing if the mailer is configured Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
		| @@ -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, | ||||
| @@ -84,8 +85,13 @@ func (source *Source) Authenticate(user *models.User, login, password string) (* | ||||
| 	} | ||||
|  | ||||
| 	err := models.CreateUser(user) | ||||
| 	if err != nil { | ||||
| 		return user, err | ||||
| 	} | ||||
|  | ||||
| 	if err == nil && isAttributeSSHPublicKeySet && models.AddPublicKeysBySource(user, source.loginSource, sr.SSHPublicKey) { | ||||
| 	mailer.SendRegisterNotifyMail(user) | ||||
|  | ||||
| 	if isAttributeSSHPublicKeySet && models.AddPublicKeysBySource(user, source.loginSource, sr.SSHPublicKey) { | ||||
| 		err = models.RewriteAllPublicKeys() | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -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" | ||||
| ) | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
| @@ -74,5 +75,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 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user