| rev |
line source |
|
bsw@905
|
1 local login = param.get("login")
|
|
bsw@905
|
2 local password = param.get("password")
|
|
bsw@905
|
3
|
|
bsw@905
|
4 local member = Member:by_login_and_password(login, password)
|
|
bsw/jbe@0
|
5
|
|
bsw@286
|
6 function do_etherpad_auth(member)
|
|
bsw@286
|
7 local result = net.curl(
|
|
bsw@286
|
8 config.etherpad.api_base
|
|
bsw@286
|
9 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
|
|
bsw@286
|
10 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
|
|
bsw@286
|
11 )
|
|
bsw@286
|
12
|
|
bsw@286
|
13 if not result then
|
|
bsw@286
|
14 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
|
|
bsw@286
|
15 return false
|
|
bsw@286
|
16 end
|
|
bsw@286
|
17
|
|
bsw@286
|
18 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
|
|
bsw@286
|
19
|
|
bsw@286
|
20 if not etherpad_author_id then
|
|
bsw@286
|
21 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
|
|
bsw@286
|
22 return false
|
|
bsw@286
|
23 end
|
|
bsw@286
|
24
|
|
bsw@286
|
25 local time_in_24h = os.time() + 24 * 60 * 60
|
|
bsw@286
|
26
|
|
bsw@286
|
27 local result = net.curl(
|
|
bsw@286
|
28 config.etherpad.api_base
|
|
bsw@286
|
29 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
|
|
bsw@286
|
30 .. "&groupID=" .. config.etherpad.group_id
|
|
bsw@286
|
31 .. "&authorID=" .. etherpad_author_id
|
|
bsw@286
|
32 .. "&validUntil=" .. time_in_24h
|
|
bsw@286
|
33 )
|
|
bsw@286
|
34
|
|
bsw@286
|
35 if not result then
|
|
bsw@286
|
36 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
|
|
bsw@286
|
37 return false
|
|
bsw@286
|
38 end
|
|
bsw@286
|
39
|
|
bsw@286
|
40 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
|
|
bsw@286
|
41
|
|
bsw@286
|
42 if not etherpad_sesion_id then
|
|
bsw@286
|
43 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
|
|
bsw@286
|
44 return false
|
|
bsw@286
|
45 end
|
|
bsw@286
|
46
|
|
bsw@286
|
47 request.set_cookie{
|
|
bsw@286
|
48 path = config.etherpad.cookie_path,
|
|
bsw@286
|
49 name = "sessionID",
|
|
bsw@286
|
50 value = etherpad_sesion_id
|
|
bsw@286
|
51 }
|
|
bsw@286
|
52 end
|
|
bsw@286
|
53
|
|
bsw/jbe@0
|
54 if member then
|
|
bsw@203
|
55 member.last_login = "now"
|
|
bsw@990
|
56
|
|
bsw@990
|
57 local delegations = Delegation:delegations_to_check_for_member_id(member.id)
|
|
bsw@990
|
58
|
|
bsw@990
|
59 if config.check_delegations_interval_hard
|
|
bsw@990
|
60 and member.needs_delegation_check_hard
|
|
bsw@990
|
61 and #delegations > 0 then
|
|
bsw@990
|
62
|
|
bsw@988
|
63 app.session.needs_delegation_check = true
|
|
bsw@990
|
64
|
|
bsw@988
|
65 else
|
|
bsw@990
|
66
|
|
bsw@990
|
67 if #delegations == 0 then
|
|
bsw@990
|
68 member.last_delegation_check = "now"
|
|
bsw@990
|
69 end
|
|
bsw@990
|
70
|
|
bsw@988
|
71 member.last_activity = "now"
|
|
bsw@988
|
72 member.active = true
|
|
bsw@990
|
73
|
|
bsw@988
|
74 end
|
|
bsw@990
|
75
|
|
bsw@292
|
76 if member.lang == nil then
|
|
bsw@292
|
77 member.lang = app.session.lang
|
|
bsw@292
|
78 else
|
|
bsw@292
|
79 app.session.lang = member.lang
|
|
bsw@292
|
80 end
|
|
bsw@905
|
81
|
|
bsw@905
|
82 if member.password_hash_needs_update then
|
|
bsw@905
|
83 member:set_password(password)
|
|
bsw@905
|
84 end
|
|
bsw@905
|
85
|
|
bsw@203
|
86 member:save()
|
|
bsw/jbe@0
|
87 app.session.member = member
|
|
bsw/jbe@0
|
88 app.session:save()
|
|
bsw/jbe@0
|
89 trace.debug('User authenticated')
|
|
bsw@286
|
90 if config.etherpad then
|
|
bsw@286
|
91 do_etherpad_auth(member)
|
|
bsw@286
|
92 end
|
|
bsw/jbe@0
|
93 else
|
|
bsw@3
|
94 slot.select("error", function()
|
|
bsw@756
|
95 ui.tag{ content = _'Invalid login name or password!' }
|
|
bsw/jbe@0
|
96 end)
|
|
bsw/jbe@0
|
97 trace.debug('User NOT authenticated')
|
|
bsw/jbe@0
|
98 return false
|
|
bsw/jbe@0
|
99 end
|