webmcp

view demo-app/model/session.lua @ 4:5e32ef998acf

Version 1.0.4

ui.link{...} with POST target can now be parameterized with BOTH content and text to allow HTML content for JavaScript browsers and a text-only version for accessiblity

Changes related to database selectors:
- Support for row-based locking
- New method :count(), caching and returning the number of rows, which WOULD have been returned by :exec()
- Bugfix: WHERE and HAVING expressions are now enclosed in parenthesis to avoid problems with operator precedence

ui.script{...} now supports external .js files

Changes in langtool.lua to cope with escaped new-line chars (\n)
author jbe/bsw
date Fri Dec 25 12:00:00 2009 +0100 (2009-12-25)
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