class HUserManager
Public Class Methods
new(databaseManager = nil)
click to toggle source
# File lib/husermanager/husermanager.rb, line 6 def initialize(databaseManager = nil) @databaseManager = (databaseManager == nil) ? hpgsql() : databaseManager end
test1()
click to toggle source
# File lib/husermanager/husermanager.rb, line 107 def self.test1() userProfile = {:name => "Herbert", :familienname => "Bonaffini", :adresse => "Wien", :arbeit => "Developer"} p hpgsql().insertValues(userProfile) p hpgsql().updateValues(userProfile) HUserManager.instance().addProfileIfNotExist(1, "familienname", "Bonaffini", 1) user = {:id => 'default', :username => "herbert.bonaffini9@gmail.com", :password => "ciao", :enabled => 1, :user_type_id => 1} #p "id: #{HUserManager.instance().newUser(user)}" p "autenticate: #{HUserManager.instance().autenticate('herbert.bonaffini9@gmail.com', "ciao")}" p HUserManager.instance().activationUrl("herbert.bonaffini9@gmail.com") return HUserManager.instance().getUserValueByUserName('herbert.bonaffini@gmail.com', 'address') end
Public Instance Methods
activationUrl(username)
click to toggle source
# File lib/husermanager/husermanager.rb, line 99 def activationUrl(username) query = "select activation from user_table where username = '#{username}'" return @databaseManager.run(query).dataByFieldName(0, "activation") end
addProfileIfNotExist(userId, fieldName, fieldValue, ordering)
click to toggle source
# File lib/husermanager/husermanager.rb, line 48 def addProfileIfNotExist(userId, fieldName, fieldValue, ordering) query = "select id from user_profile_table where profile_key = '#{fieldName}' and id = #{userId}" resultTable = @databaseManager.run(query).resultTable self.newUserProfile(userId, fieldName, fieldValue, ordering) if(resultTable.count == 0) end
autenticate(username, password)
click to toggle source
return nil if user not found return -1 if mismatch password return id if the username and password are ok
# File lib/husermanager/husermanager.rb, line 81 def autenticate(username, password) query = "select id, password from user_table where username = '#{username}'" resultTable = @databaseManager.run(query).resultTable return nil if(resultTable.count == 0) storePassword = resultTable[0]["password"] return Password.new(storePassword).is_password?(password) ? resultTable[0]["id"] : -1 end
deleteUser(username)
click to toggle source
# File lib/husermanager/husermanager.rb, line 91 def deleteUser(username) query = "delete from user_table where username = '#{username}'" @databaseManager.run(query) end
getUserValueById(userId, fieldName)
click to toggle source
# File lib/husermanager/husermanager.rb, line 25 def getUserValueById(userId, fieldName) return nil if(fieldName == "") fieldName = self.sanitize(fieldName) query = "select profile_value from user_profile_table where profile_key = '#{fieldName}' and user_id = '#{userId}'"; return @databaseManager.run(query).dataByFieldName(0, "profile_value") end
getUserValueByUserName(userName, fieldName)
click to toggle source
# File lib/husermanager/husermanager.rb, line 36 def getUserValueByUserName(userName, fieldName) return nil if(userName == "" || fieldName == "") fieldName = self.sanitize(fieldName) userId = userNameToUserId(userName) return (userId == nil) ? nil : getUserValueById(userId, fieldName) end
newUser(user)
click to toggle source
# File lib/husermanager/husermanager.rb, line 68 def newUser(user) user[:password] = Password.create(HIO.unQuote(user[:password])) user[:activation] = Digest::SHA1.hexdigest([Time.now, rand].join) userQuery = "insert into user_table #{@databaseManager.insertValues(user)} returning id" return @databaseManager.run(userQuery).dataByFieldName(0, "id") end
newUserProfile(userId, profileKey, profileValue, ordering)
click to toggle source
# File lib/husermanager/husermanager.rb, line 56 def newUserProfile(userId, profileKey, profileValue, ordering) userProfile = Hash.new() userProfile["user_id"] = userId userProfile["profile_key"] = profileKey userProfile["profile_value"] = profileValue userProfile["ordering"] = ordering userProfileQuery = "insert into user_profile_table #{@databaseManager.insertValues(userProfile)}" @databaseManager.run(userProfileQuery) end
sanitize(str)
click to toggle source
# File lib/husermanager/husermanager.rb, line 12 def sanitize(str) return str.gsub("'", "\'") end
userNameToUserId(userName)
click to toggle source
# File lib/husermanager/husermanager.rb, line 18 def userNameToUserId(userName) query = "select id from user_table where username = '#{userName}'" return @databaseManager.run(query).dataByFieldName(0, "id") end