Fixes for Urls.

This commit is contained in:
dom96 2012-05-17 01:21:59 +01:00
commit 961a3fc0e9
4 changed files with 17 additions and 17 deletions

View file

@ -6,13 +6,13 @@
# All rights reserved. # All rights reserved.
# #
import cairo, os, strutils import cairo, os, strutils, jester
proc getCaptchaFilename*(i: int): string {.inline.} = proc getCaptchaFilename*(i: int): string {.inline.} =
result = "public/captchas/capture_" & $i & ".png" result = "public/captchas/capture_" & $i & ".png"
proc getCaptchaUrl*(i: int): string = proc getCaptchaUrl*(req: var TRequest, i: int): string =
result = "/captchas/capture_" & $i & ".png" result = req.makeUri("/captchas/capture_" & $i & ".png", absolute = false)
proc createCaptcha*(file, text: string) = proc createCaptcha*(file, text: string) =
var surface = imageSurfaceCreate(FORMAT_ARGB32, 10*text.len, 10) var surface = imageSurfaceCreate(FORMAT_ARGB32, 10*text.len, 10)

View file

@ -123,7 +123,7 @@
<div id="replytop"> <div id="replytop">
<span>${topText}</span> <span>${topText}</span>
</div> </div>
<form action="/$action" method="POST"> <form action="${c.req.makeUri(action, false)}" method="POST">
${FieldValid(c, "subject", "Subject:")} ${FieldValid(c, "subject", "Subject:")}
${TextWidget(c, "subject", title, maxlength=100)} ${TextWidget(c, "subject", title, maxlength=100)}
<br /> <br />
@ -146,7 +146,7 @@
# #
#proc genFormRegister(c: var TForumData): string = #proc genFormRegister(c: var TForumData): string =
# result = "" # result = ""
<form action="/doregister" method="POST"> <form action="${c.req.makeUri("/doregister", false)}" method="POST">
<b>Register</b><br /> <b>Register</b><br />
<table border="0"> <table border="0">
<tr> <tr>
@ -173,7 +173,7 @@
#proc genFormLogin(c: var TForumData): string = #proc genFormLogin(c: var TForumData): string =
# result = "" # result = ""
# if not c.loggedIn: # if not c.loggedIn:
<form action="/dologin" method="POST"> <form action="${c.req.makeUri("/dologin", false)}" method="POST">
<table border="0"> <table border="0">
<tr><td>Username:</td><td> <tr><td>Username:</td><td>
<input type="text" name="name" maxlength="20"></td></tr> <input type="text" name="name" maxlength="20"></td></tr>
@ -202,11 +202,11 @@
# if usr.isAdmin: # if usr.isAdmin:
#if index != 0: result.add ',' #if index != 0: result.add ','
#end if #end if
<span class="user admin">${usr.nick}</span> #result.add("""<span class="user admin"> """ & usr.nick & """</span>""")
# else: # else:
#if index != 0: result.add ',' #if index != 0: result.add ','
#end if #end if
<span class="user">${usr.nick}</span> #result.add("""<span class="user"> """ & usr.nick & """</span>""")
# end if # end if
#end for #end for
</span> </span>

View file

@ -13,7 +13,6 @@ import
const const
unselectedThread = -1 unselectedThread = -1
transientThread = 0 transientThread = 0
websiteLoc = ""
type type
TCrud = enum crCreate, crRead, crUpdate, crDelete TCrud = enum crCreate, crRead, crUpdate, crDelete
@ -185,7 +184,7 @@ proc antibot(c: var TForumData): string =
answer).int mod 10_000 answer).int mod 10_000
let CaptchaFile = getCaptchaFilename(CaptchaId) let CaptchaFile = getCaptchaFilename(CaptchaId)
createCaptcha(CaptchaFile, $a & "+" & $b) createCaptcha(CaptchaFile, $a & "+" & $b)
result = """<img src="$1" />""" % getCaptchaUrl(captchaId) result = """<img src="$1" />""" % c.req.getCaptchaUrl(captchaId)
const const
SecureChars = {'A'..'Z', 'a'..'z', '0'..'9', '_', '\128'..'\255'} SecureChars = {'A'..'Z', 'a'..'z', '0'..'9', '_', '\128'..'\255'}
@ -407,7 +406,8 @@ proc login(c: var TForumData, name, pass: string): bool =
proc genActionMenu(c: var TForumData): string = proc genActionMenu(c: var TForumData): string =
result = "" result = ""
var btns: seq[TStyledButton] = @[] var btns: seq[TStyledButton] = @[]
if c.req.pathInfo != "/": # TODO: Make this detection better?
if c.req.pathInfo notin ["/", "/login", "/register", "/dologin", "/doregister"]:
btns.add(("Thread List", c.req.makeUri("/", false))) btns.add(("Thread List", c.req.makeUri("/", false)))
if c.loggedIn: if c.loggedIn:
let hasReplyBtn = c.req.pathInfo != "/donewthread" and c.req.pathInfo != "/doreply" let hasReplyBtn = c.req.pathInfo != "/donewthread" and c.req.pathInfo != "/doreply"
@ -575,6 +575,6 @@ when isMainModule:
if paramCount() > 0: if paramCount() > 0:
if paramStr(1) == "scgi": if paramStr(1) == "scgi":
http = false http = false
run(websiteLoc, port = TPort(9000), http = http) run("", port = TPort(9000), http = http)
db.close() db.close()

View file

@ -5,8 +5,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>Nimrod Forum</title> <title>Nimrod Forum</title>
<link rel="stylesheet" href="/css/normalize.css"> <link rel="stylesheet" href="${c.req.makeUri("css/normalize.css", absolute = false)}">
<link rel="stylesheet" href="/css/style.css"> <link rel="stylesheet" href="${c.req.makeUri("css/style.css", absolute = false)}">
</head> </head>
<body> <body>
<div id="wrapper"> <div id="wrapper">
@ -18,12 +18,12 @@
#let frontQuery = c.req.makeUri("/") #let frontQuery = c.req.makeUri("/")
<span><a href="${frontQuery}">Nimrod's Forum</a></span> <span><a href="${frontQuery}">Nimrod's Forum</a></span>
#if c.loggedIn: #if c.loggedIn:
<a href="${websiteLoc}logout" class="right">Logout</a> <a href="${frontQuery}logout" class="right">Logout</a>
<span id="welcome">$c.username</span> <span id="welcome">$c.username</span>
${genGravatar(c.email, 26)} ${genGravatar(c.email, 26)}
#else: #else:
<a href="${websiteLoc}register" class="right">Register</a> <a href="${frontQuery}register" class="right">Register</a>
<a href="${websiteLoc}login" class="right">Login</a> <a href="${frontQuery}login" class="right">Login</a>
#end if #end if
</div> </div>