1
0
mirror of https://github.com/volatiletech/authboss.git synced 2025-01-24 05:17:10 +02:00
authboss/config.go

123 lines
3.1 KiB
Go
Raw Normal View History

package authboss
import (
"html/template"
"io"
"io/ioutil"
2015-01-25 15:40:57 -08:00
"net/smtp"
2015-02-22 13:16:11 -08:00
"strings"
"time"
2015-01-30 15:38:28 -08:00
"golang.org/x/crypto/bcrypt"
2015-02-08 23:08:33 -08:00
)
const (
layoutTpl = "layout.tpl"
layoutEmailTpl = "layoutEmail.tpl"
)
// Cfg is the singleton instance of Config
var Cfg *Config = NewConfig()
// Config holds all the configuration for both authboss and it's modules.
type Config struct {
2015-02-22 13:16:11 -08:00
// MountPath is the path to mount authboss's routes at (eg /auth).
MountPath string
2015-02-22 13:16:11 -08:00
// ViewsPath is the path to search for overridden templates.
ViewsPath string
2015-02-22 13:16:11 -08:00
// HostName is the host of the web application (eg https://www.happiness.com:8080) for e-mail url generation.
HostName string
2015-02-22 13:16:11 -08:00
// BCryptCost is the cost of the bcrypt password hashing function.
2015-01-30 15:38:28 -08:00
BCryptCost int
2015-02-22 13:16:11 -08:00
// PrimaryID is the primary identifier of the user. Set to one of:
// authboss.StoreEmail, authboss.StoreUsername (StoreEmail is default)
PrimaryID string
Layout *template.Template
LayoutEmail *template.Template
LayoutDataMaker ViewDataMaker
AuthLogoutRoute string
AuthLoginSuccessRoute string
2015-01-30 15:38:28 -08:00
RecoverRedirect string
RecoverInitiateSuccessFlash string
2015-01-30 15:38:28 -08:00
RecoverTokenDuration time.Duration
RecoverTokenExpiredFlash string
RecoverFailedErrorFlash string
2015-01-17 23:37:05 -08:00
Policies []Validator
ConfirmFields []string
2015-01-25 18:13:32 -08:00
2015-02-22 13:16:11 -08:00
ExpireAfter time.Duration
LockAfter int
LockWindow time.Duration
LockDuration time.Duration
EmailFrom string
EmailSubjectPrefix string
2015-01-27 17:34:55 -08:00
SMTPAddress string
SMTPAuth smtp.Auth
2015-01-25 15:40:57 -08:00
2015-01-27 17:34:55 -08:00
XSRFName string
XSRFMaker XSRF
2015-01-25 15:40:57 -08:00
Storer Storer
CookieStoreMaker CookieStoreMaker
SessionStoreMaker SessionStoreMaker
LogWriter io.Writer
Callbacks *Callbacks
Mailer Mailer
}
func NewConfig() *Config {
return &Config{
2015-01-30 15:38:28 -08:00
MountPath: "/",
ViewsPath: "/",
HostName: "localhost:8080",
BCryptCost: bcrypt.DefaultCost,
2015-01-10 23:12:40 -08:00
2015-02-22 13:16:11 -08:00
PrimaryID: StoreEmail,
2015-02-20 23:33:35 -08:00
Layout: template.Must(template.New("").Parse(`<html><body>{{template "authboss" .}}</body></html>`)),
LayoutEmail: template.Must(template.New("").Parse(`<html><body>{{template "authboss" .}}</body></html>`)),
2015-02-08 23:08:33 -08:00
2015-02-20 23:33:35 -08:00
AuthLogoutRoute: "/login",
2015-01-18 14:24:20 -08:00
AuthLoginSuccessRoute: "/",
2015-01-30 15:38:28 -08:00
Policies: []Validator{
Rules{
FieldName: "username",
Required: true,
MinLength: 2,
MaxLength: 4,
AllowWhitespace: false,
},
Rules{
FieldName: "password",
Required: true,
MinLength: 4,
MaxLength: 8,
AllowWhitespace: false,
},
},
2015-02-22 13:16:11 -08:00
ConfirmFields: []string{
StoreEmail, "confirm" + strings.Title(StoreEmail),
StorePassword, "confirm" + strings.Title(StorePassword),
},
2015-01-30 15:38:28 -08:00
RecoverRedirect: "/login",
RecoverInitiateSuccessFlash: "An email has been sent with further insructions on how to reset your password",
2015-01-30 15:38:28 -08:00
RecoverTokenDuration: time.Duration(24) * time.Hour,
RecoverTokenExpiredFlash: "Account recovery request has expired. Please try agian.",
RecoverFailedErrorFlash: "Account recovery has failed. Please contact tech support.",
LogWriter: ioutil.Discard,
2015-01-15 14:01:01 -08:00
Callbacks: NewCallbacks(),
2015-01-25 15:40:57 -08:00
Mailer: LogMailer(ioutil.Discard),
}
}