080
This commit is contained in:
parent
380414c20f
commit
f3d5bf14f5
86
src/a3.nim
86
src/a3.nim
@ -1,11 +1,6 @@
|
||||
import
|
||||
mike,
|
||||
segfaults,
|
||||
os,
|
||||
nimja/parser,
|
||||
strutils,
|
||||
./a3pkg/[models, mics],
|
||||
./a3c/[users],
|
||||
./[admin, cart, about, index, checkout, validation, contact, shop, signup]
|
||||
|
||||
"/" -> [get, post]: ctx.index()
|
||||
@ -35,87 +30,10 @@ import
|
||||
"/shop-single" -> get: ctx.shopSingle()
|
||||
|
||||
"/login" -> get: ctx.getLogin()
|
||||
|
||||
"/login" -> post:
|
||||
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")
|
||||
|
||||
"/login" -> post: ctx.postLogin()
|
||||
"/logout" -> get: ctx.logout()
|
||||
"/signup" -> get: ctx.getSignup()
|
||||
"/signup" -> post:
|
||||
var
|
||||
form = ctx.urlForm
|
||||
|
||||
db = newDatabase()
|
||||
user: User
|
||||
|
||||
firstNameError = ""
|
||||
lastNameError = ""
|
||||
emailError = ""
|
||||
passwordError = ""
|
||||
|
||||
user.firstName = form["firstName"]
|
||||
user.lastName = form["lastName"]
|
||||
user.email = form["email"]
|
||||
user.password = form["password"]
|
||||
|
||||
if user.firstName == "":
|
||||
firstNameError = "First Name is Required"
|
||||
|
||||
if user.lastName == "":
|
||||
lastNameError = "Last Name is Required"
|
||||
|
||||
if user.email == "":
|
||||
emailError = "Email is Required"
|
||||
|
||||
if user.password == "":
|
||||
passwordError = "Password is Required"
|
||||
|
||||
if firstNameError == "" and lastNameError == "" and emailError == "" and passwordError == "":
|
||||
user.accessLevel = 1
|
||||
|
||||
db.createPost(user)
|
||||
ctx.redirect("/login")
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "signup.nimja")
|
||||
"/signup" -> post: ctx.postSignup()
|
||||
|
||||
"/admin/dashboard" -> get:
|
||||
ctx.admin()
|
||||
|
@ -19,7 +19,7 @@ proc getLogin*(ctx: Context): string=
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "login.nimja")
|
||||
|
||||
proc postLogin*(ctx: Context)=
|
||||
proc postLogin*(ctx: Context): string=
|
||||
|
||||
var
|
||||
email = ctx.urlForm["email"]
|
||||
@ -60,7 +60,7 @@ proc postLogin*(ctx: Context)=
|
||||
if user == false:
|
||||
loginError = "Invalid Login or Password"
|
||||
|
||||
# compileTemplateFile(getScriptDir() / "a3a" / "login.nimja")
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "login.nimja")
|
||||
|
||||
proc logout*(ctx: Context)=
|
||||
ctx &= initCookie("email", "")
|
||||
@ -82,3 +82,40 @@ proc getSignup*(ctx: Context): string=
|
||||
user.password = ""
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "signup.nimja")
|
||||
|
||||
proc postSignup*(ctx: Context): string=
|
||||
var
|
||||
form = ctx.urlForm
|
||||
|
||||
db = newDatabase()
|
||||
user: User
|
||||
|
||||
firstNameError = ""
|
||||
lastNameError = ""
|
||||
emailError = ""
|
||||
passwordError = ""
|
||||
|
||||
user.firstName = form["firstName"]
|
||||
user.lastName = form["lastName"]
|
||||
user.email = form["email"]
|
||||
user.password = form["password"]
|
||||
|
||||
if user.firstName == "":
|
||||
firstNameError = "First Name is Required"
|
||||
|
||||
if user.lastName == "":
|
||||
lastNameError = "Last Name is Required"
|
||||
|
||||
if user.email == "":
|
||||
emailError = "Email is Required"
|
||||
|
||||
if user.password == "":
|
||||
passwordError = "Password is Required"
|
||||
|
||||
if firstNameError == "" and lastNameError == "" and emailError == "" and passwordError == "":
|
||||
user.accessLevel = 1
|
||||
|
||||
db.createPost(user)
|
||||
ctx.redirect("/login")
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "signup.nimja")
|
||||
|
Loading…
Reference in New Issue
Block a user