webmcp

view demo-app/model/session.lua @ 2:72860d232f32

Version 1.0.2

Fixed bug with explicit garbage collection (requests > 256kB caused an error)

Views prefixed with an underscore can't be called externally

ui.paginate now displays the last page, if the selected page number is too high.
author jbe/bsw
date Thu Dec 10 12:00:00 2009 +0100 (2009-12-10)
parents 9fdfb27f8e67
children
line source
1 Session = mondelefant.new_class()
2 Session.table = 'session'
3 Session.primary_key = { "ident" }
5 Session:add_reference{
6 mode = 'm1', -- many (m) sessions refer to one (1) user
7 to = "User", -- name of referenced model (quoting avoids auto-loading here)
8 this_key = 'user_id', -- own key in session table
9 that_key = 'id', -- other key in user table
10 ref = 'user', -- name of reference
11 back_ref = nil, -- not used for m1 relation!
12 default_order = nil -- not used for m1 relation!
13 }
15 local function random_string()
16 return multirand.string(
17 32,
18 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
19 )
20 end
22 function Session:new()
23 local session = self.prototype.new(self) -- super call
24 session.ident = random_string()
25 session.csrf_secret = random_string()
26 session:save()
27 return session
28 end
30 function Session:by_ident(ident)
31 local selector = self:new_selector()
32 selector:add_where{ 'ident = ?', ident }
33 selector:optional_object_mode()
34 return selector:exec()
35 end

Impressum / About Us