{"id":211,"date":"2017-03-03T20:26:01","date_gmt":"2017-03-03T19:26:01","guid":{"rendered":"http:\/\/www.hman-projects.de\/?p=211"},"modified":"2017-03-03T20:32:20","modified_gmt":"2017-03-03T19:32:20","slug":"phonegap-cordova-2017-teil-4-usersettings-innerhalb-der-app-sichern","status":"publish","type":"post","link":"https:\/\/www.hman-projects.de\/?p=211","title":{"rendered":"Phonegap \u2013 Cordova 2017 Teil 4: Usersettings innerhalb der App sichern"},"content":{"rendered":"<p>Settings, &#8211; irgendwo muss der User ja seine Account-Daten f\u00fcr den Zugriff auf diese Tools sichern.<\/p>\n<p>Wie sichert man Daten im Browser und funktioniert das auch noch in Cordova?<br \/>\nDie Maske war dazu schnell erstellt und dann um diese Accordionpane aus JQuery-Mobile erweitert.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-213\" src=\"http:\/\/www.hman-projects.de\/wp-content\/uploads\/2017\/03\/cordova_usersettings_page_1.png\" alt=\"Page mit Usersettings\" width=\"263\" height=\"482\" srcset=\"https:\/\/www.hman-projects.de\/wp-content\/uploads\/2017\/03\/cordova_usersettings_page_1.png 263w, https:\/\/www.hman-projects.de\/wp-content\/uploads\/2017\/03\/cordova_usersettings_page_1-164x300.png 164w\" sizes=\"(max-width: 263px) 100vw, 263px\" \/><\/p>\n<p>Hier der Code:<\/p>\n<p><!--more--><\/p>\n<p><code><br \/>\nfunction saveSpSettings() {<br \/>\n\/\/ Store the settings locally<br \/>\nvar sp_uname = $('#sp_uname').val();<br \/>\nvar sp_pw = $('#sp_pw').val();<br \/>\nvar sp_oc = $('#sp_oc').val();<br \/>\nlocalStorage.setItem ( \"spSettings\", JSON.stringify( { spUname: sp_uname, spPw: sp_pw, spOc: sp_oc } ) );<br \/>\n\/\/ if ok:<br \/>\nshowAlert( 'Settings', 'Stored');<br \/>\n}<br \/>\nfunction loadSpSettings() {<br \/>\nvar spSettings = JSON.parse(localStorage.getItem ( \"spSettings\" ));<br \/>\nif (spSettings.spUname) {<br \/>\n$('#sp_uname').val(spSettings.spUname);<br \/>\nvar sp_uname =spSettings.spUname;<br \/>\n}<br \/>\nif (spSettings.spPw) {<br \/>\n$('#sp_pw').val(spSettings.spPw);<br \/>\nvar sp_pw = spSettings.spPw;<br \/>\n\/\/ Debugging: showAlert( 'Settings', sp_pw );<br \/>\n}<br \/>\nif (spSettings.spOc) {<br \/>\n$('#sp_oc').val(spSettings.spOc);<br \/>\nvar sp_oc = spSettings.spOc;<br \/>\n}<br \/>\n}<br \/>\n<\/code><!--more--><\/p>\n<hr \/>\n<p>Das wars, zwei Funktionen um Einstellungen als JSON-String zu sichern und zu laden. Sp\u00e4ter wird das Passwort nur noch optional gespeichert und muss beim ersten Start oder nach Zeit wieder neu eingegeben erden.<br \/>\nDie Funktion\u00a0 \u201esaveSpSettings\u201c wird durch den Save-Button getriggert.<br \/>\nDie Funktion \u201eloadSpSettings\u201c wird beim Start der App getriggert.<\/p>\n<p>Falls das Passwort wirklich hier gesichert werden soll, dann wird es sp\u00e4ter verschl\u00fcsselt gespeichert. F\u00fcr einen test des localStorage reicht das aber so.<\/p>\n<p>Link zum Accordion:\u2028<a href=\"http:\/\/demos.jquerymobile.com\/1.3.2\/widgets\/accordions\/\" target=\"_blank\">http:\/\/demos.jquerymobile.com\/1.3.2\/widgets\/accordions\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Settings, &#8211; irgendwo muss der User ja seine Account-Daten f\u00fcr den Zugriff auf diese Tools sichern. Wie sichert man Daten im Browser und funktioniert das auch noch in Cordova? Die Maske war dazu schnell erstellt und dann um diese Accordionpane aus JQuery-Mobile erweitert. Hier der Code:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=\/wp\/v2\/posts\/211"}],"collection":[{"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":6,"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hman-projects.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}