Browse Source

golint fixed for parts of routers root, dev, user and org dirs (#167)

* golint fixed for parts of routers root, dev and org dirs

* add user/auth.go golint fixed

* rename unnecessary exported to unexported and user dir golint fixed
Lunny Xiao 3 years ago
parent
commit
cf045b029c

+ 1 - 0
routers/dev/template.go

@@ -11,6 +11,7 @@ import (
11 11
 	"code.gitea.io/gitea/modules/setting"
12 12
 )
13 13
 
14
+// TemplatePreview render for previewing the indicated template
14 15
 func TemplatePreview(ctx *context.Context) {
15 16
 	ctx.Data["User"] = models.User{Name: "Unknown"}
16 17
 	ctx.Data["AppName"] = setting.AppName

+ 22 - 9
routers/home.go

@@ -17,17 +17,22 @@ import (
17 17
 )
18 18
 
19 19
 const (
20
-	HOME                  base.TplName = "home"
21
-	EXPLORE_REPOS         base.TplName = "explore/repos"
22
-	EXPLORE_USERS         base.TplName = "explore/users"
23
-	EXPLORE_ORGANIZATIONS base.TplName = "explore/organizations"
20
+	// tplHome home page template
21
+	tplHome base.TplName = "home"
22
+	// tplExploreRepos explore repositories page template
23
+	tplExploreRepos base.TplName = "explore/repos"
24
+	// tplExploreUsers explore users page template
25
+	tplExploreUsers base.TplName = "explore/users"
26
+	// tplExploreOrganizations explore organizations page template
27
+	tplExploreOrganizations base.TplName = "explore/organizations"
24 28
 )
25 29
 
30
+// Home render home page
26 31
 func Home(ctx *context.Context) {
27 32
 	if ctx.IsSigned {
28 33
 		if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
29 34
 			ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
30
-			ctx.HTML(200, user.ACTIVATE)
35
+			ctx.HTML(200, user.TplActivate)
31 36
 		} else {
32 37
 			user.Dashboard(ctx)
33 38
 		}
@@ -42,9 +47,10 @@ func Home(ctx *context.Context) {
42 47
 	}
43 48
 
44 49
 	ctx.Data["PageIsHome"] = true
45
-	ctx.HTML(200, HOME)
50
+	ctx.HTML(200, tplHome)
46 51
 }
47 52
 
53
+// RepoSearchOptions when calling search repositories
48 54
 type RepoSearchOptions struct {
49 55
 	Counter  func(bool) int64
50 56
 	Ranger   func(int, int) ([]*models.Repository, error)
@@ -54,6 +60,7 @@ type RepoSearchOptions struct {
54 60
 	TplName  base.TplName
55 61
 }
56 62
 
63
+// RenderRepoSearch render repositories search page
57 64
 func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
58 65
 	page := ctx.QueryInt("page")
59 66
 	if page <= 0 {
@@ -102,6 +109,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
102 109
 	ctx.HTML(200, opts.TplName)
103 110
 }
104 111
 
112
+// ExploreRepos render explore repositories page
105 113
 func ExploreRepos(ctx *context.Context) {
106 114
 	ctx.Data["Title"] = ctx.Tr("explore")
107 115
 	ctx.Data["PageIsExplore"] = true
@@ -112,10 +120,11 @@ func ExploreRepos(ctx *context.Context) {
112 120
 		Ranger:   models.GetRecentUpdatedRepositories,
113 121
 		PageSize: setting.UI.ExplorePagingNum,
114 122
 		OrderBy:  "updated_unix DESC",
115
-		TplName:  EXPLORE_REPOS,
123
+		TplName:  tplExploreRepos,
116 124
 	})
117 125
 }
118 126
 
127
+// UserSearchOptions options when render search user page
119 128
 type UserSearchOptions struct {
120 129
 	Type     models.UserType
121 130
 	Counter  func() int64
@@ -125,6 +134,7 @@ type UserSearchOptions struct {
125 134
 	TplName  base.TplName
126 135
 }
127 136
 
137
+// RenderUserSearch render user search page
128 138
 func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
129 139
 	page := ctx.QueryInt("page")
130 140
 	if page <= 1 {
@@ -166,6 +176,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
166 176
 	ctx.HTML(200, opts.TplName)
167 177
 }
168 178
 
179
+// ExploreUsers render explore users page
169 180
 func ExploreUsers(ctx *context.Context) {
170 181
 	ctx.Data["Title"] = ctx.Tr("explore")
171 182
 	ctx.Data["PageIsExplore"] = true
@@ -177,10 +188,11 @@ func ExploreUsers(ctx *context.Context) {
177 188
 		Ranger:   models.Users,
178 189
 		PageSize: setting.UI.ExplorePagingNum,
179 190
 		OrderBy:  "name ASC",
180
-		TplName:  EXPLORE_USERS,
191
+		TplName:  tplExploreUsers,
181 192
 	})
182 193
 }
183 194
 
195
+// ExploreOrganizations render explore organizations page
184 196
 func ExploreOrganizations(ctx *context.Context) {
185 197
 	ctx.Data["Title"] = ctx.Tr("explore")
186 198
 	ctx.Data["PageIsExplore"] = true
@@ -192,10 +204,11 @@ func ExploreOrganizations(ctx *context.Context) {
192 204
 		Ranger:   models.Organizations,
193 205
 		PageSize: setting.UI.ExplorePagingNum,
194 206
 		OrderBy:  "name ASC",
195
-		TplName:  EXPLORE_ORGANIZATIONS,
207
+		TplName:  tplExploreOrganizations,
196 208
 	})
197 209
 }
198 210
 
211
+// NotFound render 404 page
199 212
 func NotFound(ctx *context.Context) {
200 213
 	ctx.Data["Title"] = "Page Not Found"
201 214
 	ctx.Handle(404, "home.NotFound", nil)

+ 24 - 19
routers/install.go

@@ -34,7 +34,8 @@ import (
34 34
 )
35 35
 
36 36
 const (
37
-	INSTALL base.TplName = "install"
37
+	// tplInstall template for installation page
38
+	tplInstall base.TplName = "install"
38 39
 )
39 40
 
40 41
 func checkRunMode() {
@@ -49,6 +50,7 @@ func checkRunMode() {
49 50
 	log.Info("Run Mode: %s", strings.Title(macaron.Env))
50 51
 }
51 52
 
53
+// NewServices init new services
52 54
 func NewServices() {
53 55
 	setting.NewServices()
54 56
 	mailer.NewContext()
@@ -97,6 +99,7 @@ func GlobalInit() {
97 99
 	}
98 100
 }
99 101
 
102
+// InstallInit prepare for rendering installation page
100 103
 func InstallInit(ctx *context.Context) {
101 104
 	if setting.InstallLock {
102 105
 		ctx.Handle(404, "Install", errors.New("Installation is prohibited"))
@@ -116,6 +119,7 @@ func InstallInit(ctx *context.Context) {
116 119
 	ctx.Data["DbOptions"] = dbOpts
117 120
 }
118 121
 
122
+// Install render installation page
119 123
 func Install(ctx *context.Context) {
120 124
 	form := auth.InstallForm{}
121 125
 
@@ -175,9 +179,10 @@ func Install(ctx *context.Context) {
175 179
 	form.RequireSignInView = setting.Service.RequireSignInView
176 180
 
177 181
 	auth.AssignForm(form, ctx.Data)
178
-	ctx.HTML(200, INSTALL)
182
+	ctx.HTML(200, tplInstall)
179 183
 }
180 184
 
185
+// InstallPost response for submit install items
181 186
 func InstallPost(ctx *context.Context, form auth.InstallForm) {
182 187
 	ctx.Data["CurDbOption"] = form.DbType
183 188
 
@@ -191,12 +196,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
191 196
 			ctx.Data["Err_Admin"] = true
192 197
 		}
193 198
 
194
-		ctx.HTML(200, INSTALL)
199
+		ctx.HTML(200, tplInstall)
195 200
 		return
196 201
 	}
197 202
 
198 203
 	if _, err := exec.LookPath("git"); err != nil {
199
-		ctx.RenderWithErr(ctx.Tr("install.test_git_failed", err), INSTALL, &form)
204
+		ctx.RenderWithErr(ctx.Tr("install.test_git_failed", err), tplInstall, &form)
200 205
 		return
201 206
 	}
202 207
 
@@ -214,12 +219,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
214 219
 	if (models.DbCfg.Type == "sqlite3" || models.DbCfg.Type == "tidb") &&
215 220
 		len(models.DbCfg.Path) == 0 {
216 221
 		ctx.Data["Err_DbPath"] = true
217
-		ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), INSTALL, &form)
222
+		ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), tplInstall, &form)
218 223
 		return
219 224
 	} else if models.DbCfg.Type == "tidb" &&
220 225
 		strings.ContainsAny(path.Base(models.DbCfg.Path), ".-") {
221 226
 		ctx.Data["Err_DbPath"] = true
222
-		ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), INSTALL, &form)
227
+		ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), tplInstall, &form)
223 228
 		return
224 229
 	}
225 230
 
@@ -228,10 +233,10 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
228 233
 	if err := models.NewTestEngine(x); err != nil {
229 234
 		if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
230 235
 			ctx.Data["Err_DbType"] = true
231
-			ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &form)
236
+			ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), tplInstall, &form)
232 237
 		} else {
233 238
 			ctx.Data["Err_DbSetting"] = true
234
-			ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), INSTALL, &form)
239
+			ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), tplInstall, &form)
235 240
 		}
236 241
 		return
237 242
 	}
@@ -240,7 +245,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
240 245
 	form.RepoRootPath = strings.Replace(form.RepoRootPath, "\\", "/", -1)
241 246
 	if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil {
242 247
 		ctx.Data["Err_RepoRootPath"] = true
243
-		ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), INSTALL, &form)
248
+		ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), tplInstall, &form)
244 249
 		return
245 250
 	}
246 251
 
@@ -248,14 +253,14 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
248 253
 	form.LogRootPath = strings.Replace(form.LogRootPath, "\\", "/", -1)
249 254
 	if err := os.MkdirAll(form.LogRootPath, os.ModePerm); err != nil {
250 255
 		ctx.Data["Err_LogRootPath"] = true
251
-		ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), INSTALL, &form)
256
+		ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), tplInstall, &form)
252 257
 		return
253 258
 	}
254 259
 
255 260
 	currentUser, match := setting.IsRunUserMatchCurrentUser(form.RunUser)
256 261
 	if !match {
257 262
 		ctx.Data["Err_RunUser"] = true
258
-		ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, currentUser), INSTALL, &form)
263
+		ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, currentUser), tplInstall, &form)
259 264
 		return
260 265
 	}
261 266
 
@@ -263,7 +268,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
263 268
 	if form.DisableRegistration && len(form.AdminName) == 0 {
264 269
 		ctx.Data["Err_Services"] = true
265 270
 		ctx.Data["Err_Admin"] = true
266
-		ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), INSTALL, form)
271
+		ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), tplInstall, form)
267 272
 		return
268 273
 	}
269 274
 
@@ -271,13 +276,13 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
271 276
 	if len(form.AdminName) > 0 && len(form.AdminPasswd) == 0 {
272 277
 		ctx.Data["Err_Admin"] = true
273 278
 		ctx.Data["Err_AdminPasswd"] = true
274
-		ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), INSTALL, form)
279
+		ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form)
275 280
 		return
276 281
 	}
277 282
 	if form.AdminPasswd != form.AdminConfirmPasswd {
278 283
 		ctx.Data["Err_Admin"] = true
279 284
 		ctx.Data["Err_AdminPasswd"] = true
280
-		ctx.RenderWithErr(ctx.Tr("form.password_not_match"), INSTALL, form)
285
+		ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form)
281 286
 		return
282 287
 	}
283 288
 
@@ -347,12 +352,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
347 352
 
348 353
 	err := os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
349 354
 	if err != nil {
350
-		ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
355
+		ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
351 356
 		return
352 357
 	}
353 358
 
354 359
 	if err := cfg.SaveTo(setting.CustomConf); err != nil {
355
-		ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
360
+		ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
356 361
 		return
357 362
 	}
358 363
 
@@ -372,7 +377,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
372 377
 				setting.InstallLock = false
373 378
 				ctx.Data["Err_AdminName"] = true
374 379
 				ctx.Data["Err_AdminEmail"] = true
375
-				ctx.RenderWithErr(ctx.Tr("install.invalid_admin_setting", err), INSTALL, &form)
380
+				ctx.RenderWithErr(ctx.Tr("install.invalid_admin_setting", err), tplInstall, &form)
376 381
 				return
377 382
 			}
378 383
 			log.Info("Admin account already exist")
@@ -381,11 +386,11 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
381 386
 
382 387
 		// Auto-login for admin
383 388
 		if err := ctx.Session.Set("uid", u.ID); err != nil {
384
-			ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
389
+			ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
385 390
 			return
386 391
 		}
387 392
 		if err := ctx.Session.Set("uname", u.Name); err != nil {
388
-			ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
393
+			ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
389 394
 			return
390 395
 		}
391 396
 	}

+ 9 - 4
routers/org/members.go

@@ -15,10 +15,13 @@ import (
15 15
 )
16 16
 
17 17
 const (
18
-	MEMBERS       base.TplName = "org/member/members"
19
-	MEMBER_INVITE base.TplName = "org/member/invite"
18
+	// tplMembers template for organization members page
19
+	tplMembers base.TplName = "org/member/members"
20
+	// tplMemberInvite template for orgnization invite page
21
+	tplMemberInvite base.TplName = "org/member/invite"
20 22
 )
21 23
 
24
+// Members render orgnization users page
22 25
 func Members(ctx *context.Context) {
23 26
 	org := ctx.Org.Organization
24 27
 	ctx.Data["Title"] = org.FullName
@@ -30,9 +33,10 @@ func Members(ctx *context.Context) {
30 33
 	}
31 34
 	ctx.Data["Members"] = org.Members
32 35
 
33
-	ctx.HTML(200, MEMBERS)
36
+	ctx.HTML(200, tplMembers)
34 37
 }
35 38
 
39
+// MembersAction response for operation to a member of orgnization
36 40
 func MembersAction(ctx *context.Context) {
37 41
 	uid := com.StrTo(ctx.Query("uid")).MustInt64()
38 42
 	if uid == 0 {
@@ -91,6 +95,7 @@ func MembersAction(ctx *context.Context) {
91 95
 	}
92 96
 }
93 97
 
98
+// Invitation render organization invitation page
94 99
 func Invitation(ctx *context.Context) {
95 100
 	org := ctx.Org.Organization
96 101
 	ctx.Data["Title"] = org.FullName
@@ -119,5 +124,5 @@ func Invitation(ctx *context.Context) {
119 124
 		return
120 125
 	}
121 126
 
122
-	ctx.HTML(200, MEMBER_INVITE)
127
+	ctx.HTML(200, tplMemberInvite)
123 128
 }

+ 9 - 6
routers/org/org.go

@@ -14,19 +14,22 @@ import (
14 14
 )
15 15
 
16 16
 const (
17
-	CREATE base.TplName = "org/create"
17
+	// tplCreateOrg template path for create organization
18
+	tplCreateOrg base.TplName = "org/create"
18 19
 )
19 20
 
21
+// Create render the page for create organization
20 22
 func Create(ctx *context.Context) {
21 23
 	ctx.Data["Title"] = ctx.Tr("new_org")
22
-	ctx.HTML(200, CREATE)
24
+	ctx.HTML(200, tplCreateOrg)
23 25
 }
24 26
 
27
+// CreatePost response for create organization
25 28
 func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
26 29
 	ctx.Data["Title"] = ctx.Tr("new_org")
27 30
 
28 31
 	if ctx.HasError() {
29
-		ctx.HTML(200, CREATE)
32
+		ctx.HTML(200, tplCreateOrg)
30 33
 		return
31 34
 	}
32 35
 
@@ -40,11 +43,11 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
40 43
 		ctx.Data["Err_OrgName"] = true
41 44
 		switch {
42 45
 		case models.IsErrUserAlreadyExist(err):
43
-			ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), CREATE, &form)
46
+			ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
44 47
 		case models.IsErrNameReserved(err):
45
-			ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form)
48
+			ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form)
46 49
 		case models.IsErrNamePatternNotAllowed(err):
47
-			ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form)
50
+			ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
48 51
 		default:
49 52
 			ctx.Handle(500, "CreateOrganization", err)
50 53
 		}

+ 20 - 10
routers/org/setting.go

@@ -17,23 +17,28 @@ import (
17 17
 )
18 18
 
19 19
 const (
20
-	SETTINGS_OPTIONS base.TplName = "org/settings/options"
21
-	SETTINGS_DELETE  base.TplName = "org/settings/delete"
22
-	SETTINGS_HOOKS   base.TplName = "org/settings/hooks"
20
+	// tplSettingsOptions template path for render settings
21
+	tplSettingsOptions base.TplName = "org/settings/options"
22
+	// tplSettingsDelete template path for render delete repository
23
+	tplSettingsDelete base.TplName = "org/settings/delete"
24
+	// tplSettingsHooks template path for render hook settings
25
+	tplSettingsHooks base.TplName = "org/settings/hooks"
23 26
 )
24 27
 
28
+// Settings render the main settings page
25 29
 func Settings(ctx *context.Context) {
26 30
 	ctx.Data["Title"] = ctx.Tr("org.settings")
27 31
 	ctx.Data["PageIsSettingsOptions"] = true
28
-	ctx.HTML(200, SETTINGS_OPTIONS)
32
+	ctx.HTML(200, tplSettingsOptions)
29 33
 }
30 34
 
35
+// SettingsPost response for settings change submited
31 36
 func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
32 37
 	ctx.Data["Title"] = ctx.Tr("org.settings")
33 38
 	ctx.Data["PageIsSettingsOptions"] = true
34 39
 
35 40
 	if ctx.HasError() {
36
-		ctx.HTML(200, SETTINGS_OPTIONS)
41
+		ctx.HTML(200, tplSettingsOptions)
37 42
 		return
38 43
 	}
39 44
 
@@ -47,12 +52,12 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
47 52
 			return
48 53
 		} else if isExist {
49 54
 			ctx.Data["OrgName"] = true
50
-			ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SETTINGS_OPTIONS, &form)
55
+			ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSettingsOptions, &form)
51 56
 			return
52 57
 		} else if err = models.ChangeUserName(org, form.Name); err != nil {
53 58
 			if err == models.ErrUserNameIllegal {
54 59
 				ctx.Data["OrgName"] = true
55
-				ctx.RenderWithErr(ctx.Tr("form.illegal_username"), SETTINGS_OPTIONS, &form)
60
+				ctx.RenderWithErr(ctx.Tr("form.illegal_username"), tplSettingsOptions, &form)
56 61
 			} else {
57 62
 				ctx.Handle(500, "ChangeUserName", err)
58 63
 			}
@@ -83,6 +88,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateOrgSettingForm) {
83 88
 	ctx.Redirect(ctx.Org.OrgLink + "/settings")
84 89
 }
85 90
 
91
+// SettingsAvatar response for change avatar on settings page
86 92
 func SettingsAvatar(ctx *context.Context, form auth.AvatarForm) {
87 93
 	form.Source = auth.AvatarLocal
88 94
 	if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
@@ -94,6 +100,7 @@ func SettingsAvatar(ctx *context.Context, form auth.AvatarForm) {
94 100
 	ctx.Redirect(ctx.Org.OrgLink + "/settings")
95 101
 }
96 102
 
103
+// SettingsDeleteAvatar response for delete avatar on setings page
97 104
 func SettingsDeleteAvatar(ctx *context.Context) {
98 105
 	if err := ctx.Org.Organization.DeleteAvatar(); err != nil {
99 106
 		ctx.Flash.Error(err.Error())
@@ -102,6 +109,7 @@ func SettingsDeleteAvatar(ctx *context.Context) {
102 109
 	ctx.Redirect(ctx.Org.OrgLink + "/settings")
103 110
 }
104 111
 
112
+// SettingsDelete response for delete repository
105 113
 func SettingsDelete(ctx *context.Context) {
106 114
 	ctx.Data["Title"] = ctx.Tr("org.settings")
107 115
 	ctx.Data["PageIsSettingsDelete"] = true
@@ -110,7 +118,7 @@ func SettingsDelete(ctx *context.Context) {
110 118
 	if ctx.Req.Method == "POST" {
111 119
 		if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
112 120
 			if models.IsErrUserNotExist(err) {
113
-				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
121
+				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil)
114 122
 			} else {
115 123
 				ctx.Handle(500, "UserSignIn", err)
116 124
 			}
@@ -131,9 +139,10 @@ func SettingsDelete(ctx *context.Context) {
131 139
 		return
132 140
 	}
133 141
 
134
-	ctx.HTML(200, SETTINGS_DELETE)
142
+	ctx.HTML(200, tplSettingsDelete)
135 143
 }
136 144
 
145
+// Webhooks render webhook list page
137 146
 func Webhooks(ctx *context.Context) {
138 147
 	ctx.Data["Title"] = ctx.Tr("org.settings")
139 148
 	ctx.Data["PageIsSettingsHooks"] = true
@@ -147,9 +156,10 @@ func Webhooks(ctx *context.Context) {
147 156
 	}
148 157
 
149 158
 	ctx.Data["Webhooks"] = ws
150
-	ctx.HTML(200, SETTINGS_HOOKS)
159
+	ctx.HTML(200, tplSettingsHooks)
151 160
 }
152 161
 
162
+// DeleteWebhook response for delete webhook
153 163
 func DeleteWebhook(ctx *context.Context) {
154 164
 	if err := models.DeleteWebhookByOrgID(ctx.Org.Organization.ID, ctx.QueryInt64("id")); err != nil {
155 165
 		ctx.Flash.Error("DeleteWebhookByOrgID: " + err.Error())

+ 27 - 13
routers/org/teams.go

@@ -17,12 +17,17 @@ import (
17 17
 )
18 18
 
19 19
 const (
20
-	TEAMS             base.TplName = "org/team/teams"
21
-	TEAM_NEW          base.TplName = "org/team/new"
22
-	TEAM_MEMBERS      base.TplName = "org/team/members"
23
-	TEAM_REPOSITORIES base.TplName = "org/team/repositories"
20
+	// tplTeams template path for teams list page
21
+	tplTeams base.TplName = "org/team/teams"
22
+	// tplTeamNew template path for create new team page
23
+	tplTeamNew base.TplName = "org/team/new"
24
+	// tplTeamMembers template path for showing team members page
25
+	tplTeamMembers base.TplName = "org/team/members"
26
+	// tplTeamRepositories template path for showing team repositories page
27
+	tplTeamRepositories base.TplName = "org/team/repositories"
24 28
 )
25 29
 
30
+// Teams render teams list page
26 31
 func Teams(ctx *context.Context) {
27 32
 	org := ctx.Org.Organization
28 33
 	ctx.Data["Title"] = org.FullName
@@ -36,9 +41,10 @@ func Teams(ctx *context.Context) {
36 41
 	}
37 42
 	ctx.Data["Teams"] = org.Teams
38 43
 
39
-	ctx.HTML(200, TEAMS)
44
+	ctx.HTML(200, tplTeams)
40 45
 }
41 46
 
47
+// TeamsAction response for join, leave, remove, add operations to team
42 48
 func TeamsAction(ctx *context.Context) {
43 49
 	uid := com.StrTo(ctx.Query("uid")).MustInt64()
44 50
 	if uid == 0 {
@@ -107,6 +113,7 @@ func TeamsAction(ctx *context.Context) {
107 113
 	}
108 114
 }
109 115
 
116
+// TeamsRepoAction operate team's repository
110 117
 func TeamsRepoAction(ctx *context.Context) {
111 118
 	if !ctx.Org.IsOwner {
112 119
 		ctx.Error(404)
@@ -141,14 +148,16 @@ func TeamsRepoAction(ctx *context.Context) {
141 148
 	ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories")
142 149
 }
143 150
 
151
+// NewTeam render create new team page
144 152
 func NewTeam(ctx *context.Context) {
145 153
 	ctx.Data["Title"] = ctx.Org.Organization.FullName
146 154
 	ctx.Data["PageIsOrgTeams"] = true
147 155
 	ctx.Data["PageIsOrgTeamsNew"] = true
148 156
 	ctx.Data["Team"] = &models.Team{}
149
-	ctx.HTML(200, TEAM_NEW)
157
+	ctx.HTML(200, tplTeamNew)
150 158
 }
151 159
 
160
+// NewTeamPost response for create new team
152 161
 func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
153 162
 	ctx.Data["Title"] = ctx.Org.Organization.FullName
154 163
 	ctx.Data["PageIsOrgTeams"] = true
@@ -163,7 +172,7 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
163 172
 	ctx.Data["Team"] = t
164 173
 
165 174
 	if ctx.HasError() {
166
-		ctx.HTML(200, TEAM_NEW)
175
+		ctx.HTML(200, tplTeamNew)
167 176
 		return
168 177
 	}
169 178
 
@@ -171,7 +180,7 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
171 180
 		ctx.Data["Err_TeamName"] = true
172 181
 		switch {
173 182
 		case models.IsErrTeamAlreadyExist(err):
174
-			ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), TEAM_NEW, &form)
183
+			ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
175 184
 		default:
176 185
 			ctx.Handle(500, "NewTeam", err)
177 186
 		}
@@ -181,6 +190,7 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
181 190
 	ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
182 191
 }
183 192
 
193
+// TeamMembers render team members page
184 194
 func TeamMembers(ctx *context.Context) {
185 195
 	ctx.Data["Title"] = ctx.Org.Team.Name
186 196
 	ctx.Data["PageIsOrgTeams"] = true
@@ -188,9 +198,10 @@ func TeamMembers(ctx *context.Context) {
188 198
 		ctx.Handle(500, "GetMembers", err)
189 199
 		return
190 200
 	}
191
-	ctx.HTML(200, TEAM_MEMBERS)
201
+	ctx.HTML(200, tplTeamMembers)
192 202
 }
193 203
 
204
+// TeamRepositories show the repositories of team
194 205
 func TeamRepositories(ctx *context.Context) {
195 206
 	ctx.Data["Title"] = ctx.Org.Team.Name
196 207
 	ctx.Data["PageIsOrgTeams"] = true
@@ -198,17 +209,19 @@ func TeamRepositories(ctx *context.Context) {
198 209
 		ctx.Handle(500, "GetRepositories", err)
199 210
 		return
200 211
 	}
201
-	ctx.HTML(200, TEAM_REPOSITORIES)
212
+	ctx.HTML(200, tplTeamRepositories)
202 213
 }
203 214
 
215
+// EditTeam render team edit page
204 216
 func EditTeam(ctx *context.Context) {
205 217
 	ctx.Data["Title"] = ctx.Org.Organization.FullName
206 218
 	ctx.Data["PageIsOrgTeams"] = true
207 219
 	ctx.Data["team_name"] = ctx.Org.Team.Name
208 220
 	ctx.Data["desc"] = ctx.Org.Team.Description
209
-	ctx.HTML(200, TEAM_NEW)
221
+	ctx.HTML(200, tplTeamNew)
210 222
 }
211 223
 
224
+// EditTeamPost response for modify team information
212 225
 func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
213 226
 	t := ctx.Org.Team
214 227
 	ctx.Data["Title"] = ctx.Org.Organization.FullName
@@ -216,7 +229,7 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
216 229
 	ctx.Data["Team"] = t
217 230
 
218 231
 	if ctx.HasError() {
219
-		ctx.HTML(200, TEAM_NEW)
232
+		ctx.HTML(200, tplTeamNew)
220 233
 		return
221 234
 	}
222 235
 
@@ -247,7 +260,7 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
247 260
 		ctx.Data["Err_TeamName"] = true
248 261
 		switch {
249 262
 		case models.IsErrTeamAlreadyExist(err):
250
-			ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), TEAM_NEW, &form)
263
+			ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), tplTeamNew, &form)
251 264
 		default:
252 265
 			ctx.Handle(500, "UpdateTeam", err)
253 266
 		}
@@ -256,6 +269,7 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
256 269
 	ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName)
257 270
 }
258 271
 
272
+// DeleteTeam response for the delete team request
259 273
 func DeleteTeam(ctx *context.Context) {
260 274
 	if err := models.DeleteTeam(ctx.Org.Team); err != nil {
261 275
 		ctx.Flash.Error("DeleteTeam: " + err.Error())

+ 47 - 33
routers/user/auth.go

@@ -19,11 +19,14 @@ import (
19 19
 )
20 20
 
21 21
 const (
22
-	SIGNIN          base.TplName = "user/auth/signin"
23
-	SIGNUP          base.TplName = "user/auth/signup"
24
-	ACTIVATE        base.TplName = "user/auth/activate"
25
-	FORGOT_PASSWORD base.TplName = "user/auth/forgot_passwd"
26
-	RESET_PASSWORD  base.TplName = "user/auth/reset_passwd"
22
+	// tplSignIn template for sign in page
23
+	tplSignIn base.TplName = "user/auth/signin"
24
+	// tplSignUp template path for sign up page
25
+	tplSignUp base.TplName = "user/auth/signup"
26
+	// TplActivate template path for activate user
27
+	TplActivate       base.TplName = "user/auth/activate"
28
+	tplForgotPassword base.TplName = "user/auth/forgot_passwd"
29
+	tplResetPassword  base.TplName = "user/auth/reset_passwd"
27 30
 )
28 31
 
29 32
 // AutoSignIn reads cookie and try to auto-login.
@@ -66,6 +69,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
66 69
 	return true, nil
67 70
 }
68 71
 
72
+// SignIn render sign in page
69 73
 func SignIn(ctx *context.Context) {
70 74
 	ctx.Data["Title"] = ctx.Tr("sign_in")
71 75
 
@@ -93,21 +97,22 @@ func SignIn(ctx *context.Context) {
93 97
 		return
94 98
 	}
95 99
 
96
-	ctx.HTML(200, SIGNIN)
100
+	ctx.HTML(200, tplSignIn)
97 101
 }
98 102
 
103
+// SignInPost response for sign in request
99 104
 func SignInPost(ctx *context.Context, form auth.SignInForm) {
100 105
 	ctx.Data["Title"] = ctx.Tr("sign_in")
101 106
 
102 107
 	if ctx.HasError() {
103
-		ctx.HTML(200, SIGNIN)
108
+		ctx.HTML(200, tplSignIn)
104 109
 		return
105 110
 	}
106 111
 
107 112
 	u, err := models.UserSignIn(form.UserName, form.Password)
108 113
 	if err != nil {
109 114
 		if models.IsErrUserNotExist(err) {
110
-			ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), SIGNIN, &form)
115
+			ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
111 116
 		} else {
112 117
 			ctx.Handle(500, "UserSignIn", err)
113 118
 		}
@@ -143,6 +148,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
143 148
 	ctx.Redirect(setting.AppSubUrl + "/")
144 149
 }
145 150
 
151
+// SignOut sign out from login status
146 152
 func SignOut(ctx *context.Context) {
147 153
 	ctx.Session.Delete("uid")
148 154
 	ctx.Session.Delete("uname")
@@ -155,6 +161,7 @@ func SignOut(ctx *context.Context) {
155 161
 	ctx.Redirect(setting.AppSubUrl + "/")
156 162
 }
157 163
 
164
+// SignUp render the register page
158 165
 func SignUp(ctx *context.Context) {
159 166
 	ctx.Data["Title"] = ctx.Tr("sign_up")
160 167
 
@@ -162,13 +169,14 @@ func SignUp(ctx *context.Context) {
162 169
 
163 170
 	if setting.Service.DisableRegistration {
164 171
 		ctx.Data["DisableRegistration"] = true
165
-		ctx.HTML(200, SIGNUP)
172
+		ctx.HTML(200, tplSignUp)
166 173
 		return
167 174
 	}
168 175
 
169
-	ctx.HTML(200, SIGNUP)
176
+	ctx.HTML(200, tplSignUp)
170 177
 }
171 178
 
179
+// SignUpPost response for sign up information submission
172 180
 func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
173 181
 	ctx.Data["Title"] = ctx.Tr("sign_up")
174 182
 
@@ -180,19 +188,19 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
180 188
 	}
181 189
 
182 190
 	if ctx.HasError() {
183
-		ctx.HTML(200, SIGNUP)
191
+		ctx.HTML(200, tplSignUp)
184 192
 		return
185 193
 	}
186 194
 
187 195
 	if setting.Service.EnableCaptcha && !cpt.VerifyReq(ctx.Req) {
188 196
 		ctx.Data["Err_Captcha"] = true
189
-		ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), SIGNUP, &form)
197
+		ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUp, &form)
190 198
 		return
191 199
 	}
192 200
 
193 201
 	if form.Password != form.Retype {
194 202
 		ctx.Data["Err_Password"] = true
195
-		ctx.RenderWithErr(ctx.Tr("form.password_not_match"), SIGNUP, &form)
203
+		ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplSignUp, &form)
196 204
 		return
197 205
 	}
198 206
 
@@ -206,16 +214,16 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
206 214
 		switch {
207 215
 		case models.IsErrUserAlreadyExist(err):
208 216
 			ctx.Data["Err_UserName"] = true
209
-			ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), SIGNUP, &form)
217
+			ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplSignUp, &form)
210 218
 		case models.IsErrEmailAlreadyUsed(err):
211 219
 			ctx.Data["Err_Email"] = true
212
-			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SIGNUP, &form)
220
+			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignUp, &form)
213 221
 		case models.IsErrNameReserved(err):
214 222
 			ctx.Data["Err_UserName"] = true
215
-			ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), SIGNUP, &form)
223
+			ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplSignUp, &form)
216 224
 		case models.IsErrNamePatternNotAllowed(err):
217 225
 			ctx.Data["Err_UserName"] = true
218
-			ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), SIGNUP, &form)
226
+			ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplSignUp, &form)
219 227
 		default:
220 228
 			ctx.Handle(500, "CreateUser", err)
221 229
 		}
@@ -239,7 +247,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
239 247
 		ctx.Data["IsSendRegisterMail"] = true
240 248
 		ctx.Data["Email"] = u.Email
241 249
 		ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
242
-		ctx.HTML(200, ACTIVATE)
250
+		ctx.HTML(200, TplActivate)
243 251
 
244 252
 		if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil {
245 253
 			log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
@@ -250,6 +258,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
250 258
 	ctx.Redirect(setting.AppSubUrl + "/user/login")
251 259
 }
252 260
 
261
+// Activate render activate user page
253 262
 func Activate(ctx *context.Context) {
254 263
 	code := ctx.Query("code")
255 264
 	if len(code) == 0 {
@@ -273,7 +282,7 @@ func Activate(ctx *context.Context) {
273 282
 		} else {
274 283
 			ctx.Data["ServiceNotEnabled"] = true
275 284
 		}
276
-		ctx.HTML(200, ACTIVATE)
285
+		ctx.HTML(200, TplActivate)
277 286
 		return
278 287
 	}
279 288
 
@@ -299,15 +308,16 @@ func Activate(ctx *context.Context) {
299 308
 	}
300 309
 
301 310
 	ctx.Data["IsActivateFailed"] = true
302
-	ctx.HTML(200, ACTIVATE)
311
+	ctx.HTML(200, TplActivate)
303 312
 }
304 313
 
314
+// ActivateEmail render the activate email page
305 315
 func ActivateEmail(ctx *context.Context) {
306 316
 	code := ctx.Query("code")
307
-	email_string := ctx.Query("email")
317
+	emailStr := ctx.Query("email")
308 318
 
309 319
 	// Verify code.
310
-	if email := models.VerifyActiveEmailCode(code, email_string); email != nil {
320
+	if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
311 321
 		if err := email.Activate(); err != nil {
312 322
 			ctx.Handle(500, "ActivateEmail", err)
313 323
 		}
@@ -320,19 +330,21 @@ func ActivateEmail(ctx *context.Context) {
320 330
 	return
321 331
 }
322 332
 
333
+// ForgotPasswd render the forget pasword page
323 334
 func ForgotPasswd(ctx *context.Context) {
324 335
 	ctx.Data["Title"] = ctx.Tr("auth.forgot_password")
325 336
 
326 337
 	if setting.MailService == nil {
327 338
 		ctx.Data["IsResetDisable"] = true
328
-		ctx.HTML(200, FORGOT_PASSWORD)
339
+		ctx.HTML(200, tplForgotPassword)
329 340
 		return
330 341
 	}
331 342
 
332 343
 	ctx.Data["IsResetRequest"] = true
333
-	ctx.HTML(200, FORGOT_PASSWORD)
344
+	ctx.HTML(200, tplForgotPassword)
334 345
 }
335 346
 
347
+// ForgotPasswdPost response for forget password request
336 348
 func ForgotPasswdPost(ctx *context.Context) {
337 349
 	ctx.Data["Title"] = ctx.Tr("auth.forgot_password")
338 350
 
@@ -350,23 +362,23 @@ func ForgotPasswdPost(ctx *context.Context) {
350 362
 		if models.IsErrUserNotExist(err) {
351 363
 			ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
352 364
 			ctx.Data["IsResetSent"] = true
353
-			ctx.HTML(200, FORGOT_PASSWORD)
365
+			ctx.HTML(200, tplForgotPassword)
354 366
 			return
355
-		} else {
356
-			ctx.Handle(500, "user.ResetPasswd(check existence)", err)
357 367
 		}
368
+
369
+		ctx.Handle(500, "user.ResetPasswd(check existence)", err)
358 370
 		return
359 371
 	}
360 372
 
361 373
 	if !u.IsLocal() {
362 374
 		ctx.Data["Err_Email"] = true
363
-		ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), FORGOT_PASSWORD, nil)
375
+		ctx.RenderWithErr(ctx.Tr("auth.non_local_account"), tplForgotPassword, nil)
364 376
 		return
365 377
 	}
366 378
 
367 379
 	if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) {
368 380
 		ctx.Data["ResendLimited"] = true
369
-		ctx.HTML(200, FORGOT_PASSWORD)
381
+		ctx.HTML(200, tplForgotPassword)
370 382
 		return
371 383
 	}
372 384
 
@@ -377,9 +389,10 @@ func ForgotPasswdPost(ctx *context.Context) {
377 389
 
378 390
 	ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
379 391
 	ctx.Data["IsResetSent"] = true
380
-	ctx.HTML(200, FORGOT_PASSWORD)
392
+	ctx.HTML(200, tplForgotPassword)
381 393
 }
382 394
 
395
+// ResetPasswd render the reset password page
383 396
 func ResetPasswd(ctx *context.Context) {
384 397
 	ctx.Data["Title"] = ctx.Tr("auth.reset_password")
385 398
 
@@ -390,9 +403,10 @@ func ResetPasswd(ctx *context.Context) {
390 403
 	}
391 404
 	ctx.Data["Code"] = code
392 405
 	ctx.Data["IsResetForm"] = true
393
-	ctx.HTML(200, RESET_PASSWORD)
406
+	ctx.HTML(200, tplResetPassword)
394 407
 }
395 408
 
409
+// ResetPasswdPost response fro reset password request
396 410
 func ResetPasswdPost(ctx *context.Context) {
397 411
 	ctx.Data["Title"] = ctx.Tr("auth.reset_password")
398 412
 
@@ -409,7 +423,7 @@ func ResetPasswdPost(ctx *context.Context) {
409 423
 		if len(passwd) < 6 {
410 424
 			ctx.Data["IsResetForm"] = true
411 425
 			ctx.Data["Err_Password"] = true
412
-			ctx.RenderWithErr(ctx.Tr("auth.password_too_short"), RESET_PASSWORD, nil)
426
+			ctx.RenderWithErr(ctx.Tr("auth.password_too_short"), tplResetPassword, nil)
413 427
 			return
414 428
 		}
415 429
 
@@ -428,5 +442,5 @@ func ResetPasswdPost(ctx *context.Context) {
428 442
 	}
429 443
 
430 444
 	ctx.Data["IsResetFailed"] = true
431
-	ctx.HTML(200, RESET_PASSWORD)
445
+	ctx.HTML(200, tplResetPassword)
432 446
 }

+ 11 - 7
routers/user/home.go

@@ -18,10 +18,10 @@ import (
18 18
 )
19 19
 
20 20
 const (
21
-	DASHBOARD base.TplName = "user/dashboard/dashboard"
22
-	ISSUES    base.TplName = "user/dashboard/issues"
23
-	PROFILE   base.TplName = "user/profile"
24
-	ORG_HOME  base.TplName = "org/home"
21
+	tplDashborad base.TplName = "user/dashboard/dashboard"
22
+	tplIssues    base.TplName = "user/dashboard/issues"
23
+	tplProfile   base.TplName = "user/profile"
24
+	tplOrgHome   base.TplName = "org/home"
25 25
 )
26 26
 
27 27
 // getDashboardContextUser finds out dashboard is viewing as which context user.
@@ -86,6 +86,7 @@ func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID, offset in
86 86
 	ctx.Data["Feeds"] = feeds
87 87
 }
88 88
 
89
+// Dashboard render the dashborad page
89 90
 func Dashboard(ctx *context.Context) {
90 91
 	ctxUser := getDashboardContextUser(ctx)
91 92
 	if ctx.Written() {
@@ -150,9 +151,10 @@ func Dashboard(ctx *context.Context) {
150 151
 	if ctx.Written() {
151 152
 		return
152 153
 	}
153
-	ctx.HTML(200, DASHBOARD)
154
+	ctx.HTML(200, tplDashborad)
154 155
 }
155 156
 
157
+// Issues render the user issues page
156 158
 func Issues(ctx *context.Context) {
157 159
 	isPullList := ctx.Params(":type") == "pulls"
158 160
 	if isPullList {
@@ -308,9 +310,10 @@ func Issues(ctx *context.Context) {
308 310
 		ctx.Data["State"] = "open"
309 311
 	}
310 312
 
311
-	ctx.HTML(200, ISSUES)
313
+	ctx.HTML(200, tplIssues)
312 314
 }
313 315
 
316
+// ShowSSHKeys ouput all the ssh keys of user by uid
314 317
 func ShowSSHKeys(ctx *context.Context, uid int64) {
315 318
 	keys, err := models.ListPublicKeys(uid)
316 319
 	if err != nil {
@@ -373,9 +376,10 @@ func showOrgProfile(ctx *context.Context) {
373 376
 
374 377
 	ctx.Data["Teams"] = org.Teams
375 378
 
376
-	ctx.HTML(200, ORG_HOME)
379
+	ctx.HTML(200, tplOrgHome)
377 380
 }
378 381
 
382
+// Email2User show user page via email
379 383
 func Email2User(ctx *context.Context) {
380 384
 	u, err := models.GetUserByEmail(ctx.Query("email"))
381 385
 	if err != nil {

+ 11 - 5
routers/user/profile.go

@@ -19,10 +19,11 @@ import (
19 19
 )
20 20
 
21 21
 const (
22
-	FOLLOWERS base.TplName = "user/meta/followers"
23
-	STARS     base.TplName = "user/meta/stars"
22
+	tplFollowers base.TplName = "user/meta/followers"
23
+	tplStars     base.TplName = "user/meta/stars"
24 24
 )
25 25
 
26
+// GetUserByName get user by name
26 27
 func GetUserByName(ctx *context.Context, name string) *models.User {
27 28
 	user, err := models.GetUserByName(name)
28 29
 	if err != nil {
@@ -41,6 +42,7 @@ func GetUserByParams(ctx *context.Context) *models.User {
41 42
 	return GetUserByName(ctx, ctx.Params(":username"))
42 43
 }
43 44
 
45
+// Profile render user's profile page
44 46
 func Profile(ctx *context.Context) {
45 47
 	uname := ctx.Params(":username")
46 48
 	// Special handle for FireFox requests favicon.ico.
@@ -107,9 +109,10 @@ func Profile(ctx *context.Context) {
107 109
 		ctx.Data["Page"] = paginater.New(ctxUser.NumRepos, setting.UI.User.RepoPagingNum, page, 5)
108 110
 	}
109 111
 
110
-	ctx.HTML(200, PROFILE)
112
+	ctx.HTML(200, tplProfile)
111 113
 }
112 114
 
115
+// Followers render user's followers page
113 116
 func Followers(ctx *context.Context) {
114 117
 	u := GetUserByParams(ctx)
115 118
 	if ctx.Written() {
@@ -119,9 +122,10 @@ func Followers(ctx *context.Context) {
119 122
 	ctx.Data["CardsTitle"] = ctx.Tr("user.followers")
120 123
 	ctx.Data["PageIsFollowers"] = true
121 124
 	ctx.Data["Owner"] = u
122
-	repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, FOLLOWERS)
125
+	repo.RenderUserCards(ctx, u.NumFollowers, u.GetFollowers, tplFollowers)
123 126
 }
124 127
 
128
+// Following render user's followering page
125 129
 func Following(ctx *context.Context) {
126 130
 	u := GetUserByParams(ctx)
127 131
 	if ctx.Written() {
@@ -131,13 +135,15 @@ func Following(ctx *context.Context) {
131 135
 	ctx.Data["CardsTitle"] = ctx.Tr("user.following")
132 136
 	ctx.Data["PageIsFollowing"] = true
133 137
 	ctx.Data["Owner"] = u
134
-	repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, FOLLOWERS)
138
+	repo.RenderUserCards(ctx, u.NumFollowing, u.GetFollowing, tplFollowers)
135 139
 }
136 140
 
141
+// Stars show repositories user starred
137 142
 func Stars(ctx *context.Context) {
138 143
 
139 144
 }
140 145
 
146
+// Action response for follow/unfollow user request
141 147
 func Action(ctx *context.Context) {
142 148
 	u := GetUserByParams(ctx)
143 149
 	if ctx.Written() {

+ 44 - 26
routers/user/setting.go

@@ -21,22 +21,23 @@ import (
21 21
 )
22 22
 
23 23
 const (
24
-	SETTINGS_PROFILE      base.TplName = "user/settings/profile"
25
-	SETTINGS_AVATAR       base.TplName = "user/settings/avatar"
26
-	SETTINGS_PASSWORD     base.TplName = "user/settings/password"
27
-	SETTINGS_EMAILS       base.TplName = "user/settings/email"
28
-	SETTINGS_SSH_KEYS     base.TplName = "user/settings/sshkeys"
29
-	SETTINGS_SOCIAL       base.TplName = "user/settings/social"
30
-	SETTINGS_APPLICATIONS base.TplName = "user/settings/applications"
31
-	SETTINGS_DELETE       base.TplName = "user/settings/delete"
32
-	NOTIFICATION          base.TplName = "user/notification"
33
-	SECURITY              base.TplName = "user/security"
24
+	tplSettingsProfile      base.TplName = "user/settings/profile"
25
+	tplSettingsAvatar       base.TplName = "user/settings/avatar"
26
+	tplSettingsPassword     base.TplName = "user/settings/password"
27
+	tplSettingsEmails       base.TplName = "user/settings/email"
28
+	tplSettingsSSHKeys      base.TplName = "user/settings/sshkeys"
29
+	tplSettingsSocial       base.TplName = "user/settings/social"
30
+	tplSettingsApplications base.TplName = "user/settings/applications"
31
+	tplSettingsDelete       base.TplName = "user/settings/delete"
32
+	tplNotification         base.TplName = "user/notification"
33
+	tplSecurity             base.TplName = "user/security"
34 34
 )
35 35
 
36
+// Settings render user's profile page
36 37
 func Settings(ctx *context.Context) {
37 38
 	ctx.Data["Title"] = ctx.Tr("settings")
38 39
 	ctx.Data["PageIsSettingsProfile"] = true
39
-	ctx.HTML(200, SETTINGS_PROFILE)
40
+	ctx.HTML(200, tplSettingsProfile)
40 41
 }
41 42
 
42 43
 func handleUsernameChange(ctx *context.Context, newName string) {
@@ -74,12 +75,13 @@ func handleUsernameChange(ctx *context.Context, newName string) {
74 75
 	ctx.User.LowerName = strings.ToLower(newName)
75 76
 }
76 77
 
78
+// SettingsPost response for change user's profile
77 79
 func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) {
78 80
 	ctx.Data["Title"] = ctx.Tr("settings")
79 81
 	ctx.Data["PageIsSettingsProfile"] = true
80 82
 
81 83
 	if ctx.HasError() {
82
-		ctx.HTML(200, SETTINGS_PROFILE)
84
+		ctx.HTML(200, tplSettingsProfile)
83 85
 		return
84 86
 	}
85 87
 
@@ -102,6 +104,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) {
102 104
 	ctx.Redirect(setting.AppSubUrl + "/user/settings")
103 105
 }
104 106
 
107
+// UpdateAvatarSetting update user's avatar
105 108
 // FIXME: limit size.
106 109
 func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *models.User) error {
107 110
 	ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
@@ -144,12 +147,14 @@ func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *mo
144 147
 	return nil
145 148
 }
146 149
 
150
+// SettingsAvatar render user avatar page
147 151
 func SettingsAvatar(ctx *context.Context) {
148 152
 	ctx.Data["Title"] = ctx.Tr("settings")
149 153
 	ctx.Data["PageIsSettingsAvatar"] = true
150
-	ctx.HTML(200, SETTINGS_AVATAR)
154
+	ctx.HTML(200, tplSettingsAvatar)
151 155
 }
152 156
 
157
+// SettingsAvatarPost response for change user's avatar request
153 158
 func SettingsAvatarPost(ctx *context.Context, form auth.AvatarForm) {
154 159
 	if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil {
155 160
 		ctx.Flash.Error(err.Error())
@@ -160,6 +165,7 @@ func SettingsAvatarPost(ctx *context.Context, form auth.AvatarForm) {
160 165
 	ctx.Redirect(setting.AppSubUrl + "/user/settings/avatar")
161 166
 }
162 167
 
168
+// SettingsDeleteAvatar render delete avatar page
163 169
 func SettingsDeleteAvatar(ctx *context.Context) {
164 170
 	if err := ctx.User.DeleteAvatar(); err != nil {
165 171
 		ctx.Flash.Error(err.Error())
@@ -168,18 +174,20 @@ func SettingsDeleteAvatar(ctx *context.Context) {
168 174
 	ctx.Redirect(setting.AppSubUrl + "/user/settings/avatar")
169 175
 }
170 176
 
177
+// SettingsPassword render change user's password page
171 178
 func SettingsPassword(ctx *context.Context) {
172 179
 	ctx.Data["Title"] = ctx.Tr("settings")
173 180
 	ctx.Data["PageIsSettingsPassword"] = true
174
-	ctx.HTML(200, SETTINGS_PASSWORD)
181
+	ctx.HTML(200, tplSettingsPassword)
175 182
 }
176 183
 
184
+// SettingsPasswordPost response for change user's password
177 185
 func SettingsPasswordPost(ctx *context.Context, form auth.ChangePasswordForm) {
178 186
 	ctx.Data["Title"] = ctx.Tr("settings")
179 187
 	ctx.Data["PageIsSettingsPassword"] = true
180 188
 
181 189
 	if ctx.HasError() {
182
-		ctx.HTML(200, SETTINGS_PASSWORD)
190
+		ctx.HTML(200, tplSettingsPassword)
183 191
 		return
184 192
 	}
185 193
 
@@ -202,6 +210,7 @@ func SettingsPasswordPost(ctx *context.Context, form auth.ChangePasswordForm) {
202 210
 	ctx.Redirect(setting.AppSubUrl + "/user/settings/password")
203 211
 }
204 212
 
213
+// SettingsEmails render user's emails page
205 214
 func SettingsEmails(ctx *context.Context) {
206 215
 	ctx.Data["Title"] = ctx.Tr("settings")
207 216
 	ctx.Data["PageIsSettingsEmails"] = true
@@ -213,9 +222,10 @@ func SettingsEmails(ctx *context.Context) {
213 222
 	}
214 223
 	ctx.Data["Emails"] = emails
215 224
 
216
-	ctx.HTML(200, SETTINGS_EMAILS)
225
+	ctx.HTML(200, tplSettingsEmails)
217 226
 }
218 227
 
228
+// SettingsEmailPost response for change user's email
219 229
 func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
220 230
 	ctx.Data["Title"] = ctx.Tr("settings")
221 231
 	ctx.Data["PageIsSettingsEmails"] = true
@@ -241,7 +251,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
241 251
 	ctx.Data["Emails"] = emails
242 252
 
243 253
 	if ctx.HasError() {
244
-		ctx.HTML(200, SETTINGS_EMAILS)
254
+		ctx.HTML(200, tplSettingsEmails)
245 255
 		return
246 256
 	}
247 257
 
@@ -252,7 +262,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
252 262
 	}
253 263
 	if err := models.AddEmailAddress(email); err != nil {
254 264
 		if models.IsErrEmailAlreadyUsed(err) {
255
-			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form)
265
+			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSettingsEmails, &form)
256 266
 			return
257 267
 		}
258 268
 		ctx.Handle(500, "AddEmailAddress", err)
@@ -275,6 +285,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {
275 285
 	ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
276 286
 }
277 287
 
288
+// DeleteEmail reponse for delete user's email
278 289
 func DeleteEmail(ctx *context.Context) {
279 290
 	if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
280 291
 		ctx.Handle(500, "DeleteEmail", err)
@@ -288,6 +299,7 @@ func DeleteEmail(ctx *context.Context) {
288 299
 	})
289 300
 }
290 301
 
302
+// SettingsSSHKeys render user's SSH public keys page
291 303
 func SettingsSSHKeys(ctx *context.Context) {
292 304
 	ctx.Data["Title"] = ctx.Tr("settings")
293 305
 	ctx.Data["PageIsSettingsSSHKeys"] = true
@@ -299,9 +311,10 @@ func SettingsSSHKeys(ctx *context.Context) {
299 311
 	}
300 312
 	ctx.Data["Keys"] = keys
301 313
 
302
-	ctx.HTML(200, SETTINGS_SSH_KEYS)
314
+	ctx.HTML(200, tplSettingsSSHKeys)
303 315
 }
304 316
 
317
+// SettingsSSHKeysPost response for change user's SSH keys
305 318
 func SettingsSSHKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
306 319
 	ctx.Data["Title"] = ctx.Tr("settings")
307 320
 	ctx.Data["PageIsSettingsSSHKeys"] = true
@@ -314,7 +327,7 @@ func SettingsSSHKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
314 327
 	ctx.Data["Keys"] = keys
315 328
 
316 329
 	if ctx.HasError() {
317
-		ctx.HTML(200, SETTINGS_SSH_KEYS)
330
+		ctx.HTML(200, tplSettingsSSHKeys)
318 331
 		return
319 332
 	}
320 333
 
@@ -334,10 +347,10 @@ func SettingsSSHKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
334 347
 		switch {
335 348
 		case models.IsErrKeyAlreadyExist(err):
336 349
 			ctx.Data["Err_Content"] = true
337
-			ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), SETTINGS_SSH_KEYS, &form)
350
+			ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), tplSettingsSSHKeys, &form)
338 351
 		case models.IsErrKeyNameAlreadyUsed(err):
339 352
 			ctx.Data["Err_Title"] = true
340
-			ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), SETTINGS_SSH_KEYS, &form)
353
+			ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsSSHKeys, &form)
341 354
 		default:
342 355
 			ctx.Handle(500, "AddPublicKey", err)
343 356
 		}
@@ -348,6 +361,7 @@ func SettingsSSHKeysPost(ctx *context.Context, form auth.AddSSHKeyForm) {
348 361
 	ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh")
349 362
 }
350 363
 
364
+// DeleteSSHKey response for delete user's SSH key
351 365
 func DeleteSSHKey(ctx *context.Context) {
352 366
 	if err := models.DeletePublicKey(ctx.User, ctx.QueryInt64("id")); err != nil {
353 367
 		ctx.Flash.Error("DeletePublicKey: " + err.Error())
@@ -360,6 +374,7 @@ func DeleteSSHKey(ctx *context.Context) {
360 374
 	})
361 375
 }
362 376
 
377
+// SettingsApplications render user's access tokens page
363 378
 func SettingsApplications(ctx *context.Context) {
364 379
 	ctx.Data["Title"] = ctx.Tr("settings")
365 380
 	ctx.Data["PageIsSettingsApplications"] = true
@@ -371,9 +386,10 @@ func SettingsApplications(ctx *context.Context) {
371 386
 	}
372 387
 	ctx.Data["Tokens"] = tokens
373 388
 
374
-	ctx.HTML(200, SETTINGS_APPLICATIONS)
389
+	ctx.HTML(200, tplSettingsApplications)
375 390
 }
376 391
 
392
+// SettingsApplicationsPost response for add user's access token
377 393
 func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) {
378 394
 	ctx.Data["Title"] = ctx.Tr("settings")
379 395
 	ctx.Data["PageIsSettingsApplications"] = true
@@ -385,7 +401,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm
385 401
 			return
386 402
 		}
387 403
 		ctx.Data["Tokens"] = tokens
388
-		ctx.HTML(200, SETTINGS_APPLICATIONS)
404
+		ctx.HTML(200, tplSettingsApplications)
389 405
 		return
390 406
 	}
391 407
 
@@ -404,6 +420,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm
404 420
 	ctx.Redirect(setting.AppSubUrl + "/user/settings/applications")
405 421
 }
406 422
 
423
+// SettingsDeleteApplication response for delete user access token
407 424
 func SettingsDeleteApplication(ctx *context.Context) {
408 425
 	if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id")); err != nil {
409 426
 		ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
@@ -416,6 +433,7 @@ func SettingsDeleteApplication(ctx *context.Context) {
416 433
 	})
417 434
 }
418 435
 
436
+// SettingsDelete render user suicide page and response for delete user himself
419 437
 func SettingsDelete(ctx *context.Context) {
420 438
 	ctx.Data["Title"] = ctx.Tr("settings")
421 439
 	ctx.Data["PageIsSettingsDelete"] = true
@@ -423,7 +441,7 @@ func SettingsDelete(ctx *context.Context) {
423 441
 	if ctx.Req.Method == "POST" {
424 442
 		if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
425 443
 			if models.IsErrUserNotExist(err) {
426
-				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
444
+				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsDelete, nil)
427 445
 			} else {
428 446
 				ctx.Handle(500, "UserSignIn", err)
429 447
 			}
@@ -448,5 +466,5 @@ func SettingsDelete(ctx *context.Context) {
448 466
 		return
449 467
 	}
450 468
 
451
-	ctx.HTML(200, SETTINGS_DELETE)
469
+	ctx.HTML(200, tplSettingsDelete)
452 470
 }