liquid_feedback_frontend

view app/main/index/_action/login.lua @ 1145:904f6807f7fa

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

Impressum / About Us