// UserEmailer provides functions for sending emails to Users.
typeUserEmailerstruct{
uruser.UserRepo
pwiuser.PasswordInfoRepo
signerFnsignerFunc
tokenValidityWindowtime.Duration
issuerURLurl.URL
emailer*email.TemplatizedEmailer
fromAddressstring
passwordResetURLurl.URL
verifyEmailURLurl.URL
}
// NewUserEmailer creates a new UserEmailer.
funcNewUserEmailer(uruser.UserRepo,
pwiuser.PasswordInfoRepo,
signerFnsignerFunc,
tokenValidityWindowtime.Duration,
issuerURLurl.URL,
emailer*email.TemplatizedEmailer,
fromAddressstring,
passwordResetURLurl.URL,
verifyEmailURLurl.URL,
)*UserEmailer{
return&UserEmailer{
ur:ur,
pwi:pwi,
signerFn:signerFn,
tokenValidityWindow:tokenValidityWindow,
issuerURL:issuerURL,
emailer:emailer,
fromAddress:fromAddress,
passwordResetURL:passwordResetURL,
verifyEmailURL:verifyEmailURL,
}
}
// SendResetPasswordEmail sends a password reset email to the user specified by the email addresss, containing a link with a signed token which can be visitied to initiate the password change/reset process.
// This method DOES NOT check for client ID, redirect URL validity - it is expected that upstream users have already done so.
// If there is no emailer is configured, the URL of the aforementioned link is returned, otherwise nil is returned.
// SendEmailVerification sends an email to the user with the given userID containing a link which when visited marks the user as having had their email verified.
// If there is no emailer is configured, the URL of the aforementioned link is returned, otherwise nil is returned.