webmcp

view demo-app/model/session.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 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