Skip to content

Commit eea55fc

Browse files
committed
Update authboss-sample for latest version
1 parent 0b584cc commit eea55fc

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

blog.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
"golang.org/x/oauth2"
16-
ab "gopkg.in/authboss.v0"
16+
"gopkg.in/authboss.v0"
1717
_ "gopkg.in/authboss.v0/auth"
1818
_ "gopkg.in/authboss.v0/confirm"
1919
_ "gopkg.in/authboss.v0/lock"
@@ -39,22 +39,23 @@ var funcs = template.FuncMap{
3939
}
4040

4141
var (
42+
ab = authboss.New()
4243
database = NewMemStorer()
4344
templates = tpl.Must(tpl.Load("views", "views/partials", "layout.html.tpl", funcs))
4445
schemaDec = schema.NewDecoder()
4546
)
4647

4748
func setupAuthboss() {
48-
ab.Cfg.Storer = database
49-
ab.Cfg.OAuth2Storer = database
50-
ab.Cfg.MountPath = "/auth"
51-
ab.Cfg.ViewsPath = "ab_views"
52-
ab.Cfg.RootURL = `http://localhost:3000`
49+
ab.Storer = database
50+
ab.OAuth2Storer = database
51+
ab.MountPath = "/auth"
52+
ab.ViewsPath = "ab_views"
53+
ab.RootURL = `http://localhost:3000`
5354

54-
ab.Cfg.LayoutDataMaker = layoutData
55+
ab.LayoutDataMaker = layoutData
5556

56-
ab.Cfg.OAuth2Providers = map[string]ab.OAuth2Provider{
57-
"google": ab.OAuth2Provider{
57+
ab.OAuth2Providers = map[string]authboss.OAuth2Provider{
58+
"google": authboss.OAuth2Provider{
5859
OAuth2Config: &oauth2.Config{
5960
ClientID: ``,
6061
ClientSecret: ``,
@@ -69,17 +70,17 @@ func setupAuthboss() {
6970
if err != nil {
7071
panic(err)
7172
}
72-
ab.Cfg.Layout = template.Must(template.New("layout").Funcs(funcs).Parse(string(b)))
73+
ab.Layout = template.Must(template.New("layout").Funcs(funcs).Parse(string(b)))
7374

74-
ab.Cfg.XSRFName = "csrf_token"
75-
ab.Cfg.XSRFMaker = func(_ http.ResponseWriter, r *http.Request) string {
75+
ab.XSRFName = "csrf_token"
76+
ab.XSRFMaker = func(_ http.ResponseWriter, r *http.Request) string {
7677
return nosurf.Token(r)
7778
}
7879

79-
ab.Cfg.CookieStoreMaker = NewCookieStorer
80-
ab.Cfg.SessionStoreMaker = NewSessionStorer
80+
ab.CookieStoreMaker = NewCookieStorer
81+
ab.SessionStoreMaker = NewSessionStorer
8182

82-
ab.Cfg.Mailer = ab.LogMailer(os.Stdout)
83+
ab.Mailer = authboss.LogMailer(os.Stdout)
8384

8485
if err := ab.Init(); err != nil {
8586
log.Fatal(err)
@@ -132,19 +133,19 @@ func main() {
132133
log.Println(http.ListenAndServe("localhost:"+port, stack))
133134
}
134135

135-
func layoutData(w http.ResponseWriter, r *http.Request) ab.HTMLData {
136+
func layoutData(w http.ResponseWriter, r *http.Request) authboss.HTMLData {
136137
currentUserName := ""
137138
userInter, err := ab.CurrentUser(w, r)
138139
if userInter != nil && err == nil {
139140
currentUserName = userInter.(*User).Name
140141
}
141142

142-
return ab.HTMLData{
143-
"loggedin": userInter != nil,
144-
"username": "",
145-
ab.FlashSuccessKey: ab.FlashSuccess(w, r),
146-
ab.FlashErrorKey: ab.FlashError(w, r),
147-
"current_user_name": currentUserName,
143+
return authboss.HTMLData{
144+
"loggedin": userInter != nil,
145+
"username": "",
146+
authboss.FlashSuccessKey: ab.FlashSuccess(w, r),
147+
authboss.FlashErrorKey: ab.FlashError(w, r),
148+
"current_user_name": currentUserName,
148149
}
149150
}
150151

0 commit comments

Comments
 (0)