mirror of
https://github.com/volatiletech/authboss.git
synced 2024-11-28 08:58:38 +02:00
no DisableGoroutines (just check for -Maker); no ModuleNames; test fix
This commit is contained in:
parent
48f0e8a75a
commit
96c55ccaaa
@ -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
|
||||
|
18
config.go
18
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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user