local hash = require('./piazza-util').hash local user = {} user.setdb = function(db) user.db = db end user.new = function(t) local u = {} u.type = 'user' u.username = t.username u.password_hash = hash(t.password) u.salutation = t.salutation or 'mr' u.firstname = t.firstname or '' u.lastname = t.lastname or '' u.position = t.position or '' u.store = t.store or '' u.address = t.address or '' u.practice_type = t.practice_type or '' u.phone_office = t.phone_office or '' u.phone_cell = t.phone_cell or '' u.email = t.email or '' u.tier = t.tier or 'silver' u.is_admin = t.is_admin or false user.db:insertrecord(u) return u end user.isgold = function(user_record) return user_record.tier == 'gold' end return user