44
This commit is contained in:
@@ -20,6 +20,28 @@ pub fn (mut app App) post_signup(username string, email string, password string)
|
||||
return app.json(noti)
|
||||
}
|
||||
|
||||
@['/controller/signup']
|
||||
pub fn (mut app App) controller_signup() vweb.Result{
|
||||
username := app.query["username"]
|
||||
print(username)
|
||||
email := app.query["email"]
|
||||
password := app.query["password"]
|
||||
app.service_add_user(username, email, password) or {
|
||||
mut noti := Noti{
|
||||
status: "failure",
|
||||
message: err.str()
|
||||
}
|
||||
return app.json(noti)
|
||||
}
|
||||
|
||||
noti := Noti{
|
||||
status: "success",
|
||||
message: "User created successfully"
|
||||
}
|
||||
|
||||
return app.json(noti)
|
||||
}
|
||||
|
||||
@['/login'; post]
|
||||
pub fn (mut app App) post_login(username string, password string) vweb.Result{
|
||||
user := app.service_login(username, password) or {
|
||||
|
@@ -3,6 +3,10 @@ module main
|
||||
import databases
|
||||
|
||||
fn (mut app App) service_add_user(username string, email string, password string) ! {
|
||||
if username == '' || email == '' || password == '' {
|
||||
return error('Invalid input')
|
||||
}
|
||||
|
||||
mut db := databases.create_db_connection()!
|
||||
|
||||
defer {
|
||||
|
Reference in New Issue
Block a user