liquid_feedback_frontend

view app/main/index/_action/login.lua @ 988:81bde33c2256

Added support for regular delegation check, fixed css for pagination
author bsw
date Sat Apr 20 18:40:34 2013 +0200 (2013-04-20)
parents e3887fea39fa
children 77873f08d94f
line source
1 local login = param.get("login")
2 local password = param.get("password")
4 local member = Member:by_login_and_password(login, password)
6 function do_etherpad_auth(member)
7 local result = net.curl(
8 config.etherpad.api_base
9 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
10 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
11 )
13 if not result then
14 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
15 return false
16 end
18 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
20 if not etherpad_author_id then
21 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
22 return false
23 end
25 local time_in_24h = os.time() + 24 * 60 * 60
27 local result = net.curl(
28 config.etherpad.api_base
29 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
30 .. "&groupID=" .. config.etherpad.group_id
31 .. "&authorID=" .. etherpad_author_id
32 .. "&validUntil=" .. time_in_24h
33 )
35 if not result then
36 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
37 return false
38 end
40 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
42 if not etherpad_sesion_id then
43 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
44 return false
45 end
47 request.set_cookie{
48 path = config.etherpad.cookie_path,
49 name = "sessionID",
50 value = etherpad_sesion_id
51 }
53 end
56 if member then
57 member.last_login = "now"
58 if config.check_delegations_interval_hard and member.needs_delegation_check_hard then
59 app.session.needs_delegation_check = true
60 else
61 member.last_activity = "now"
62 member.active = true
63 end
64 if member.lang == nil then
65 member.lang = app.session.lang
66 else
67 app.session.lang = member.lang
68 end
70 if member.password_hash_needs_update then
71 member:set_password(password)
72 end
74 member:save()
75 app.session.member = member
76 app.session:save()
77 trace.debug('User authenticated')
78 if config.etherpad then
79 do_etherpad_auth(member)
80 end
81 else
82 slot.select("error", function()
83 ui.tag{ content = _'Invalid login name or password!' }
84 end)
85 trace.debug('User NOT authenticated')
86 return false
87 end

Impressum / About Us