Skip to content

Commit c169865

Browse files
authored
fix login (#274)
1 parent 165ec28 commit c169865

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/gitly.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const namechange_period = time.hour * 24
2323
@[heap]
2424
pub struct App {
2525
veb.StaticHandler
26+
veb.Middleware[Context]
2627
started_at i64
2728
pub mut:
2829
db sqlite.DB
@@ -131,6 +132,7 @@ pub fn (mut app App) init_server() {
131132
}
132133

133134
pub fn (mut app App) before_request(mut ctx Context) {
135+
url := ctx.req.url
134136
ctx.logged_in = app.is_logged_in(mut ctx)
135137

136138
app.load_settings()
@@ -141,6 +143,7 @@ pub fn (mut app App) before_request(mut ctx Context) {
141143
User{}
142144
}
143145
}
146+
dump(url)
144147
}
145148

146149
@['/']

src/main.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fn main() {
1212
return
1313
}
1414
mut app := new_app()!
15+
16+
app.use(handler: app.before_request)
1517
// vweb.run_at(new_app()!, http_port)
1618

1719
veb.run_at[App, Context](mut app, port: http_port, family: .ip, timeout_in_seconds: 2) or {

src/user_routes.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result {
1212
ctx.set_cookie(name: 'csrf', value: csrf)
1313

1414
if app.is_logged_in(mut ctx) {
15-
return ctx.not_found()
15+
return ctx.redirect("/" + ctx.user.username)
1616
}
1717

1818
return $veb.html()

0 commit comments

Comments
 (0)