-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_section_page.nim
85 lines (59 loc) · 2.06 KB
/
edit_section_page.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import prologue
import site_comps
import strutils
import mynimlib/icecream
import karax / [karaxdsl, vdom]
################
## Components ##
################
####################
## Route Handlers ##
####################
proc isNumber(x: string): bool =
try:
discard parseInt(x)
result = true
except ValueError:
result = false
proc isHexStr(s: string): bool =
if len(s) < 3 or s[0..1] != "0x":
return false
let validHexChars = "0123456789abcdefABCDEF"
for c in s[2..^1]:
if not( c in validHexChars):
return false
return true
proc all_params(chapter_num, section_num, wallet_addr: string): tuple [are_valid: bool, err:string] =
if not isNumber(chapter_num) or not isNumber(section_num):
ic "Not a number"
return(false, "Invalid Chapter or Section Number")
let chapter_num_int = chapter_num.parseInt
let section_num_int = section_num.parseInt
if not chapter_num_int > 0 or not section_num_int > 0:
ic "Not a positive number"
return (false, "Invalid Chapter or Section Number")
if not (chapter_num_int < 8) or not (section_num_int < 8):
ic " Not a valid chapter or section number"
return (false, "Invalid Chapter or Section Number")
if not isHexStr(wallet_addr):
ic "Not a valid wallet address"
return (false, "Invalid Wallet Address")
return (true, "")
proc edit_section_page*(ctx: Context) {.async.} =
let chapter_num = ctx.getPathParams("chapter_num")
let section_num = ctx.getPathParams("section_num")
let wallet_addr = ctx.getPathParams("wallet_addr")
if not all_params(chapter_num, section_num, wallet_addr).are_valid:
let err = all_params(chapter_num, section_num, wallet_addr).err
ic err
resp err
return
let body = ppostNavCol(""):
vdom.text "FAQ"
resp base(
top_nav_2() & $body
)
################
## Routes ##
################
let edit_section_route* = pattern("/edit/chapter/{chapter_num}/section/{section_num}/{wallet_addr}", edit_section_page, @[HttpGet])