30
This commit is contained in:
39
src/services.v
Normal file
39
src/services.v
Normal file
@@ -0,0 +1,39 @@
|
||||
module main
|
||||
|
||||
import databases
|
||||
|
||||
fn (mut app App) service_add_user(username string, email string, password string) ! {
|
||||
mut db := databases.create_db_connection()!
|
||||
|
||||
defer {
|
||||
db.close() or { panic(err) }
|
||||
}
|
||||
|
||||
print(1)
|
||||
|
||||
|
||||
results := sql db {
|
||||
select from Auth where username == username && email == email
|
||||
}!
|
||||
|
||||
if results.len > 0 {
|
||||
return error('User already exists')
|
||||
}
|
||||
|
||||
auth_model := Auth{
|
||||
username: username,
|
||||
email: email,
|
||||
password: password,
|
||||
access_level: 1,
|
||||
}
|
||||
|
||||
mut insert_error := ''
|
||||
|
||||
sql db {
|
||||
insert auth_model into Auth
|
||||
} or { insert_error = err.msg() }
|
||||
|
||||
if insert_error != '' {
|
||||
return error(insert_error)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user