liquid_feedback_frontend
annotate env/util/login.lua @ 1646:9cf1f17ac730
Fixed minimum height style of card action area
| author | bsw |
|---|---|
| date | Wed Feb 10 00:30:17 2021 +0100 (2021-02-10) |
| parents | 45fd259aa1ad |
| children |
| rev | line source |
|---|---|
| bsw@1526 | 1 local function do_etherpad_auth(member) |
| bsw@1526 | 2 local result = net.curl( |
| bsw@1526 | 3 config.etherpad.api_base |
| bsw@1526 | 4 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key |
| bsw@1526 | 5 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id) |
| bsw@1526 | 6 ) |
| bsw@1526 | 7 |
| bsw@1526 | 8 if not result then |
| bsw@1526 | 9 slot.put_into("error", _"Etherpad authentication failed" .. " 1") |
| bsw@1526 | 10 return false |
| bsw@1526 | 11 end |
| bsw@1526 | 12 |
| bsw@1526 | 13 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"') |
| bsw@1526 | 14 |
| bsw@1526 | 15 if not etherpad_author_id then |
| bsw@1526 | 16 slot.put_into("error", _"Etherpad authentication failed" .. " 2") |
| bsw@1526 | 17 return false |
| bsw@1526 | 18 end |
| bsw@1526 | 19 |
| bsw@1526 | 20 local time_in_24h = os.time() + 24 * 60 * 60 |
| bsw@1526 | 21 |
| bsw@1526 | 22 local result = net.curl( |
| bsw@1526 | 23 config.etherpad.api_base |
| bsw@1526 | 24 .. "api/1/createSession?apikey=" .. config.etherpad.api_key |
| bsw@1526 | 25 .. "&groupID=" .. config.etherpad.group_id |
| bsw@1526 | 26 .. "&authorID=" .. etherpad_author_id |
| bsw@1526 | 27 .. "&validUntil=" .. time_in_24h |
| bsw@1526 | 28 ) |
| bsw@1526 | 29 |
| bsw@1526 | 30 if not result then |
| bsw@1526 | 31 slot.put_into("error", _"Etherpad authentication failed" .. " 3") |
| bsw@1526 | 32 return false |
| bsw@1526 | 33 end |
| bsw@1526 | 34 |
| bsw@1526 | 35 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"') |
| bsw@1526 | 36 |
| bsw@1526 | 37 if not etherpad_sesion_id then |
| bsw@1526 | 38 slot.put_into("error", _"Etherpad authentication failed" .. " 4") |
| bsw@1526 | 39 return false |
| bsw@1526 | 40 end |
| bsw@1526 | 41 |
| bsw@1526 | 42 request.set_cookie{ |
| bsw@1526 | 43 path = config.etherpad.cookie_path, |
| bsw@1526 | 44 name = "sessionID", |
| bsw@1526 | 45 value = etherpad_sesion_id |
| bsw@1526 | 46 } |
| bsw@1526 | 47 end |
| bsw@1526 | 48 |
| bsw@1526 | 49 function util.login(member) |
| bsw@1526 | 50 member.last_login = "now" |
| bsw@1526 | 51 |
| bsw@1526 | 52 local delegations = Delegation:delegations_to_check_for_member_id(member.id) |
| bsw@1526 | 53 |
| bsw@1526 | 54 if config.check_delegations_interval_hard |
| bsw@1526 | 55 and member.needs_delegation_check_hard |
| bsw@1526 | 56 and #delegations > 0 then |
| bsw@1526 | 57 |
| bsw@1526 | 58 app.session.needs_delegation_check = true |
| bsw@1526 | 59 |
| bsw@1526 | 60 else |
| bsw@1526 | 61 |
| bsw@1526 | 62 if #delegations == 0 then |
| bsw@1526 | 63 member.last_delegation_check = "now" |
| bsw@1526 | 64 end |
| bsw@1526 | 65 |
| bsw@1526 | 66 member.last_activity = "now" |
| bsw@1526 | 67 member.active = true |
| bsw@1526 | 68 |
| bsw@1526 | 69 end |
| bsw@1526 | 70 |
| bsw@1526 | 71 if member.lang == nil then |
| bsw@1526 | 72 member.lang = app.session.lang |
| bsw@1526 | 73 else |
| bsw@1526 | 74 app.session.lang = member.lang |
| bsw@1526 | 75 end |
| bsw@1526 | 76 |
| bsw@1526 | 77 if member.password_hash_needs_update then |
| bsw@1526 | 78 member:set_password(password) |
| bsw@1526 | 79 end |
| bsw@1526 | 80 |
| bsw@1526 | 81 member:save() |
| bsw@1526 | 82 app.session.member = member |
| bsw@1526 | 83 app.session:save() |
| bsw@1526 | 84 |
| bsw@1526 | 85 trace.debug('User authenticated') |
| bsw@1526 | 86 if config.etherpad then |
| bsw@1526 | 87 return do_etherpad_auth(member) |
| bsw@1526 | 88 end |
| bsw@1526 | 89 |
| bsw@1526 | 90 return true |
| bsw@1526 | 91 |
| bsw@1526 | 92 end |