Merge pull request 'main' (#9) from harshscool955952/8:main into harsh

Reviewed-on: #9
This commit is contained in:
cereci5049 2024-08-05 14:14:28 +02:00
commit 2702d93d53
11 changed files with 38 additions and 6 deletions

0
README.MD Normal file
View file

View file

@ -14,24 +14,27 @@ proc signup*(ctx: Context): string=
firstName = ctx.urlForm["fn"]
lastName = ctx.urlForm["ln"]
email = ctx.urlForm["em"]
phone = ctx.urlForm["ph"]
password = ctx.urlForm["pw"]
conn = newTurso()
echo firstName, lastName, email, password
if firstName.len == 0 or lastName.len == 0 or email.len == 0 or password.len == 0:
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"}"""))
else:
var user = User(
firstName: firstName,
lastName: lastName,
email: email,
phone: phone,
password: password,
accessLevel: 1
)
conn.createPost(user)
ctx &= user
ctx.redirect("/")
else:
ctx.send(parseJson("""{"ok": false, "failure": "Invalid method"}"""))

Binary file not shown.

BIN
src/db/db_up.exe Normal file

Binary file not shown.

0
src/db/products.nim Normal file
View file

View file

@ -11,7 +11,8 @@ proc setupUsers*(conn: Turso) =
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL,
phone VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created_at TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
@ -20,7 +21,7 @@ proc setupUsers*(conn: Turso) =
""")
proc createPost*(conn: Turso, user: User)=
conn.execute(fmt"""INSERT INTO users (first_name, last_name, email, password, access_level) VALUES ("{user.firstName}", "{user.lastName}", "{user.email}", "{user.password}", {user.accessLevel});""")
conn.execute(fmt"""INSERT INTO users (first_name, last_name, email, phone, password, access_level) VALUES ("{user.firstName}", "{user.lastName}", "{user.email}", "{user.phone}", "{user.password}", {user.accessLevel});""")
proc getUser*(conn: Turso, email: string, password: string): (bool, User)=
var
@ -29,8 +30,9 @@ proc getUser*(conn: Turso, email: string, password: string): (bool, User)=
firstName: data["rows"][0][1]["value"].getStr(),
lastName: data["rows"][0][2]["value"].getStr(),
email: data["rows"][0][3]["value"].getStr(),
password: data["rows"][0][4]["value"].getStr(),
accessLevel: parseInt(data["rows"][0][7]["value"].getStr())
phone: data["rows"][0][4]["value"].getStr(),
password: data["rows"][0][5]["value"].getStr(),
accessLevel: parseInt(data["rows"][0][8]["value"].getStr())
)
if user.firstName.len == 0 or user.lastName.len == 0 or user.email.len == 0 or user.password.len == 0:

BIN
src/hh1

Binary file not shown.

BIN
src/hh1.exe Normal file

Binary file not shown.

View file

@ -14,6 +14,7 @@ import
echo(fmt"[mike] before request: {ctx.httpMethod} {path2}")
"/" -> [get, post]:
let user = ctx[User]
compileTemplateFile(getScriptDir() / "view" / "index.nimja")
"/shop" -> get:
@ -40,6 +41,18 @@ import
"/login" -> get:
compileTemplateFile(getScriptDir() / "view" / "login.nimja")
"/:path" -> get:
compileTemplateFile(getScriptDir() / "view" / "404.nimja")
"/login"-> post:
var em =ctx.urlForm["email"]
var ps=ctx.urlForm["password"]
let conn=newTurso()
var temp=getUser(conn,em,ps)
if temp[0]:
ctx.redirect("/")
else:
echo "user not found"
servePublic("src/public", "/static")
run()

View file

@ -1,9 +1,10 @@
type
User* = object of RootObj
User* = ref object of RootObj
id*: int
firstName*: string
lastName*: string
email*: string
phone*: string
password*: string
createdAt*: string
updatedAt*: string

View file

@ -53,6 +53,19 @@
</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">
<label for="password">Password:</label>
{# <!-- <label class="text-danger">{{passwordError}}</label> --> #}