fix user exists query
This commit is contained in:
parent
4bf9cdfc8e
commit
23bf81188a
1 changed files with 15 additions and 10 deletions
25
src/user.ml
25
src/user.ml
|
|
@ -16,10 +16,10 @@ module Q = struct
|
||||||
Caqti_request.find_opt Caqti_type.string Caqti_type.string
|
Caqti_request.find_opt Caqti_type.string Caqti_type.string
|
||||||
"SELECT password FROM user WHERE nick=?;"
|
"SELECT password FROM user WHERE nick=?;"
|
||||||
|
|
||||||
let find_user =
|
let is_already_user =
|
||||||
Caqti_request.find_opt
|
Caqti_request.find_opt
|
||||||
Caqti_type.(tup2 string string)
|
Caqti_type.(tup2 string string)
|
||||||
Caqti_type.unit
|
Caqti_type.int
|
||||||
"SELECT EXISTS(SELECT 1 FROM user WHERE nick=? OR email=?);"
|
"SELECT EXISTS(SELECT 1 FROM user WHERE nick=? OR email=?);"
|
||||||
|
|
||||||
let inser_new_user =
|
let inser_new_user =
|
||||||
|
|
@ -110,17 +110,22 @@ let register ~email ~nick ~password =
|
||||||
if not valid then
|
if not valid then
|
||||||
Error "Something is wrong"
|
Error "Something is wrong"
|
||||||
else
|
else
|
||||||
let unique = Db.find_opt Q.find_user (nick, email) in
|
let unique = Db.find_opt Q.is_already_user (nick, email) in
|
||||||
match unique with
|
match unique with
|
||||||
| Ok unique -> (
|
| Ok unique -> (
|
||||||
match unique with
|
match unique with
|
||||||
| Some _ -> Error "nick or email already exists"
|
| Some nb -> (
|
||||||
| None -> (
|
match nb with
|
||||||
let res = Db.exec Q.inser_new_user (nick, password, email, ("", "")) in
|
| 0 -> (
|
||||||
match res with
|
let res =
|
||||||
| Ok res -> Ok res
|
Db.exec Q.inser_new_user (nick, password, email, ("", ""))
|
||||||
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
in
|
||||||
) )
|
match res with
|
||||||
|
| Ok res -> Ok res
|
||||||
|
| Error e ->
|
||||||
|
Error (Format.sprintf "db error: %s" (Caqti_error.show e)) )
|
||||||
|
| _ -> Error "nick or email already exists" )
|
||||||
|
| None -> Error "db error" )
|
||||||
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
||||||
|
|
||||||
let list () =
|
let list () =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue