079
This commit is contained in:
parent
da5e05fb44
commit
380414c20f
23
src/a3.nim
23
src/a3.nim
@ -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
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user