diff --git a/auth/auth.go b/auth/auth.go index d7223ca..7c43865 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -12,8 +12,6 @@ import ( ) const ( - ModuleName = "auth" - methodGET = "GET" methodPOST = "POST" @@ -21,7 +19,7 @@ const ( ) func init() { - authboss.RegisterModule(ModuleName, &Auth{}) + authboss.RegisterModule("auth", &Auth{}) } // Auth module diff --git a/config.go b/config.go index 569859c..96c0c9e 100644 --- a/config.go +++ b/config.go @@ -21,8 +21,6 @@ type Config struct { RootURL string // BCryptCost is the cost of the bcrypt password hashing function. BCryptCost int - // If true, authboss won't use any goroutines. Dependencies of authboss may or may not use goroutines. - DisableGoroutines bool // PrimaryID is the primary identifier of the user. Set to one of: // authboss.StoreEmail, authboss.StoreUsername (StoreEmail is default) @@ -106,7 +104,9 @@ type Config struct { // a Storer on demand from the current http request. Unless you have an exceedingly unusual // special requirement, defining Storer directly is the preferred pattern; literally the only // known use case at the time of this property being added is Google App Engine, which requires - // the current context as an argument to its datastore API methods. + // the current context as an argument to its datastore API methods. To avoid passing StoreMaker + // an expired request object, where relevant, calls to this function will never be spun off as + // goroutines. StoreMaker StoreMaker // OAuth2Storer is a different kind of storer only meant for OAuth2. OAuth2Storer OAuth2Storer @@ -114,7 +114,9 @@ type Config struct { // a OAuth2Storer on demand from the current http request. Unless you have an exceedingly unusual // special requirement, defining OAuth2Storer directly is the preferred pattern; literally the only // known use case at the time of this property being added is Google App Engine, which requires - // the current context as an argument to its datastore API methods. + // the current context as an argument to its datastore API methods. To avoid passing OAuth2StoreMaker + // an expired request object, where relevant, calls to this function will never be spun off as + // goroutines. OAuth2StoreMaker OAuth2StoreMaker // CookieStoreMaker must be defined to provide an interface capapable of storing cookies // for the given response, and reading them from the request. @@ -129,7 +131,9 @@ type Config struct { // a LogWriter on demand from the current http request. Unless you have an exceedingly unusual // special requirement, defining LogWriter directly is the preferred pattern; literally the only // known use case at the time of this property being added is Google App Engine, which requires - // the current context as an argument to its logging API methods. + // the current context as an argument to its logging API methods. To avoid passing LogWriteMaker + // an expired request object, where relevant, calls to this function will never be spun off as + // goroutines. LogWriteMaker LogWriteMaker // Mailer is the mailer being used to send e-mails out. Authboss defines two loggers for use // LogMailer and SMTPMailer, the default is a LogMailer to io.Discard. @@ -138,7 +142,9 @@ type Config struct { // a Mailer on demand from the current http request. Unless you have an exceedingly unusual // special requirement, defining Mailer directly is the preferred pattern; literally the only // known use case at the time of this property being added is Google App Engine, which requires - // the current context as an argument to its mail API methods. + // the current context as an argument to its mail API methods. To avoid passing MailMaker + // an expired request object, where relevant, calls to this function will never be spun off as + // goroutines. MailMaker MailMaker // ContextProvider provides a context for a given request ContextProvider func(*http.Request) context.Context diff --git a/confirm/confirm.go b/confirm/confirm.go index 2dc176c..689bf8c 100644 --- a/confirm/confirm.go +++ b/confirm/confirm.go @@ -17,8 +17,6 @@ import ( // Storer and FormValue constants const ( - ModuleName = "confirm" - StoreConfirmToken = "confirm_token" StoreConfirmed = "confirmed" @@ -43,7 +41,7 @@ type ConfirmStorer interface { } func init() { - authboss.RegisterModule(ModuleName, &Confirm{}) + authboss.RegisterModule("confirm", &Confirm{}) } // Confirm module @@ -138,7 +136,7 @@ func (c *Confirm) afterRegister(ctx *authboss.Context) error { } var goConfirmEmail = func(c *Confirm, ctx *authboss.Context, to, token string) { - if ctx.DisableGoroutines { + if ctx.MailMaker != nil { c.confirmEmail(ctx, to, token) } else { go c.confirmEmail(ctx, to, token) diff --git a/lock/lock.go b/lock/lock.go index 249f9ca..41a56fd 100644 --- a/lock/lock.go +++ b/lock/lock.go @@ -10,8 +10,6 @@ import ( // Storage key constants const ( - ModuleName = "Lock" - StoreAttemptNumber = "attempt_number" StoreAttemptTime = "attempt_time" StoreLocked = "locked" @@ -22,7 +20,7 @@ var ( ) func init() { - authboss.RegisterModule(ModuleName, &Lock{}) + authboss.RegisterModule("lock", &Lock{}) } // Lock module diff --git a/oauth2/oauth2.go b/oauth2/oauth2.go index 5bc6141..cae969c 100644 --- a/oauth2/oauth2.go +++ b/oauth2/oauth2.go @@ -17,10 +17,6 @@ import ( "gopkg.in/authboss.v0/internal/response" ) -const ( - ModuleName = "oauth2" -) - var ( errOAuthStateValidation = errors.New("Could not validate oauth2 state param") ) @@ -31,7 +27,7 @@ type OAuth2 struct { } func init() { - authboss.RegisterModule(ModuleName, &OAuth2{}) + authboss.RegisterModule("oauth2", &OAuth2{}) } // Initialize module diff --git a/recover/recover.go b/recover/recover.go index afa664f..bcb300c 100644 --- a/recover/recover.go +++ b/recover/recover.go @@ -28,8 +28,6 @@ const ( ) const ( - ModuleName = "recover" - methodGET = "GET" methodPOST = "POST" @@ -58,7 +56,7 @@ type RecoverStorer interface { func init() { m := &Recover{} - authboss.RegisterModule(ModuleName, m) + authboss.RegisterModule("recover", m) } // Recover module @@ -197,7 +195,7 @@ func newToken() (encodedToken, encodedChecksum string, err error) { } var goRecoverEmail = func(r *Recover, ctx *authboss.Context, to, encodedToken string) { - if ctx.DisableGoroutines { + if ctx.MailMaker != nil { r.sendRecoverEmail(ctx, to, encodedToken) } else { go r.sendRecoverEmail(ctx, to, encodedToken) diff --git a/recover/recover_test.go b/recover/recover_test.go index 42642c7..ab77eba 100644 --- a/recover/recover_test.go +++ b/recover/recover_test.go @@ -268,7 +268,7 @@ func TestRecover_sendRecoverMail_FailToSend(t *testing.T) { mailer.SendErr = "failed to send" r.Mailer = mailer - r.sendRecoverEmail("", "") + r.sendRecoverEmail(r.NewContext(), "", "") if !strings.Contains(logger.String(), "failed to send") { t.Error("Expected logged to have msg:", "failed to send") @@ -285,7 +285,7 @@ func TestRecover_sendRecoverEmail(t *testing.T) { r.RootURL = "bar" r.Mailer = mailer - r.sendRecoverEmail("a@b.c", "abc=") + r.sendRecoverEmail(r.NewContext(), "a@b.c", "abc=") if len(mailer.Last.To) != 1 { t.Error("Expected 1 to email") } diff --git a/register/register.go b/register/register.go index ad85af6..a1ecf8e 100644 --- a/register/register.go +++ b/register/register.go @@ -11,8 +11,6 @@ import ( ) const ( - ModuleName = "register" - tplRegister = "register.html.tpl" ) @@ -26,7 +24,7 @@ type RegisterStorer interface { } func init() { - authboss.RegisterModule(ModuleName, &Register{}) + authboss.RegisterModule("register", &Register{}) } // Register module. diff --git a/remember/remember.go b/remember/remember.go index d07ec0a..d6a9597 100644 --- a/remember/remember.go +++ b/remember/remember.go @@ -14,8 +14,6 @@ import ( ) const ( - ModuleName = "remember" - nRandBytes = 32 ) @@ -41,7 +39,7 @@ type RememberStorer interface { } func init() { - authboss.RegisterModule(ModuleName, &Remember{}) + authboss.RegisterModule("remember", &Remember{}) } // Remember module