This commit is contained in:
2024-07-04 04:27:02 +05:30
parent 0b86e17ee3
commit be276acef4
2 changed files with 26 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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 {