041
This commit is contained in:
parent
76e3ee93ea
commit
019d527a67
7 changed files with 124 additions and 62 deletions
|
@ -16,7 +16,6 @@ proc htmxLogin*(ctx: Context) =
|
|||
val: Validity
|
||||
validity = initTable[string, Validity]()
|
||||
|
||||
ctx &= initCookie("user2", "$(%* temp[1])")
|
||||
if em.len==0 or ps.len==0:
|
||||
for a, b in form:
|
||||
if form[a] == "":
|
||||
|
|
|
@ -3,8 +3,8 @@ import
|
|||
nimja/parser,
|
||||
json,
|
||||
../db/users,
|
||||
../model/model,
|
||||
../lib/mics
|
||||
../model/[model, rand],
|
||||
../lib/[mics, htmx]
|
||||
|
||||
proc signup*(ctx: Context): string=
|
||||
if ctx.httpMethod == HttpGet:
|
||||
|
@ -14,18 +14,34 @@ proc signup*(ctx: Context): string=
|
|||
compileTemplateFile(".." / "view" / "signup.nimja", baseDir = getScriptDir())
|
||||
elif ctx.httpMethod == HttpPost:
|
||||
var
|
||||
firstName = ctx.urlForm["fn"]
|
||||
lastName = ctx.urlForm["ln"]
|
||||
email = ctx.urlForm["em"]
|
||||
phone = ctx.urlForm["ph"]
|
||||
password = ctx.urlForm["pw"]
|
||||
form = ctx.urlForm
|
||||
firstName = form["fn"]
|
||||
lastName = form["ln"]
|
||||
email = form["em"]
|
||||
phone = form["ph"]
|
||||
password = form["pw"]
|
||||
|
||||
conn = newTurso()
|
||||
|
||||
val: Validity
|
||||
validity = initTable[string, Validity]()
|
||||
|
||||
echo firstName, lastName, email, password
|
||||
|
||||
if firstName.len == 0 or lastName.len == 0 or email.len == 0 or phone.len == 0 or password.len == 0:
|
||||
ctx.send(parseJson("""{"ok": false, "failure": "Missing parameters"}"""))
|
||||
# ctx.send(parseJson("""{"ok": false, "failure": "Missing parameters"}"""))
|
||||
for a, b in form:
|
||||
if form[a] == "":
|
||||
val.name = ""
|
||||
val.message = "Field is Required"
|
||||
val.mark = "is-invalid"
|
||||
validity[a] = val
|
||||
else:
|
||||
val.name = b
|
||||
val.message = ""
|
||||
val.mark = ""
|
||||
validity[a] = val
|
||||
ctx.send htmxSignup(validity, "")
|
||||
else:
|
||||
var user = User(
|
||||
firstName: firstName,
|
||||
|
|
|
@ -6,24 +6,27 @@ import
|
|||
../model/model
|
||||
|
||||
proc setupUsers*(conn: Turso) =
|
||||
conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS Users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
firstName VARCHAR(255) NOT NULL,
|
||||
lastName VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
phone VARCHAR(255) NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
createdAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updatedAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
accessLevel INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
## setupUsers creates the Users table if it does not exist
|
||||
conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS Users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
firstName VARCHAR(255) NOT NULL,
|
||||
lastName VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
phone VARCHAR(255) NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
createdAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updatedAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
accessLevel INTEGER NOT NULL
|
||||
)
|
||||
""")
|
||||
|
||||
proc createPost*(conn: Turso, user: User)=
|
||||
## createPost inserts a new user into the Users table
|
||||
conn.execute(fmt"""INSERT INTO users (firstName, lastName, email, phone, password, accessLevel) VALUES ("{user.firstName}", "{user.lastName}", "{user.email}", "{user.phone}", "{user.password}", {user.accessLevel});""")
|
||||
|
||||
proc getUser*(conn: Turso, email: string, password: string): (bool, User)=
|
||||
## getUser retrieves a user from the Users table
|
||||
echo "h1"
|
||||
var
|
||||
data = conn.getData(fmt"""SELECT * FROM users WHERE email = "{email}" and password = "{password}";""")
|
||||
|
|
|
@ -101,6 +101,7 @@ load()
|
|||
user = getUserFromCookie(user1)
|
||||
compileTemplateFile("view" / "404.nimja", baseDir = getScriptDir())
|
||||
|
||||
# Experimental
|
||||
"/hi" -> get:
|
||||
var
|
||||
user1 = ctx.cookies.getOrDefault("user1", "")
|
||||
|
|
|
@ -14,14 +14,14 @@ proc htmxLogin*(val: Table[string, Validity], message: string): string =
|
|||
<label class="text-danger">{message}</label>
|
||||
<div class="form-group mt-5">
|
||||
<label for="email">Email:</label>
|
||||
<label class="text-danger">{val["email"].message}</label>
|
||||
<input type="email" name="email" id="email" class="form-control {val["email"].mark}" required autocomplete="off" value="{val["email"].name}">
|
||||
<label class="text-danger">{val["em"].message}</label>
|
||||
<input type="email" name="em" id="email" class="form-control {val["em"].mark}" required autocomplete="off" value="{val["em"].name}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password:</label>
|
||||
<label class="text-danger">{val["password"].message}</label>
|
||||
<input type="password" name="password" id="password" class="form-control {val["password"].mark}" required autocomplete="off" value="{val["password"].name}">
|
||||
<label class="text-danger">{val["pw"].message}</label>
|
||||
<input type="password" name="pw" id="password" class="form-control {val["pw"].mark}" required autocomplete="off" value="{val["pw"].name}">
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -41,7 +41,7 @@ proc htmxEmail*(email: string, input: Validity): string =
|
|||
>
|
||||
<label for="email">Email:</label>
|
||||
<label class="text-danger">{input.message}</label>
|
||||
<input type="email" name="email" id="email" class="form-control {input.mark}" required autocomplete="off"
|
||||
<input type="email" name="em" id="email" class="form-control {input.mark}" required autocomplete="off"
|
||||
hx-post="/htmx/email"
|
||||
value="{email}"
|
||||
>
|
||||
|
@ -55,8 +55,69 @@ proc htmxPassword*(password: string, input: Validity): string =
|
|||
>
|
||||
<label for="password">Password:</label>
|
||||
<label class="text-danger">{input.message}</label>
|
||||
<input type="password" name="password" id="password" class="form-control {input.mark}" required autocomplete="off"
|
||||
<input type="password" name="pw" id="password" class="form-control {input.mark}" required autocomplete="off"
|
||||
hx-post="/htmx/password"
|
||||
value="{password}"
|
||||
>
|
||||
</div>"""
|
||||
</div>"""
|
||||
|
||||
proc htmxSignup*(val: Table[string, Validity], message: string): string =
|
||||
result = fmt"""
|
||||
<form id="input_form" class="" novalidate
|
||||
hx-trigger="submit"
|
||||
hx-post="/signup"
|
||||
hx-target="#input_form"
|
||||
>
|
||||
|
||||
<label class="text-danger">{message}</label>
|
||||
<div class="form-group mt-5">
|
||||
<label for="email">First Name:</label>
|
||||
<label class="text-danger"></label>
|
||||
|
||||
<input type="text" name="fn" class="form-control" required autocomplete="off">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Last Name:</label>
|
||||
<label class="text-danger"></label>
|
||||
|
||||
<input type="text" name="ln" class="form-control" required autocomplete="off">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<label class="text-danger">{val["em"].message}</label>
|
||||
|
||||
<input type="email" name="em" class="form-control {val["em"].mark}" required autocomplete="off" value="{val["em"].name}">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Phone:</label>
|
||||
<label class="text-danger"></label>
|
||||
|
||||
<input type="email" name="ph" class="form-control" required autocomplete="off">
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<label for="password">Password:</label>
|
||||
<label class="text-danger"></label>
|
||||
<input type="password" name="password" id="password" class="form-control" required autocomplete="off"
|
||||
value=""
|
||||
hx-post="/htmx/password"
|
||||
>
|
||||
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<button id="b4" type="submit" class="btn btn-primary">Submit</button>
|
||||
<a id="b4" href="/login" class="btn btn-outline-primary">Login</a>
|
||||
<hr>
|
||||
</form>"""
|
|
@ -21,7 +21,7 @@
|
|||
>
|
||||
<label for="email">Email:</label>
|
||||
<label class="text-danger"></label>
|
||||
<input type="email" name="email" id="email" class="form-control" required autocomplete="off"
|
||||
<input type="email" name="em" id="email" class="form-control" required autocomplete="off"
|
||||
value=""
|
||||
hx-post="/htmx/email"
|
||||
>
|
||||
|
@ -33,7 +33,7 @@
|
|||
>
|
||||
<label for="password">Password:</label>
|
||||
<label class="text-danger"></label>
|
||||
<input type="password" name="password" id="password" class="form-control" required autocomplete="off"
|
||||
<input type="password" name="pw" id="password" class="form-control" required autocomplete="off"
|
||||
value=""
|
||||
hx-post="/htmx/password"
|
||||
>
|
||||
|
|
|
@ -10,73 +10,55 @@
|
|||
<div class="col">
|
||||
<h1 class="mt-5">Sign Up</h1>
|
||||
|
||||
<form id="input_form" method="post" class="" novalidate>
|
||||
<form id="input_form" class="" novalidate
|
||||
hx-trigger="submit"
|
||||
hx-post="/signup"
|
||||
hx-target="#input_form"
|
||||
>
|
||||
|
||||
{# <!-- <label class="text-danger">{{loginError}}</label> --> #}
|
||||
<label class="text-danger"></label>
|
||||
<div class="form-group mt-5">
|
||||
<label for="email">First Name:</label>
|
||||
{# <!-- <label class="text-danger">{{emailError}}</label> --> #}
|
||||
<label class="text-danger"></label>
|
||||
|
||||
{# <!-- {% if emailError != "" %}
|
||||
<input type="email" name="email" id="email" class="form-control is-invalid" required autocomplete="off">
|
||||
{% else %} --> #}
|
||||
<input type="text" name="fn" class="form-control" required autocomplete="off">
|
||||
{# <!-- {% endif %} --> #}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Last Name:</label>
|
||||
{# <!-- <label class="text-danger">{{emailError}}</label> --> #}
|
||||
<label class="text-danger"></label>
|
||||
|
||||
{# <!-- {% if emailError != "" %}
|
||||
<input type="email" name="email" id="email" class="form-control is-invalid" required autocomplete="off">
|
||||
{% else %} --> #}
|
||||
<input type="text" name="ln" class="form-control" required autocomplete="off">
|
||||
{# <!-- {% endif %} --> #}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
{# <!-- <label class="text-danger">{{emailError}}</label> --> #}
|
||||
<label class="text-danger"></label>
|
||||
|
||||
{# <!-- {% if emailError != "" %}
|
||||
<input type="email" name="email" id="email" class="form-control is-invalid" required autocomplete="off">
|
||||
{% else %} --> #}
|
||||
<input type="email" name="em" class="form-control" required autocomplete="off">
|
||||
{# <!-- {% endif %} --> #}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Phone:</label>
|
||||
{# <!-- <label class="text-danger">{{emailError}}</label> --> #}
|
||||
<label class="text-danger"></label>
|
||||
|
||||
{# <!-- {% if emailError != "" %}
|
||||
<input type="email" name="email" id="email" class="form-control is-invalid" required autocomplete="off">
|
||||
{% else %} --> #}
|
||||
<input type="email" name="ph" class="form-control" required autocomplete="off">
|
||||
{# <!-- {% endif %} --> #}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="form-group"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<label for="password">Password:</label>
|
||||
{# <!-- <label class="text-danger">{{passwordError}}</label> --> #}
|
||||
<label class="text-danger"></label>
|
||||
|
||||
{# <!-- {% if passwordError != "" %}
|
||||
<input type="password" name="password" id="password" class="form-control is-invalid" required autocomplete="off">
|
||||
{% else %} --> #}
|
||||
<input type="password" name="pw" id="password" class="form-control" required autocomplete="off">
|
||||
{# <!-- {% endif %} --> #}
|
||||
|
||||
<input type="password" name="pw" id="password" class="form-control" required autocomplete="off"
|
||||
value=""
|
||||
hx-post="/htmx/password"
|
||||
>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue