46 lines
1.1 KiB
V
46 lines
1.1 KiB
V
module main
|
|
|
|
import veb
|
|
|
|
pub fn (app &App) signup(mut ctx Context) veb.Result {
|
|
return $veb.html()
|
|
}
|
|
|
|
pub fn (app &App) login(mut ctx Context) veb.Result {
|
|
return $veb.html()
|
|
}
|
|
|
|
pub fn (app &App) user(mut ctx Context) veb.Result {
|
|
user_id := ctx.get_cookie('token') or { '' }
|
|
token := app.auth.find_token(user_id) or { return ctx.redirect('/login') }
|
|
|
|
if token.user_id == 0 {
|
|
// Redirect to login if not logged in
|
|
return ctx.redirect('/login')
|
|
}
|
|
|
|
user := app.service_get_user(token.user_id) or { return ctx.redirect('/login') }
|
|
|
|
return $veb.html()
|
|
}
|
|
|
|
pub fn (app &App) profile(mut ctx Context) veb.Result {
|
|
user_id := ctx.get_cookie('token') or { '' }
|
|
token := app.auth.find_token(user_id) or { return ctx.redirect('/login') }
|
|
|
|
if token.user_id == 0 {
|
|
return ctx.redirect('/login')
|
|
}
|
|
|
|
user := app.service_get_user(token.user_id) or { return ctx.redirect('/login') }
|
|
bookings := app.service_get_user_bookings(token.user_id) or { []Booking{} }
|
|
|
|
mut flights := []Flight{}
|
|
for booking in bookings {
|
|
flight := app.service_get_flight(booking.flight_id) or { continue }
|
|
flights << flight
|
|
}
|
|
|
|
return $veb.html()
|
|
}
|