a mini social media app for small communities
1module main
2
3import veb
4import entity { User }
5
6fn (mut app App) index(mut ctx Context) veb.Result {
7 ctx.title = app.config.instance.name
8 user := app.whoami(mut ctx) or { User{} }
9 recent_posts := app.get_recent_posts()
10 pinned_posts := app.get_pinned_posts()
11 motd := app.get_motd()
12 return $veb.html()
13}
14
15fn (mut app App) login(mut ctx Context) veb.Result {
16 ctx.title = 'login to ${app.config.instance.name}'
17 user := app.whoami(mut ctx) or { User{} }
18 return $veb.html()
19}
20
21fn (mut app App) register(mut ctx Context) veb.Result {
22 ctx.title = 'register for ${app.config.instance.name}'
23 user := app.whoami(mut ctx) or { User{} }
24 return $veb.html()
25}
26
27fn (mut app App) me(mut ctx Context) veb.Result {
28 user := app.whoami(mut ctx) or {
29 ctx.error('not logged in')
30 return ctx.redirect('/login')
31 }
32 ctx.title = '${app.config.instance.name} - ${user.get_name()}'
33 return ctx.redirect('/user/${user.username}')
34}
35
36fn (mut app App) admin(mut ctx Context) veb.Result {
37 ctx.title = '${app.config.instance.name} dashboard'
38 user := app.whoami(mut ctx) or { User{} }
39 return $veb.html()
40}
41
42fn (mut app App) inbox(mut ctx Context) veb.Result {
43 user := app.whoami(mut ctx) or {
44 ctx.error('not logged in')
45 return ctx.redirect('/login')
46 }
47 ctx.title = '${app.config.instance.name} inbox'
48 notifications := app.get_notifications_for(user.id)
49 return $veb.html()
50}
51
52@['/user/:username']
53fn (mut app App) user(mut ctx Context, username string) veb.Result {
54 user := app.whoami(mut ctx) or { User{} }
55 viewing := app.get_user_by_name(username) or {
56 ctx.error('user not found')
57 return ctx.redirect('/')
58 }
59 ctx.title = '${app.config.instance.name} - ${user.get_name()}'
60 return $veb.html()
61}
62
63@['/post/:post_id']
64fn (mut app App) post(mut ctx Context, post_id int) veb.Result {
65 post := app.get_post_by_id(post_id) or {
66 ctx.error('no such post')
67 return ctx.redirect('/')
68 }
69 ctx.title = '${app.config.instance.name} - ${post.title}'
70 user := app.whoami(mut ctx) or { User{} }
71 return $veb.html()
72}