3
0

Apply style to auth notification emails

Added command for system-cli for auth notification testing:
> ./system-cli auth test-notifications your@email.tld

This send all (both) notification emails to specified receipient
This commit is contained in:
Denis Arh
2019-05-13 19:43:26 +02:00
parent 9d8049cf45
commit 42e456cc66
5 changed files with 126 additions and 23 deletions
+29 -1
View File
@@ -12,6 +12,7 @@ import (
"github.com/crusttech/crust/internal/settings"
"github.com/crusttech/crust/system/internal/auth/external"
"github.com/crusttech/crust/system/internal/repository"
"github.com/crusttech/crust/system/internal/service"
"github.com/crusttech/crust/system/types"
)
@@ -81,7 +82,34 @@ func authCmd(ctx context.Context, db *factory.DB, settingsService settings.Servi
},
}
cmd.AddCommand(autoDiscoverCmd, jwtCmd)
testEmails := &cobra.Command{
Use: "test-notifications [recipient]",
Short: "Sends samples of all authentication notification to receipient",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var (
err error
ntf = service.DefaultAuthNotification.With(ctx)
)
err = ntf.EmailConfirmation("en", args[0], "notification-testing-token")
if err != nil {
exit(cmd, err)
}
err = ntf.PasswordReset("en", args[0], "notification-testing-token")
if err != nil {
exit(cmd, err)
}
},
}
cmd.AddCommand(
autoDiscoverCmd,
testEmails,
jwtCmd,
)
return cmd
}
+5 -1
View File
@@ -194,6 +194,10 @@ func settingsAutoConfigure(cmd *cobra.Command, setSvc settings.Service, systemAp
setIfMissing("auth.frontend.url.redirect", func() interface{} {
return frontendUrl + "/auth/"
})
setIfMissing("auth.frontend.url.base", func() interface{} {
return frontendUrl + "/"
})
}
// Auth email (password reset, email confirmation)
@@ -209,7 +213,7 @@ func settingsAutoConfigure(cmd *cobra.Command, setSvc settings.Service, systemAp
return fromName
}
return "Crust"
return "Crust Team"
})
// No external providers preconfigured, so disable
+4 -8
View File
@@ -658,7 +658,7 @@ func (svc auth) sendEmailAddressConfirmationToken(u *types.User) (err error) {
var (
notificationLang = "en"
token, url string
token string
)
token, err = svc.createUserToken(u, credentialsTypeEmailAuthToken)
@@ -666,9 +666,7 @@ func (svc auth) sendEmailAddressConfirmationToken(u *types.User) (err error) {
return
}
url = svc.settings.frontendUrlEmailConfirmation + token
err = svc.notifications.EmailConfirmation(notificationLang, u.Email, url)
err = svc.notifications.EmailConfirmation(notificationLang, u.Email, token)
if err != nil {
return errors.Wrap(err, "could not send email authentication notification")
}
@@ -701,7 +699,7 @@ func (svc auth) sendPasswordResetToken(u *types.User) (err error) {
var (
notificationLang = "en"
token, url string
token string
)
token, err = svc.createUserToken(u, credentialsTypeResetPasswordToken)
@@ -709,9 +707,7 @@ func (svc auth) sendPasswordResetToken(u *types.User) (err error) {
return
}
url = svc.settings.frontendUrlPasswordReset + token
err = svc.notifications.PasswordReset(notificationLang, u.Email, url)
err = svc.notifications.PasswordReset(notificationLang, u.Email, token)
if err != nil {
return errors.Wrap(err, "could not send password reset notification")
}
File diff suppressed because one or more lines are too long
+4
View File
@@ -17,6 +17,9 @@ type (
// Where to redirect user after external auth flow
frontendUrlRedirect string
// Webapp Base URL
frontendUrlBase string
mailFromAddress string
mailFromName string
@@ -50,6 +53,7 @@ func AuthSettings(kv authSettingsStore) authSettings {
frontendUrlPasswordReset: kv.String("auth.frontend.url.password-reset"),
frontendUrlEmailConfirmation: kv.String("auth.frontend.url.email-confirmation"),
frontendUrlRedirect: kv.String("auth.frontend.url.redirect"),
frontendUrlBase: kv.String("auth.frontend.url.base"),
mailFromAddress: kv.String("auth.mail.from-address"),
mailFromName: kv.String("auth.mail.from-name"),