liquid_feedback_frontend

view env/util/login.lua @ 1800:b87997219042

Updated spanish translation
author bsw
date Thu Oct 21 15:22:29 2021 +0200 (2021-10-21)
parents 45fd259aa1ad
children
line source
1 local function do_etherpad_auth(member)
2 local result = net.curl(
3 config.etherpad.api_base
4 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
5 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
6 )
8 if not result then
9 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
10 return false
11 end
13 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
15 if not etherpad_author_id then
16 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
17 return false
18 end
20 local time_in_24h = os.time() + 24 * 60 * 60
22 local result = net.curl(
23 config.etherpad.api_base
24 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
25 .. "&groupID=" .. config.etherpad.group_id
26 .. "&authorID=" .. etherpad_author_id
27 .. "&validUntil=" .. time_in_24h
28 )
30 if not result then
31 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
32 return false
33 end
35 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
37 if not etherpad_sesion_id then
38 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
39 return false
40 end
42 request.set_cookie{
43 path = config.etherpad.cookie_path,
44 name = "sessionID",
45 value = etherpad_sesion_id
46 }
47 end
49 function util.login(member)
50 member.last_login = "now"
52 local delegations = Delegation:delegations_to_check_for_member_id(member.id)
54 if config.check_delegations_interval_hard
55 and member.needs_delegation_check_hard
56 and #delegations > 0 then
58 app.session.needs_delegation_check = true
60 else
62 if #delegations == 0 then
63 member.last_delegation_check = "now"
64 end
66 member.last_activity = "now"
67 member.active = true
69 end
71 if member.lang == nil then
72 member.lang = app.session.lang
73 else
74 app.session.lang = member.lang
75 end
77 if member.password_hash_needs_update then
78 member:set_password(password)
79 end
81 member:save()
82 app.session.member = member
83 app.session:save()
85 trace.debug('User authenticated')
86 if config.etherpad then
87 return do_etherpad_auth(member)
88 end
90 return true
92 end

Impressum / About Us