| rev |
line source |
|
bsw@905
|
1 local login = param.get("login")
|
|
bsw@905
|
2 local password = param.get("password")
|
|
bsw@905
|
3
|
|
bsw@1071
|
4 local member, err, uid = Member:by_login_and_password(login, password)
|
|
bsw@1071
|
5
|
|
bsw@1071
|
6 if err == "ldap_credentials_valid_but_no_member" then
|
|
bsw@1071
|
7 app.session.authority = "ldap"
|
|
bsw@1071
|
8 app.session.authority_data = encode.pg_hstore{
|
|
bsw@1071
|
9 login = login,
|
|
bsw@1071
|
10 uid = uid
|
|
bsw@1071
|
11 }
|
|
bsw@1071
|
12 app.session:save()
|
|
bsw@1071
|
13 request.redirect{
|
|
bsw@1071
|
14 module = "index", view = "register", params = {
|
|
bsw@1071
|
15 ldap_login = login
|
|
bsw@1071
|
16 }
|
|
bsw@1071
|
17 }
|
|
bsw@1071
|
18 return
|
|
bsw@1071
|
19 end
|
|
bsw/jbe@0
|
20
|
|
bsw@286
|
21 function do_etherpad_auth(member)
|
|
bsw@286
|
22 local result = net.curl(
|
|
bsw@286
|
23 config.etherpad.api_base
|
|
bsw@286
|
24 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
|
|
bsw@286
|
25 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
|
|
bsw@286
|
26 )
|
|
bsw@286
|
27
|
|
bsw@286
|
28 if not result then
|
|
bsw@286
|
29 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
|
|
bsw@286
|
30 return false
|
|
bsw@286
|
31 end
|
|
bsw@286
|
32
|
|
bsw@286
|
33 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
|
|
bsw@286
|
34
|
|
bsw@286
|
35 if not etherpad_author_id then
|
|
bsw@286
|
36 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
|
|
bsw@286
|
37 return false
|
|
bsw@286
|
38 end
|
|
bsw@286
|
39
|
|
bsw@286
|
40 local time_in_24h = os.time() + 24 * 60 * 60
|
|
bsw@286
|
41
|
|
bsw@286
|
42 local result = net.curl(
|
|
bsw@286
|
43 config.etherpad.api_base
|
|
bsw@286
|
44 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
|
|
bsw@286
|
45 .. "&groupID=" .. config.etherpad.group_id
|
|
bsw@286
|
46 .. "&authorID=" .. etherpad_author_id
|
|
bsw@286
|
47 .. "&validUntil=" .. time_in_24h
|
|
bsw@286
|
48 )
|
|
bsw@286
|
49
|
|
bsw@286
|
50 if not result then
|
|
bsw@286
|
51 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
|
|
bsw@286
|
52 return false
|
|
bsw@286
|
53 end
|
|
bsw@286
|
54
|
|
bsw@286
|
55 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
|
|
bsw@286
|
56
|
|
bsw@286
|
57 if not etherpad_sesion_id then
|
|
bsw@286
|
58 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
|
|
bsw@286
|
59 return false
|
|
bsw@286
|
60 end
|
|
bsw@286
|
61
|
|
bsw@286
|
62 request.set_cookie{
|
|
bsw@286
|
63 path = config.etherpad.cookie_path,
|
|
bsw@286
|
64 name = "sessionID",
|
|
bsw@286
|
65 value = etherpad_sesion_id
|
|
bsw@286
|
66 }
|
|
bsw@286
|
67 end
|
|
bsw@286
|
68
|
|
bsw/jbe@0
|
69 if member then
|
|
bsw@203
|
70 member.last_login = "now"
|
|
bsw@990
|
71
|
|
bsw@990
|
72 local delegations = Delegation:delegations_to_check_for_member_id(member.id)
|
|
bsw@990
|
73
|
|
bsw@990
|
74 if config.check_delegations_interval_hard
|
|
bsw@990
|
75 and member.needs_delegation_check_hard
|
|
bsw@990
|
76 and #delegations > 0 then
|
|
bsw@990
|
77
|
|
bsw@988
|
78 app.session.needs_delegation_check = true
|
|
bsw@990
|
79
|
|
bsw@988
|
80 else
|
|
bsw@990
|
81
|
|
bsw@990
|
82 if #delegations == 0 then
|
|
bsw@990
|
83 member.last_delegation_check = "now"
|
|
bsw@990
|
84 end
|
|
bsw@990
|
85
|
|
bsw@988
|
86 member.last_activity = "now"
|
|
bsw@988
|
87 member.active = true
|
|
bsw@990
|
88
|
|
bsw@988
|
89 end
|
|
bsw@990
|
90
|
|
bsw@292
|
91 if member.lang == nil then
|
|
bsw@292
|
92 member.lang = app.session.lang
|
|
bsw@292
|
93 else
|
|
bsw@292
|
94 app.session.lang = member.lang
|
|
bsw@292
|
95 end
|
|
bsw@905
|
96
|
|
bsw@905
|
97 if member.password_hash_needs_update then
|
|
bsw@905
|
98 member:set_password(password)
|
|
bsw@905
|
99 end
|
|
bsw@905
|
100
|
|
bsw@203
|
101 member:save()
|
|
bsw/jbe@0
|
102 app.session.member = member
|
|
bsw/jbe@0
|
103 app.session:save()
|
|
bsw/jbe@0
|
104 trace.debug('User authenticated')
|
|
bsw@286
|
105 if config.etherpad then
|
|
bsw@286
|
106 do_etherpad_auth(member)
|
|
bsw@286
|
107 end
|
|
bsw@1045
|
108 slot.select("script", function()
|
|
bsw@1045
|
109 ui.script{ script = [[
|
|
bsw@1045
|
110 $('#swiper_info').addClass('active');
|
|
bsw@1045
|
111 ]] }
|
|
bsw@1045
|
112 end)
|
|
bsw@1045
|
113 slot.select("swiper_info", function()
|
|
bsw@1045
|
114 ui.tag { content = _"select tabs" }
|
|
bsw@1045
|
115 slot.put(" ↑ ")
|
|
bsw@1045
|
116 ui.tag { content = _"or swipe" }
|
|
bsw@1045
|
117 slot.put(" ←<br />")
|
|
bsw@1045
|
118 ui.tag { content = _"to show more info and learn what you can do" }
|
|
bsw@1045
|
119 end )
|
|
bsw/jbe@0
|
120 else
|
|
bsw@3
|
121 slot.select("error", function()
|
|
bsw@756
|
122 ui.tag{ content = _'Invalid login name or password!' }
|
|
bsw/jbe@0
|
123 end)
|
|
bsw/jbe@0
|
124 trace.debug('User NOT authenticated')
|
|
bsw/jbe@0
|
125 return false
|
|
bsw/jbe@0
|
126 end
|