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.
#
import cairo, os, strutils
import cairo, os, strutils, jester
proc getCaptchaFilename*(i: int): string {.inline.} =
result = "public/captchas/capture_" & $i & ".png"
proc getCaptchaUrl*(i: int): string =
result = "/captchas/capture_" & $i & ".png"
proc getCaptchaUrl*(req: var TRequest, i: int): string =
result = req.makeUri("/captchas/capture_" & $i & ".png", absolute = false)
proc createCaptcha*(file, text: string) =
var surface = imageSurfaceCreate(FORMAT_ARGB32, 10*text.len, 10)

View file

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

View file

@ -13,7 +13,6 @@ import
const
unselectedThread = -1
transientThread = 0
websiteLoc = ""
type
TCrud = enum crCreate, crRead, crUpdate, crDelete
@ -185,7 +184,7 @@ proc antibot(c: var TForumData): string =
answer).int mod 10_000
let CaptchaFile = getCaptchaFilename(CaptchaId)
createCaptcha(CaptchaFile, $a & "+" & $b)
result = """<img src="$1" />""" % getCaptchaUrl(captchaId)
result = """<img src="$1" />""" % c.req.getCaptchaUrl(captchaId)
const
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 =
result = ""
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)))
if c.loggedIn:
let hasReplyBtn = c.req.pathInfo != "/donewthread" and c.req.pathInfo != "/doreply"
@ -575,6 +575,6 @@ when isMainModule:
if paramCount() > 0:
if paramStr(1) == "scgi":
http = false
run(websiteLoc, port = TPort(9000), http = http)
run("", port = TPort(9000), http = http)
db.close()

View file

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