liquid_feedback_frontend

view app/main/index/_action/login.lua @ 990:77873f08d94f

Completed support for check delegations, removed debug code
author bsw
date Sat Apr 20 19:26:58 2013 +0200 (2013-04-20)
parents 81bde33c2256
children 701a5cf6b067
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 }
52 end
54 if member then
55 member.last_login = "now"
57 local delegations = Delegation:delegations_to_check_for_member_id(member.id)
59 if config.check_delegations_interval_hard
60 and member.needs_delegation_check_hard
61 and #delegations > 0 then
63 app.session.needs_delegation_check = true
65 else
67 if #delegations == 0 then
68 member.last_delegation_check = "now"
69 end
71 member.last_activity = "now"
72 member.active = true
74 end
76 if member.lang == nil then
77 member.lang = app.session.lang
78 else
79 app.session.lang = member.lang
80 end
82 if member.password_hash_needs_update then
83 member:set_password(password)
84 end
86 member:save()
87 app.session.member = member
88 app.session:save()
89 trace.debug('User authenticated')
90 if config.etherpad then
91 do_etherpad_auth(member)
92 end
93 else
94 slot.select("error", function()
95 ui.tag{ content = _'Invalid login name or password!' }
96 end)
97 trace.debug('User NOT authenticated')
98 return false
99 end

Impressum / About Us