forked from vlang/gitly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.v
91 lines (79 loc) · 1.87 KB
/
admin.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module main
import vweb
pub fn (mut app App) admin() vweb.Result {
if !app.is_admin() {
return app.r_home()
}
return $vweb.html()
}
['/admin/settings']
pub fn (mut app App) admin_settings() vweb.Result {
if !app.is_admin() {
return app.r_home()
}
return $vweb.html()
}
[post]
['/admin/settings']
pub fn (mut app App) update_admin_settings() vweb.Result {
if !app.is_admin() {
return app.r_home()
}
oauth_client_id := app.form['oauth_client_id']
oauth_client_secret := app.form['oauth_client_secret']
only_gh_login := 'only_gh_login' in app.form
repo_storage_path := app.form['repo_storage_path']
if oauth_client_id != '' {
app.settings.oauth_client_id = oauth_client_id
}
if oauth_client_secret != '' {
app.settings.oauth_client_secret = oauth_client_secret
}
app.settings.only_gh_login = only_gh_login
app.settings.repo_storage_path = repo_storage_path
app.update_settings()
return app.redirect('/admin')
}
['/admin/userlist']
pub fn (mut app App) admin_userlist() vweb.Result {
if !app.is_admin() {
return app.r_home()
}
// TODO add pagination
userlist := app.find_registered_user()
return $vweb.html()
}
[post]
['/admin/edituser/:user']
pub fn (mut app App) admin_edituser(user string) vweb.Result {
if !app.is_admin() {
return app.r_home()
}
clear_session := 'stop-session' in app.form
is_blocked := 'is-blocked' in app.form
is_admin := 'is-admin' in app.form
if is_admin {
app.user_set_admin(user.int())
} else {
app.user_unset_admin(user.int())
}
if is_blocked {
app.block_user(user.int())
} else {
app.unblock_user(user.int())
}
if clear_session {
app.clear_sessions(user.int())
}
return app.redirect('/admin')
}
['/admin/statics']
pub fn (mut app App) admin_statics() vweb.Result {
if !app.is_admin() {
return app.r_home()
}
return $vweb.html()
}
fn (mut app App) is_admin() bool {
return app.logged_in && app.user.is_admin
}