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

Skip to content

Commit a3b0051

Browse files
committed
修改:
1、首页登录bug; 2、发主题上传图片bug; 3、首页主题置顶功能实现;
1 parent 6093ada commit a3b0051

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>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<i id="upload-img" class="glyphicon glyphicon-picture upload-img tool-tip" data-toggle="tooltip" data-placement="top" title="上传图片"></i>
5656
</div>
5757
</div>
58-
<textarea class="form-control need-autogrow required" id="content" name="content" rows="15">{{.topic.Content}}</textarea>
58+
<textarea class="form-control need-autogrow required main-textarea" id="content" name="content" rows="15">{{.topic.Content}}</textarea>
5959
<div class="content-preview"></div>
6060
</div>
6161
</div>

websites/code/thirdparty/getpkg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ go get -u -v github.com/qiniu/api.v6
1818
go get -u -v github.com/dchest/captcha
1919

2020
cp /etc/hosts ~/hosts
21-
echo "golang.org 101.251.196.90" > /etc/hosts
22-
#echo "127.0.0.1 golang.org" > /etc/hosts
21+
#echo "golang.org 101.251.196.90" > /etc/hosts
22+
echo "127.0.0.1 golang.org" > /etc/hosts
2323

2424
trap "mv ~/hosts /etc/hosts" HUP INT QUIT TSTP
2525

websites/databases/studygolang_db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CREATE TABLE `topics` (
1616
`lastreplytime` timestamp NOT NULL DEFAULT 0 COMMENT '最后回复时间',
1717
`flag` tinyint NOT NULL DEFAULT 0 COMMENT '审核标识,0-未审核;1-已审核;2-审核删除;3-用户自己删除',
1818
`editor_uid` int unsigned NOT NULL DEFAULT 0 COMMENT '最后编辑人',
19+
`top` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '置顶,0否,1置顶',
1920
`ctime` timestamp NOT NULL DEFAULT 0,
2021
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
2122
PRIMARY KEY (`tid`),

websites/databases/studygolang_init.sql

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,103 @@ INSERT INTO `role`(`name`) VALUES('副站长');
44
INSERT INTO `role`(`name`) VALUES('超级管理员');
55
INSERT INTO `role`(`name`) VALUES('社区管理员');
66
INSERT INTO `role`(`name`) VALUES('资源管理员');
7-
INSERT INTO `role`(`name`) VALUES('酷站管理员');
7+
INSERT INTO `role`(`name`) VALUES('文章管理员');
8+
INSERT INTO `role`(`name`) VALUES('晨读管理员');
89
INSERT INTO `role`(`name`) VALUES('高级会员');
910
INSERT INTO `role`(`name`) VALUES('中级会员');
1011
INSERT INTO `role`(`name`) VALUES('初级会员');
1112

13+
INSERT INTO `authority` (`aid`, `name`, `menu1`, `menu2`, `route`, `op_user`, `ctime`, `mtime`)
14+
VALUES
15+
(1, '用户管理', 0, 0, '', 'polaris', '2014-08-17 11:06:50', '2014-08-16 10:51:13'),
16+
(2, '权限管理', 1, 0, '/admin/user/auth/list', 'polaris', '2014-08-17 11:06:50', '2014-08-16 12:05:55'),
17+
(3, '权限查询', 1, 2, '/admin/user/auth/query.html', 'polaris', '2014-08-17 11:06:50', '2014-08-17 11:06:50'),
18+
(4, '新建权限', 1, 2, '/admin/user/auth/new', 'polaris', '2014-08-17 11:06:50', '2014-08-17 21:18:56'),
19+
(5, '修改权限', 1, 2, '/admin/user/auth/modify', 'polaris', '2014-08-18 23:56:11', '2014-10-04 23:16:31'),
20+
(6, '删除权限', 1, 2, '/admin/user/auth/del', 'polaris', '2014-08-17 22:12:30', '2014-08-17 22:12:30'),
21+
(7, '角色管理', 1, 0, '/admin/user/role/list', 'polaris', '2014-08-17 23:03:40', '2014-08-17 23:03:40'),
22+
(8, '角色查询', 1, 7, '/admin/user/role/query.html', 'polaris', '2014-08-18 23:54:44', '2014-08-18 23:54:44'),
23+
(9, '新建角色', 1, 7, '/admin/user/role/new', 'polaris', '2014-08-18 23:55:10', '2014-08-18 23:55:10'),
24+
(10, '修改角色', 1, 7, '/admin/user/role/modify', 'polaris', '2014-08-18 23:55:24', '2014-08-18 23:55:24'),
25+
(11, '删除角色', 1, 7, '/admin/user/role/del', 'polaris', '2014-08-18 23:57:20', '2014-08-18 23:57:44'),
26+
(12, '用户管理', 1, 0, '/admin/user/user/list', 'polaris', '2014-08-19 00:20:41', '2014-08-19 00:20:41'),
27+
(13, '用户查询', 1, 12, '/admin/user/user/query.html', 'polaris', '2014-08-19 08:43:55', '2014-08-19 08:43:55'),
28+
(14, '用户详情', 1, 12, '/admin/user/user/detail', 'polaris', '2014-08-19 21:14:07', '2014-08-19 21:14:07');
29+
30+
INSERT INTO `role_authority` (`roleid`, `aid`, `op_user`, `ctime`)
31+
VALUES
32+
(0, 19, 'polaris', '2015-07-14 13:49:03'),
33+
(0, 20, 'polaris', '2015-07-14 13:49:03'),
34+
(0, 21, 'polaris', '2015-07-14 13:49:03'),
35+
(0, 22, 'polaris', '2015-07-14 13:49:03'),
36+
(0, 23, 'polaris', '2015-07-14 13:49:03'),
37+
(0, 24, 'polaris', '2015-07-14 13:49:03'),
38+
(0, 25, 'polaris', '2015-07-14 13:49:03'),
39+
(0, 26, 'polaris', '2015-07-14 13:49:03'),
40+
(0, 27, 'polaris', '2015-07-14 13:49:03'),
41+
(0, 28, 'polaris', '2014-10-30 22:56:21'),
42+
(0, 29, 'polaris', '2014-10-30 22:56:21'),
43+
(0, 30, 'polaris', '2014-10-30 22:56:21'),
44+
(0, 31, 'polaris', '2014-10-30 22:56:21'),
45+
(0, 37, 'polaris', '2015-07-14 13:49:03'),
46+
(1, 1, 'polaris', '2015-07-14 13:54:30'),
47+
(1, 2, 'polaris', '2015-07-14 13:54:30'),
48+
(1, 3, 'polaris', '2015-07-14 13:54:30'),
49+
(1, 4, 'polaris', '2015-07-14 13:54:30'),
50+
(1, 5, 'polaris', '2015-07-14 13:54:30'),
51+
(1, 6, 'polaris', '2015-07-14 13:54:30'),
52+
(1, 7, 'polaris', '2015-07-14 13:54:30'),
53+
(1, 8, 'polaris', '2015-07-14 13:54:30'),
54+
(1, 9, 'polaris', '2015-07-14 13:54:30'),
55+
(1, 10, 'polaris', '2015-07-14 13:54:30'),
56+
(1, 11, 'polaris', '2015-07-14 13:54:30'),
57+
(1, 12, 'polaris', '2015-07-14 13:54:30'),
58+
(1, 13, 'polaris', '2015-07-14 13:54:30'),
59+
(1, 14, 'polaris', '2015-07-14 13:54:30'),
60+
(1, 15, 'polaris', '2015-07-14 13:54:30'),
61+
(1, 16, 'polaris', '2015-07-14 13:54:30'),
62+
(1, 17, 'polaris', '2015-07-14 13:54:30'),
63+
(1, 18, 'polaris', '2015-07-14 13:54:30'),
64+
(1, 19, 'polaris', '2015-07-14 13:54:30'),
65+
(1, 20, 'polaris', '2015-07-14 13:54:30'),
66+
(1, 21, 'polaris', '2015-07-14 13:54:30'),
67+
(1, 22, 'polaris', '2015-07-14 13:54:30'),
68+
(1, 23, 'polaris', '2015-07-14 13:54:30'),
69+
(1, 24, 'polaris', '2015-07-14 13:54:30'),
70+
(1, 25, 'polaris', '2015-07-14 13:54:30'),
71+
(1, 26, 'polaris', '2015-07-14 13:54:30'),
72+
(1, 27, 'polaris', '2015-07-14 13:54:30'),
73+
(1, 28, 'polaris', '2015-07-14 13:54:30'),
74+
(1, 29, 'polaris', '2015-07-14 13:54:30'),
75+
(1, 30, 'polaris', '2015-07-14 13:54:30'),
76+
(1, 31, 'polaris', '2015-07-14 13:54:30'),
77+
(1, 32, 'polaris', '2015-07-14 13:54:30'),
78+
(1, 33, 'polaris', '2015-07-14 13:54:30'),
79+
(1, 34, 'polaris', '2015-07-14 13:54:30'),
80+
(1, 35, 'polaris', '2015-07-14 13:54:30'),
81+
(1, 36, 'polaris', '2015-07-14 13:54:30'),
82+
(1, 37, 'polaris', '2015-07-14 13:54:30'),
83+
(1, 38, 'polaris', '2015-07-14 13:54:30'),
84+
(6, 19, 'polaris', '2015-07-14 13:51:31'),
85+
(6, 20, 'polaris', '2015-07-14 13:51:31'),
86+
(6, 21, 'polaris', '2015-07-14 13:51:31'),
87+
(6, 22, 'polaris', '2015-07-14 13:51:31'),
88+
(6, 23, 'polaris', '2015-07-14 13:51:31'),
89+
(6, 24, 'polaris', '2015-07-14 13:51:31'),
90+
(6, 25, 'polaris', '2015-07-14 13:51:31'),
91+
(6, 26, 'polaris', '2015-07-14 13:51:31'),
92+
(6, 27, 'polaris', '2015-07-14 13:51:31'),
93+
(6, 37, 'polaris', '2015-07-14 13:51:31'),
94+
(7, 28, 'polaris', '2014-10-31 10:12:19'),
95+
(7, 29, 'polaris', '2014-10-31 10:12:19'),
96+
(7, 30, 'polaris', '2014-10-31 10:12:19'),
97+
(7, 31, 'polaris', '2014-10-31 10:12:19');
98+
99+
INSERT INTO `user_role` (`uid`, `roleid`, `ctime`)
100+
VALUES
101+
(1, 1, '2013-03-15 14:38:09');
102+
103+
12104
-- 帖子节点表
13105
INSERT INTO `topics_node`(`parent`, `name`, `intro`) VALUES(0, 'Golang', 'Go语言基本问题探讨');
14106
INSERT INTO `topics_node`(`parent`, `name`, `intro`) VALUES(1, 'Go基础', 'Go语言基础、语法、规范等');

0 commit comments

Comments
 (0)