Skip to content
This repository
Browse code

Fixes for Urls.

  • Loading branch information...
commit 961a3fc0e9f367f75ae891c63db04915a92ebb87 1 parent f678c75
Dominik Picheta authored May 17, 2012
6  captchas.nim
@@ -6,13 +6,13 @@
6 6
 #    All rights reserved.
7 7
 #
8 8
 
9  
-import cairo, os, strutils
  9
+import cairo, os, strutils, jester
10 10
 
11 11
 proc getCaptchaFilename*(i: int): string {.inline.} =
12 12
   result = "public/captchas/capture_" & $i & ".png"
13 13
 
14  
-proc getCaptchaUrl*(i: int): string =
15  
-  result = "/captchas/capture_" & $i & ".png"
  14
+proc getCaptchaUrl*(req: var TRequest, i: int): string =
  15
+  result = req.makeUri("/captchas/capture_" & $i & ".png", absolute = false)
16 16
 
17 17
 proc createCaptcha*(file, text: string) =
18 18
   var surface = imageSurfaceCreate(FORMAT_ARGB32, 10*text.len, 10)
10  forms.tmpl
@@ -123,7 +123,7 @@
123 123
   <div id="replytop">
124 124
     <span>${topText}</span>
125 125
   </div>
126  
-  <form action="/$action" method="POST">
  126
+  <form action="${c.req.makeUri(action, false)}" method="POST">
127 127
     ${FieldValid(c, "subject", "Subject:")}
128 128
     ${TextWidget(c, "subject", title, maxlength=100)}
129 129
     <br />
@@ -146,7 +146,7 @@
146 146
 #
147 147
 #proc genFormRegister(c: var TForumData): string =
148 148
 #  result = ""
149  
-<form action="/doregister" method="POST">
  149
+<form action="${c.req.makeUri("/doregister", false)}" method="POST">
150 150
   <b>Register</b><br />
151 151
   <table border="0">
152 152
     <tr>
@@ -173,7 +173,7 @@
173 173
 #proc genFormLogin(c: var TForumData): string =
174 174
 #  result = ""
175 175
 #  if not c.loggedIn:
176  
-  <form action="/dologin" method="POST">
  176
+  <form action="${c.req.makeUri("/dologin", false)}" method="POST">
177 177
   <table border="0">
178 178
     <tr><td>Username:</td><td>
179 179
     <input type="text" name="name" maxlength="20"></td></tr>
@@ -202,11 +202,11 @@
202 202
       #  if usr.isAdmin:
203 203
           #if index != 0: result.add ','
204 204
           #end if
205  
-          <span class="user admin">${usr.nick}</span>
  205
+          #result.add("""<span class="user admin"> """ & usr.nick & """</span>""")
206 206
       #  else:
207 207
           #if index != 0: result.add ','
208 208
           #end if
209  
-          <span class="user">${usr.nick}</span>
  209
+          #result.add("""<span class="user"> """ & usr.nick & """</span>""")
210 210
       #  end if
211 211
       #end for
212 212
     </span>
8  forum.nim
@@ -13,7 +13,6 @@ import
13 13
 const
14 14
   unselectedThread = -1
15 15
   transientThread = 0
16  
-  websiteLoc = ""
17 16
 
18 17
 type
19 18
   TCrud = enum crCreate, crRead, crUpdate, crDelete
@@ -185,7 +184,7 @@ proc antibot(c: var TForumData): string =
185 184
     answer).int mod 10_000
186 185
   let CaptchaFile = getCaptchaFilename(CaptchaId)
187 186
   createCaptcha(CaptchaFile, $a & "+" & $b)
188  
-  result = """<img src="$1" />""" % getCaptchaUrl(captchaId)
  187
+  result = """<img src="$1" />""" % c.req.getCaptchaUrl(captchaId)
189 188
 
190 189
 const
191 190
   SecureChars = {'A'..'Z', 'a'..'z', '0'..'9', '_', '\128'..'\255'}
@@ -407,7 +406,8 @@ proc login(c: var TForumData, name, pass: string): bool =
407 406
 proc genActionMenu(c: var TForumData): string =
408 407
   result = ""
409 408
   var btns: seq[TStyledButton] = @[]
410  
-  if c.req.pathInfo != "/":
  409
+  # TODO: Make this detection better?
  410
+  if c.req.pathInfo notin ["/", "/login", "/register", "/dologin", "/doregister"]:
411 411
     btns.add(("Thread List", c.req.makeUri("/", false)))
412 412
   if c.loggedIn:
413 413
     let hasReplyBtn = c.req.pathInfo != "/donewthread" and c.req.pathInfo != "/doreply"
@@ -575,6 +575,6 @@ when isMainModule:
575 575
   if paramCount() > 0:
576 576
     if paramStr(1) == "scgi":
577 577
       http = false
578  
-  run(websiteLoc, port = TPort(9000), http = http)
  578
+  run("", port = TPort(9000), http = http)
579 579
   db.close()
580 580
 
10  main.tmpl
@@ -5,8 +5,8 @@
5 5
 <html lang="en">
6 6
 <head>
7 7
   <title>Nimrod Forum</title>
8  
-  <link rel="stylesheet" href="/css/normalize.css">
9  
-  <link rel="stylesheet" href="/css/style.css">
  8
+  <link rel="stylesheet" href="${c.req.makeUri("css/normalize.css", absolute = false)}">
  9
+  <link rel="stylesheet" href="${c.req.makeUri("css/style.css", absolute = false)}">
10 10
 </head>
11 11
 <body>
12 12
   <div id="wrapper">
@@ -18,12 +18,12 @@
18 18
       #let frontQuery = c.req.makeUri("/")
19 19
       <span><a href="${frontQuery}">Nimrod's Forum</a></span>
20 20
       #if c.loggedIn:
21  
-        <a href="${websiteLoc}logout" class="right">Logout</a>
  21
+        <a href="${frontQuery}logout" class="right">Logout</a>
22 22
         <span id="welcome">$c.username</span>
23 23
         ${genGravatar(c.email, 26)}
24 24
       #else:
25  
-        <a href="${websiteLoc}register" class="right">Register</a>
26  
-        <a href="${websiteLoc}login" class="right">Login</a>
  25
+        <a href="${frontQuery}register" class="right">Register</a>
  26
+        <a href="${frontQuery}login" class="right">Login</a>
27 27
       #end if
28 28
     </div>
29 29
       

0 notes on commit 961a3fc

Please sign in to comment.
Something went wrong with that request. Please try again.