This commit is contained in:
Aritra Banik 2024-03-11 01:59:38 +05:30
parent da5e05fb44
commit 380414c20f
2 changed files with 66 additions and 21 deletions

View File

@ -78,27 +78,8 @@ import
compileTemplateFile(getScriptDir() / "a3a" / "login.nimja")
"/logout" -> get:
ctx &= initCookie("email", "")
ctx &= initCookie("password", "")
ctx.redirect("/login")
"/signup" -> get:
var
firstNameError = ""
lastNameError = ""
emailError = ""
passwordError = ""
user: User
user.firstName = ""
user.lastName = ""
user.email = ""
user.password = ""
compileTemplateFile(getScriptDir() / "a3a" / "signup.nimja")
"/logout" -> get: ctx.logout()
"/signup" -> get: ctx.getSignup()
"/signup" -> post:
var
form = ctx.urlForm

View File

@ -18,3 +18,67 @@ proc getLogin*(ctx: Context): string=
password = ""
compileTemplateFile(getScriptDir() / "a3a" / "login.nimja")
proc postLogin*(ctx: Context)=
var
email = ctx.urlForm["email"]
password = ctx.urlForm["password"]
db = newDatabase()
user = db.userAvailability(email, password)
loginError = ""
emailError = ""
passwordError = ""
qParams = ctx.queryParams
productName = qParams.getOrDefault("prod", "")
quantity = parseInt(qParams.getOrDefault("quantity", "0"))
if user == true:
ctx &= initCookie("email", email)
ctx &= initCookie("password", password)
if quantity != 0:
ctx.redirect("/cart/checkout?prod=" & productName & "&quantity=" & $quantity)
else:
ctx.redirect("/")
else:
if email == "":
emailError = "Email is Required"
if password == "":
passwordError = "Password is Required"
if user == false:
loginError = "Invalid Login or Password"
# compileTemplateFile(getScriptDir() / "a3a" / "login.nimja")
proc logout*(ctx: Context)=
ctx &= initCookie("email", "")
ctx &= initCookie("password", "")
ctx.redirect("/login")
proc getSignup*(ctx: Context): string=
var
firstNameError = ""
lastNameError = ""
emailError = ""
passwordError = ""
user: User
user.firstName = ""
user.lastName = ""
user.email = ""
user.password = ""
compileTemplateFile(getScriptDir() / "a3a" / "signup.nimja")