webmcp

view demo-app/model/user.lua @ 567:5e3ebe9fd0ce

Added tag v2.2.1 for changeset 3b71fdb3a00d
author jbe
date Wed Apr 28 13:07:52 2021 +0200 (5 months ago)
parents 9fdfb27f8e67
children
line source
1 User = mondelefant.new_class()
2 User.table = 'user'
4 User:add_reference{
5 mode = '1m', -- one (1) user can have many (m) sessions
6 to = "Session", -- referenced model (quoting avoids auto-loading here)
7 this_key = 'id', -- own key in user table
8 that_key = 'user_id', -- other key in session table
9 ref = 'sessions', -- name of reference
10 back_ref = 'user', -- each autoloaded Session automatically refers back to the User
11 default_order = '"ident"' -- order sessions by SQL expression "ident"
12 }
14 function User:by_ident_and_password(ident, password)
15 local selector = self:new_selector()
16 selector:add_where{ 'ident = ? AND password = ?', ident, password }
17 selector:optional_object_mode()
18 return selector:exec()
19 end
21 function User.object_get:name_with_login()
22 return self.name .. ' (' .. self.login .. ')'
23 end
25 function User.object:require_privilege(privilege)
26 if privilege == "admin" then
27 assert(self.admin, "Administrator privilege required")
28 elseif privilege == "write" then
29 assert(self.write_priv, "Write privilege required")
30 else
31 error("Unknown privilege passed to require_privilege method of User")
32 end
33 end

Impressum / About Us