liquid_feedback_frontend
annotate app/main/member/_action/update_api_key.lua @ 172:165f4bd02cf3
don't show the first draft of a new initiative as a new draft event in the timeline
new draft should only show changes of drafts drafts of new initiatives as they are handled by the new initiative event
new draft should only show changes of drafts drafts of new initiatives as they are handled by the new initiative event
| author | Daniel Poelzleithner <poelzi@poelzi.org> |
|---|---|
| date | Sun Oct 10 19:40:32 2010 +0200 (2010-10-10) |
| parents | 0849be391140 |
| children | 976d493106a1 |
| rev | line source |
|---|---|
| bsw@51 | 1 |
| bsw@51 | 2 local setting_key = "liquidfeedback_frontend_api_key" |
| bsw@51 | 3 local setting = Setting:by_pk(app.session.member.id, setting_key) |
| bsw@51 | 4 |
| bsw@51 | 5 local api_key |
| bsw@51 | 6 |
| bsw@51 | 7 if param.get("delete", atom.boolean) then |
| bsw@51 | 8 |
| bsw@51 | 9 if setting then |
| bsw@51 | 10 setting:destroy() |
| bsw@51 | 11 end |
| bsw@51 | 12 |
| bsw@51 | 13 else |
| bsw@51 | 14 |
| bsw@51 | 15 if not setting then |
| bsw@51 | 16 setting = Setting:new() |
| bsw@51 | 17 setting.member_id = app.session.member.id |
| bsw@51 | 18 setting.key = setting_key |
| bsw@51 | 19 end |
| bsw@51 | 20 |
| bsw@51 | 21 api_key = multirand.string( |
| bsw@51 | 22 20, |
| bsw@51 | 23 '23456789BCDFGHJKLMNPQRSTVWXYZbcdfghjkmnpqrstvwxyz' |
| bsw@51 | 24 ) |
| bsw@51 | 25 |
| bsw@51 | 26 setting.value = api_key |
| bsw@51 | 27 |
| bsw@51 | 28 setting:save() |
| bsw@51 | 29 end |
| bsw@51 | 30 |
| bsw@51 | 31 |
| bsw@51 | 32 local setting_key = "liquidfeedback_frontend_api_key_history" |
| bsw@51 | 33 |
| bsw@51 | 34 setting = SettingMap:new() |
| bsw@51 | 35 setting.member_id = app.session.member.id |
| bsw@51 | 36 setting.key = setting_key |
| bsw@51 | 37 setting.subkey = db:query("SELECT now()")[1].now |
| bsw@51 | 38 setting.value = api_key or "" |
| bsw@51 | 39 local dberr = setting:try_save() |
| bsw@51 | 40 |
| bsw@51 | 41 if dberr then |
| bsw@51 | 42 if dberr:is_kind_of("IntegrityConstraintViolation.UniqueViolation") then |
| bsw@51 | 43 slot.put_into("error", _"The API key has been changed too fast.") |
| bsw@51 | 44 return |
| bsw@51 | 45 else |
| bsw@51 | 46 dberr:escalate() |
| bsw@51 | 47 end |
| bsw@51 | 48 end |
| bsw@51 | 49 |
| bsw@51 | 50 if not api_key then |
| bsw@51 | 51 slot.put_into("notice", _"API key has been deleted") |
| bsw@51 | 52 else |
| bsw@51 | 53 slot.put_into("notice", _"API key has been updated") |
| bsw@51 | 54 end |