Skip to content

Commit 88f1566

Browse files
committed
Fix 14.4.md spaces err
1 parent 77b4a7e commit 88f1566

File tree

2 files changed

+63
-64
lines changed

2 files changed

+63
-64
lines changed

zh/14.4.md

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -61,77 +61,76 @@ github.com/bradrydzewski/go.auth
6161
1. 添加两条路由
6262
```Go
6363

64-
beego.RegisterController("/auth/login", &controllers.GithubController{})
65-
beego.RegisterController("/mainpage", &controllers.PageController{})
64+
beego.RegisterController("/auth/login", &controllers.GithubController{})
65+
beego.RegisterController("/mainpage", &controllers.PageController{})
6666
```
6767
2. 然后我们处理GithubController登陆的页面:
6868
```Go
69+
package controllers
6970

70-
package controllers
71-
72-
import (
73-
"github.com/astaxie/beego"
74-
"github.com/bradrydzewski/go.auth"
75-
)
76-
77-
const (
78-
githubClientKey = "a0864ea791ce7e7bd0df"
79-
githubSecretKey = "a0ec09a647a688a64a28f6190b5a0d2705df56ca"
80-
)
81-
82-
type GithubController struct {
83-
beego.Controller
84-
}
85-
86-
func (this *GithubController) Get() {
87-
// set the auth parameters
88-
auth.Config.CookieSecret = []byte("7H9xiimk2QdTdYI7rDddfJeV")
89-
auth.Config.LoginSuccessRedirect = "/mainpage"
90-
auth.Config.CookieSecure = false
91-
92-
githubHandler := auth.Github(githubClientKey, githubSecretKey)
93-
94-
githubHandler.ServeHTTP(this.Ctx.ResponseWriter, this.Ctx.Request)
95-
}
71+
import (
72+
"github.com/astaxie/beego"
73+
"github.com/bradrydzewski/go.auth"
74+
)
75+
76+
const (
77+
githubClientKey = "a0864ea791ce7e7bd0df"
78+
githubSecretKey = "a0ec09a647a688a64a28f6190b5a0d2705df56ca"
79+
)
80+
81+
type GithubController struct {
82+
beego.Controller
83+
}
84+
85+
func (this *GithubController) Get() {
86+
// set the auth parameters
87+
auth.Config.CookieSecret = []byte("7H9xiimk2QdTdYI7rDddfJeV")
88+
auth.Config.LoginSuccessRedirect = "/mainpage"
89+
auth.Config.CookieSecure = false
90+
91+
githubHandler := auth.Github(githubClientKey, githubSecretKey)
92+
93+
githubHandler.ServeHTTP(this.Ctx.ResponseWriter, this.Ctx.Request)
94+
}
9695

9796
```
9897
3. 处理登陆成功之后的页面
9998
```Go
99+
package controllers
100100

101-
package controllers
102-
103-
import (
104-
"github.com/astaxie/beego"
105-
"github.com/bradrydzewski/go.auth"
106-
"net/http"
107-
"net/url"
108-
)
109-
110-
type PageController struct {
111-
beego.Controller
112-
}
113-
114-
func (this *PageController) Get() {
115-
// set the auth parameters
116-
auth.Config.CookieSecret = []byte("7H9xiimk2QdTdYI7rDddfJeV")
117-
auth.Config.LoginSuccessRedirect = "/mainpage"
118-
auth.Config.CookieSecure = false
119-
120-
user, err := auth.GetUserCookie(this.Ctx.Request)
121-
122-
//if no active user session then authorize user
123-
if err != nil || user.Id() == "" {
124-
http.Redirect(this.Ctx.ResponseWriter, this.Ctx.Request, auth.Config.LoginRedirect, http.StatusSeeOther)
125-
return
126-
}
127-
128-
//else, add the user to the URL and continue
129-
this.Ctx.Request.URL.User = url.User(user.Id())
130-
this.Data["pic"] = user.Picture()
131-
this.Data["id"] = user.Id()
132-
this.Data["name"] = user.Name()
133-
this.TplNames = "home.tpl"
101+
import (
102+
"github.com/astaxie/beego"
103+
"github.com/bradrydzewski/go.auth"
104+
"net/http"
105+
"net/url"
106+
)
107+
108+
type PageController struct {
109+
beego.Controller
110+
}
111+
112+
func (this *PageController) Get() {
113+
// set the auth parameters
114+
auth.Config.CookieSecret = []byte("7H9xiimk2QdTdYI7rDddfJeV")
115+
auth.Config.LoginSuccessRedirect = "/mainpage"
116+
auth.Config.CookieSecure = false
117+
118+
user, err := auth.GetUserCookie(this.Ctx.Request)
119+
120+
//if no active user session then authorize user
121+
if err != nil || user.Id() == "" {
122+
http.Redirect(this.Ctx.ResponseWriter, this.Ctx.Request, auth.Config.LoginRedirect, http.StatusSeeOther)
123+
return
134124
}
125+
126+
//else, add the user to the URL and continue
127+
this.Ctx.Request.URL.User = url.User(user.Id())
128+
this.Data["pic"] = user.Picture()
129+
this.Data["id"] = user.Id()
130+
this.Data["name"] = user.Name()
131+
this.TplNames = "home.tpl"
132+
}
133+
135134
```
136135
整个的流程如下,首先打开浏览器输入地址:
137136

zh/14.5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ LangPath string //设置语言包所在位置
1414
```Go
1515

1616
func InitLang(){
17-
beego.Translation:=i18n.NewLocale()
18-
beego.Translation.LoadPath(beego.LangPath)
19-
beego.Translation.SetLocale(beego.Lang)
17+
beego.Translation:=i18n.NewLocale()
18+
beego.Translation.LoadPath(beego.LangPath)
19+
beego.Translation.SetLocale(beego.Lang)
2020
}
2121
```
2222
为了方便在模板中直接调用多语言包,我们设计了三个函数来处理响应的多语言:

0 commit comments

Comments
 (0)