diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-04-01 00:02:30 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-04-01 00:02:30 -0400 |
commit | 094cbeedb81afde03d8f30f8928f98c13f1aa00a (patch) | |
tree | 31195843a8d38c172f8539df062a442b43f38cca /src/guff/models | |
parent | ec78a9b0fed0d54d6cc6695f80484e34286921ab (diff) | |
download | old-guff-094cbeedb81afde03d8f30f8928f98c13f1aa00a.tar.bz2 old-guff-094cbeedb81afde03d8f30f8928f98c13f1aa00a.zip |
add user methods
Diffstat (limited to 'src/guff/models')
-rw-r--r-- | src/guff/models/user.cr | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/guff/models/user.cr b/src/guff/models/user.cr index 4dc6d0a..1862e29 100644 --- a/src/guff/models/user.cr +++ b/src/guff/models/user.cr @@ -24,9 +24,19 @@ class Guff::UserModel < Guff::Model super(models, SQL) end - def add_user(user_name : String) + def get_users + r = [] of Hash(String, String) + + all(:get_users) do |row| + r << row + end + + r + end + + def add_user(name : String) query(:add_user, { - "user_name": user_name + "user_name": name }, nil) # return user id @@ -34,26 +44,37 @@ class Guff::UserModel < Guff::Model end def update_user( - user_id : Int32, - user_name : String? = nil, - active : Boolean? = nil, + user_id : Int32, + name : String? = nil, + active : Bool? = nil, + role : String? = nil, ) sets = [] of String args = { "user_id": user_id.to_s } - if user_name != nil - sets << "user_name = :user_name" - args["user_name"] = user_name + if name != nil + args["name"] = name.not_nil! + sets << "user_name = :name" end if active != nil + args["is_active"] = active.not_nil! ? "1" : "0" sets << "is_active = :is_active" - args["is_active"] = active ? "1" : "0" end + if role != nil + args["role_name"] = role.not_nil! + sets << " + role_id = (SELECT role_id + FROM roles + WHERE role_name = :role) + " + end + + # exec query query(:update_user, args, { - "sets": sets.join(","), - }) if sets.length > 0 + "sets": sets.join(", "), + }) if sets.size > 0 end def delete_login(user_id : Int32) |