Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/gitly.v
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const namechange_period = time.hour * 24
@[heap]
pub struct App {
veb.StaticHandler
veb.Middleware[Context]
started_at i64
pub mut:
db sqlite.DB
Expand Down Expand Up @@ -131,6 +132,7 @@ pub fn (mut app App) init_server() {
}

pub fn (mut app App) before_request(mut ctx Context) {
url := ctx.req.url
ctx.logged_in = app.is_logged_in(mut ctx)

app.load_settings()
Expand All @@ -141,6 +143,7 @@ pub fn (mut app App) before_request(mut ctx Context) {
User{}
}
}
dump(url)
}

@['/']
Expand Down
2 changes: 2 additions & 0 deletions src/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fn main() {
return
}
mut app := new_app()!

app.use(handler: app.before_request)
// vweb.run_at(new_app()!, http_port)

veb.run_at[App, Context](mut app, port: http_port, family: .ip, timeout_in_seconds: 2) or {
Expand Down
2 changes: 1 addition & 1 deletion src/user_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result {
ctx.set_cookie(name: 'csrf', value: csrf)

if app.is_logged_in(mut ctx) {
return ctx.not_found()
return ctx.redirect("/" + ctx.user.username)
}

return $veb.html()
Expand Down
Loading