Skip to content

Commit 950aa01

Browse files
committed
feat: rrdoc
1 parent 12de58f commit 950aa01

9 files changed

Lines changed: 47 additions & 2 deletions

File tree

COUNT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.6-alpha,104
1+
v0.1.6-alpha,142

docs/registration.org

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* user registration
2+
3+
** terms of service and other similar stuff
4+
5+
you must put them under the directory ~_rrdoc~ under your specified static assets directory for them to be available under the ~/rrdoc/{p}~ route; e.g. if your static assets directory is ~/opt/aegis/static~, then ~/rrdoc/toc.md~ would choose render the file ~/opt/aegis/static/_rrodc/toc.md~. (it's named "rrdoc" (reading-required documents) because these are not necessarily legal documents and can be very informal, e.g. code of conducts.)
6+

pkg/aegis/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ type AegisConfig struct {
6464
EmailConfirmationRequired bool `json:"emailConfirmationRequired"`
6565
// when set to true, all registration must be screened by the webmaster.
6666
ManualApproval bool `json:"requireManualApproval"`
67+
// documents that users would have to read and agree to before
68+
// registering a new account, e.g. terms of service. if "path"
69+
// starts with "http://" or "https://", the path would be rendered
70+
// as a link. if it's not, it would be considered as na relpath to
71+
// `$staticAssetDirectory/rrdoc`, e.g. "Terms Of Service":
72+
// "tos.md" links the file "$static/rrdoc/tos.md" to the title
73+
// "Terms Of Service".
74+
ReadingRequiredDocument []struct{Title string;Path string} `json:"readingRequiredDocument"`
6775

6876
// git-related config.
6977
// NOTE(2025.12.30): we'll gradually move certain config options into here.
@@ -342,6 +350,13 @@ func (cfg *AegisConfig) Unlock() {
342350
cfg.lock.Unlock()
343351
}
344352

353+
func (cfg *AegisConfig) GetRRDocTitle(p string) string {
354+
for _, v := range cfg.ReadingRequiredDocument {
355+
if v.Path == p { return v.Title }
356+
}
357+
return ""
358+
}
359+
345360
const (
346361
OP_MODE_PLAIN = "plain"
347362
OP_MODE_SIMPLE = "simple"

routes/controller/admin/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package admin
33
import (
44
"github.com/bctnry/aegis/routes"
55
"github.com/bctnry/aegis/routes/controller/admin/edit_user"
6+
"github.com/bctnry/aegis/routes/controller/admin/rrdoc"
67
)
78

89
func BindAllAdminControllers(context *routes.RouterContext) {
@@ -14,6 +15,7 @@ func BindAllAdminControllers(context *routes.RouterContext) {
1415
bindAdminReceiptSystemSettingController(context)
1516
bindAdminUserListController(context)
1617
edit_user.BindAdminEditUserController(context)
18+
rrdoc.BindAdminRRDocController(context)
1719
bindAdminNewUserController(context)
1820
bindAdminNamespaceListController(context)
1921
bindAdminEditNamespaceController(context)

routes/controller/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func InitializeRoute(context *routes.RouterContext) {
2323
bindShutdownNoticeController(context)
2424
bindMaintenanceNoticeController(context)
2525
bindPrivateNoticeController(context)
26+
bindRRDocController(context)
2627

2728
if context.Config.UseNamespace {
2829
bindNamespaceController(context)

routes/controller/register.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ func bindRegisterController(ctx *RouterContext) {
7676
}))
7777
return
7878
}
79+
if rc.Config.ReadingRequiredDocument != nil {
80+
for i := range rc.Config.ReadingRequiredDocument {
81+
if len(strings.TrimSpace(r.Form.Get(fmt.Sprintf("req-%d", i)))) <= 0 {
82+
rc.ReportRedirect("/reg", 5, "Field Required", "You must consent to all the required documents.", w, r)
83+
return
84+
}
85+
}
86+
}
87+
7988
password := r.Form.Get("password")
8089
passwordHash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
8190
if err != nil {

templates/_footer.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{{define "_footer"}}
33
<div class="footer-message">
4-
Powered by <a href="https://github.com/AegisCodeForge/aegis">Aegis</a>, version v0.1.6-alpha (v0.1.6-alpha.build_104)
4+
Powered by <a href="https://github.com/AegisCodeForge/aegis">Aegis</a>, version v0.1.6-alpha (v0.1.6-alpha.build_142)
55
</div>
66
{{end}}

templates/admin/_admin-sidebar.template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<a class="admin-sidebar-item" href="/admin/rs-setting">Receipt system config</a>
88
<a class="admin-sidebar-item" href="/admin/mailer-setting">Mailer config</a>
99
<a class="admin-sidebar-item" href="/admin/site-lockdown">Site lockdown</a>
10+
<a class="admin-sidebar-item" href="/admin/rrdoc">Legal documents config</a>
1011

1112
<hr />
1213
<a class="admin-sidebar-item" href="/admin/user-list">Users</a>

templates/registration.template.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ <h1 class="header-name">Registration</h1>
4444
<td><textarea id="ta-reason" name="ta-reason"></textarea></td>
4545
</tr>
4646
{{end}}
47+
{{if .Config.ReadingRequiredDocument}}
48+
{{range $k, $v := .Config.ReadingRequiredDocument}}
49+
<tr class="field">
50+
<td></td>
51+
<td>
52+
<input style="display: inline" class="field-chkbox" type="checkbox" name="req-{{$k}}" id="chk-req-{{$k}}" />
53+
<label for="chk-req-{{$k}}">I have read the content of <a target="_blank" href="{{getRRDocHref $v.Path}}">{{$v.Title}}</a> and consent to its terms</label>
54+
</td>
55+
</tr>
56+
{{end}}
57+
{{end}}
4758
<tr class="field">
4859
<td></td>
4960
<td><input class="form-submit" type="submit" value="Register" /></td>

0 commit comments

Comments
 (0)