Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78de144

Browse files
committed
Merge branch 'bugfix'
2 parents 6093ada + a3b0051 commit 78de144

File tree

14 files changed

+178
-25
lines changed

14 files changed

+178
-25
lines changed

websites/code/studygolang/install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DATE=`date +%FT%T%z`
2020

2121
gofmt -w src
2222

23-
go install -ldflags "-X util/version.Version "$VERSION" -X util/version.Date "$DATE ./...
23+
go install -ldflags "-X util/version.Version="$VERSION" -X util/version.Date="$DATE ./...
2424

2525
export GOPATH="$OLDGOPATH"
2626
export PATH="$OLDPATH"

websites/code/studygolang/install.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ set VERSION=%VERNAME%-%VERCODE%
2323
gofmt -w src
2424

2525
:: -tags "debug" 表示测试
26-
go install -tags "debug" -ldflags "-X util.version.Version "%VERSION% ./...
26+
go install -tags "debug" -ldflags "-X util.version.Version="%VERSION% ./...
2727

2828
set GOPATH=%OLDGOPATH%
2929

websites/code/studygolang/src/controller/index.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ import (
2323
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
2424
// nodes := service.GenNodes()
2525

26-
// 获取最新帖子
27-
newTopics, _ := service.FindTopics(1, 10, "", "ctime DESC")
26+
num := 10
27+
28+
topicsList := make([]map[string]interface{}, num)
29+
// 置顶的topic
30+
topTopics, _ := service.FindTopics(1, num, "top=1", "ctime DESC")
31+
if len(topTopics) < num {
32+
// 获取最新帖子
33+
newTopics, _ := service.FindTopics(1, num-len(topTopics), "top=0", "ctime DESC")
34+
35+
topicsList = append(topTopics, newTopics...)
36+
}
37+
2838
// 获取热门帖子
2939
//hotTopics := service.FindHotTopics()
3040
// 获得最新博文
@@ -56,7 +66,7 @@ func IndexHandler(rw http.ResponseWriter, req *http.Request) {
5666
// 设置内容模板
5767
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/index.html")
5868
// 设置模板数据
59-
filter.SetData(req, map[string]interface{}{"topics": newTopics, "articles": recentArticles, "likeflags": likeFlags, "resources": resources})
69+
filter.SetData(req, map[string]interface{}{"topics": topicsList, "articles": recentArticles, "likeflags": likeFlags, "resources": resources})
6070
}
6171

6272
// 包装链接

websites/code/studygolang/src/filter/login.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import (
1111
"strings"
1212

1313
"config"
14-
"github.com/gorilla/context"
15-
"github.com/gorilla/sessions"
16-
"github.com/studygolang/mux"
1714
"logger"
1815
"service"
1916
"util"
17+
18+
"github.com/gorilla/context"
19+
"github.com/gorilla/sessions"
20+
"github.com/studygolang/mux"
2021
)
2122

2223
// 没登陆且没有cookie,则跳转到登录页
@@ -79,6 +80,7 @@ func (this *CookieFilter) PreFilter(rw http.ResponseWriter, req *http.Request) b
7980
if user != nil && req.RequestURI == "/account/login" {
8081
util.Redirect(rw, req, "/")
8182
}
83+
8284
return true
8385
}
8486

@@ -107,20 +109,35 @@ func setUser(req *http.Request, user map[string]interface{}) {
107109
var Store = sessions.NewCookieStore([]byte(config.Config["cookie_secret"]))
108110

109111
// 获得当前登录用户
110-
func CurrentUser(req *http.Request) (map[string]interface{}, bool) {
111-
user := getUser(req)
112+
func CurrentUser(req *http.Request) (user map[string]interface{}, succ bool) {
113+
114+
defer func() {
115+
// 判断用户是否能登陆
116+
if !service.IsNormalUser(user["status"]) {
117+
user, succ = nil, false
118+
}
119+
}()
120+
121+
succ = true
122+
123+
user = getUser(req)
112124
if len(user) != 0 {
113-
return user, true
125+
return
114126
}
115127
session, _ := Store.Get(req, "user")
116128
username, ok := session.Values["username"]
117129
if !ok {
118-
return nil, false
130+
succ = false
131+
return
119132
}
120-
user, err := service.FindCurrentUser(username.(string))
133+
134+
var err error
135+
user, err = service.FindCurrentUser(username.(string))
121136
if err != nil {
122-
return nil, false
137+
succ = false
138+
return
123139
}
140+
124141
setUser(req, user)
125-
return user, true
142+
return
126143
}

websites/code/studygolang/src/model/topic.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Topic struct {
2929
Lastreplyuid int `json:"lastreplyuid"`
3030
Lastreplytime string `json:"lastreplytime"`
3131
EditorUid int `json:"editor_uid"`
32+
Top uint8 `json:"top"`
3233
Ctime string `json:"ctime"`
3334
Mtime string `json:"mtime"`
3435

@@ -122,6 +123,7 @@ func (this *Topic) colFieldMap() map[string]interface{} {
122123
"lastreplyuid": &this.Lastreplyuid,
123124
"lastreplytime": &this.Lastreplytime,
124125
"editor_uid": &this.EditorUid,
126+
"top": &this.Top,
125127
"ctime": &this.Ctime,
126128
"mtime": &this.Mtime,
127129
}

websites/code/studygolang/src/model/user.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ func (this *UserLogin) GetPasscode() string {
121121
return this.passcode
122122
}
123123

124+
const (
125+
StatusNoAudit = iota
126+
StatusAudit
127+
StatusRefuse
128+
StatusFreeze // 冻结
129+
StatusOutage // 停用
130+
)
131+
124132
// 用户基本信息
125133
type User struct {
126134
Uid int `json:"uid"`

websites/code/studygolang/src/service/user.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func FindCurrentUser(username string) (user map[string]interface{}, err error) {
161161
"username": userInfo.Username,
162162
"email": userInfo.Email,
163163
"avatar": userInfo.Avatar,
164+
"status": userInfo.Status,
164165
}
165166

166167
// 获取未读消息数
@@ -184,6 +185,19 @@ func FindCurrentUser(username string) (user map[string]interface{}, err error) {
184185
return
185186
}
186187

188+
// IsNormalUser 判断是否是正常的用户
189+
func IsNormalUser(userStatus interface{}) bool {
190+
if userStatus == nil {
191+
return true
192+
}
193+
194+
if userStatus.(int) > model.StatusRefuse {
195+
return false
196+
}
197+
198+
return true
199+
}
200+
187201
// 判断指定的用户名是否存在
188202
func UsernameExists(username string) bool {
189203
userLogin := model.NewUserLogin()

websites/code/studygolang/static/js/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ $(document).ready( function(){
2828
StartScroll();
2929
}
3030
});
31+
32+
// 登录
33+
$('.login').submit(function(evt) {
34+
evt.preventDefault();
35+
$.post('/account/login.json', $(this).serialize(), function(data) {
36+
if (data.ok) {
37+
location.reload();
38+
} else {
39+
comTip(data.error);
40+
}
41+
});
42+
});
3143

3244
});
3345

websites/code/studygolang/template/index.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h3><a href="/topics">最新主题</a></h3>
1919
</div>
2020
<ul class="clearfix list-unstyled">
2121
{{range .topics}}
22-
<li><i></i><a href="/topics/{{.tid}}" title="{{.title}}">{{substring .title 35 "..."}}</a><span class="pull-right timeago" title="{{.ctime}}"></span></li>
22+
<li><i></i>{{if .top}}<font color="red"><span class="glyphicon glyphicon-pushpin"></span></font> {{end}}<a href="/topics/{{.tid}}" title="{{.title}}">{{substring .title 35 "..."}}</a><span class="pull-right timeago" title="{{.ctime}}"></span></li>
2323
{{end}}
2424
</ul>
2525
</div>
@@ -35,9 +35,6 @@ <h3><a href="/resources">Golang 资源</a></h3>
3535
</ul>
3636
</div>
3737
</div>
38-
<div class="row box_white" style="margin-top:20px;">
39-
<a href="http://studygolang.com/wr?u=http%3A%2F%2Fwww.shiyanlou.com%2Fcourses%2F11" target="_blank" title="实验楼"><img src="http://studygolang.qiniudn.com/ad/shiyanlou_banner.jpg" alt="实验楼 IT人专属的在线实训室 学Golang最好的地方"></a>
40-
</div>
4138
<div class="row box_white article-list">
4239
<div class="title">
4340
<h3><a href="/articles">最新博文</a></h3>
@@ -262,7 +259,7 @@ <h3><a href="javascript:">学习资料</a></h3>
262259
<h3 class="title"><i class="glyphicon glyphicon-user"></i> 用户登录</h3>
263260
</div>
264261
<div class="sb-content">
265-
<form action="/account/login" method="post" class="form-horizontal login" role="form">
262+
<form action="/account/login.json" method="post" class="form-horizontal login" role="form">
266263
<div class="form-group">
267264
<div class="col-sm-10">
268265
<input type="text" class="form-control input-sm" id="username" name="username" placeholder="请填写用户名或邮箱">

websites/code/studygolang/template/resources/new.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<i id="upload-img" class="glyphicon glyphicon-picture upload-img tool-tip" data-toggle="tooltip" data-placement="top" title="上传图片"></i>
6262
</div>
6363
</div>
64-
<textarea class="form-control need-autogrow" id="content" name="content" rows="15">{{.resource.Content}}</textarea>
64+
<textarea class="form-control need-autogrow main-textarea" id="content" name="content" rows="15">{{.resource.Content}}</textarea>
6565
<div class="content-preview"></div>
6666
</div>
6767
</div>

0 commit comments

Comments
 (0)