diff options
-rw-r--r-- | ll-auth-binding/htdocs/IdentityBinding.js | 20 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/auth.html | 14 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/index.html | 1 | ||||
-rw-r--r-- | ll-auth-binding/src/ll-auth-binding.c | 14 |
4 files changed, 44 insertions, 5 deletions
diff --git a/ll-auth-binding/htdocs/IdentityBinding.js b/ll-auth-binding/htdocs/IdentityBinding.js index 5f9ea24..4d0d98f 100644 --- a/ll-auth-binding/htdocs/IdentityBinding.js +++ b/ll-auth-binding/htdocs/IdentityBinding.js @@ -53,8 +53,24 @@ } function gotevent(obj) { - console.log("gotevent:" + JSON.stringify(obj)); - document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj); + console.log("gotevent:" + JSON.stringify(obj)); + document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj); + + document.getElementById("message").innerHTML = ""; + + if (obj.event == "ll-auth/login") { + document.getElementById("userid").innerHTML = obj.data.user; + document.getElementById("device").innerHTML = obj.data.device; + } + + if (obj.event == "ll-auth/logout") { + document.getElementById("userid").innerHTML = ""; + document.getElementById("device").innerHTML = ""; + } + + if (obj.event == "ll-auth/failed") { + document.getElementById("message").innerHTML = obj.data.message; + } } function send(message) { diff --git a/ll-auth-binding/htdocs/auth.html b/ll-auth-binding/htdocs/auth.html index 6e0da89..ac48ff9 100644 --- a/ll-auth-binding/htdocs/auth.html +++ b/ll-auth-binding/htdocs/auth.html @@ -17,12 +17,22 @@ <li><button onclick="callbinder('ll-auth','getuser', {})">get user</button></li> </ol> <br> + <div> + </div> + <h2>User:</h2> + <ol> + <li>id: <span id="userid"></span></li> + <li>device: <span id="device"></span></li> + </ol> + <div id="message" style="color:red;"></div> + <br/> <div id="main" style="visibility:hidden"> + <h2>Debug: </h2> <ol> <li>Question <div id="question"></div></li> <li>Response <div id="output"></div></li> - <li>Events: <div id="outevt"></div> + <li>Events: <div id="outevt"></div></li> </ol> </div> </body> -</html>
\ No newline at end of file +</html> diff --git a/ll-auth-binding/htdocs/index.html b/ll-auth-binding/htdocs/index.html index 5eb0401..1c90ae5 100644 --- a/ll-auth-binding/htdocs/index.html +++ b/ll-auth-binding/htdocs/index.html @@ -6,6 +6,7 @@ <h1>Identity Binding tests</h1> <ol> <li><a href="auth.html">Auth</a></li> + <li><a href="auth2.html">Auth2</a></li> </ol> </body> </html> diff --git a/ll-auth-binding/src/ll-auth-binding.c b/ll-auth-binding/src/ll-auth-binding.c index e85d63a..78e9733 100644 --- a/ll-auth-binding/src/ll-auth-binding.c +++ b/ll-auth-binding/src/ll-auth-binding.c @@ -13,7 +13,7 @@ static struct pam_conv conv = { misc_conv, NULL }; static char* current_device = NULL; static char* current_user = NULL; -afb_event evt_login, evt_logout; +afb_event evt_login, evt_logout, evt_failed; /// @brief API's verb 'login'. Try to login a user using a device /// @param[in] req The request object. Should contains a json with a "device" key. @@ -28,6 +28,7 @@ static void verb_login(struct afb_req req) { AFB_ERROR("[login] the current user must be logged out first!"); afb_req_fail(req, "current user must be logged out first!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"A user is already logged in!\"}")); return; } @@ -36,6 +37,7 @@ static void verb_login(struct afb_req req) { AFB_ERROR("[login] device must be provided!"); afb_req_fail(req, "device must be provided!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"device must be provided!\"}")); return; } @@ -45,6 +47,7 @@ static void verb_login(struct afb_req req) { AFB_ERROR("PAM start failed!"); afb_req_fail(req, "PAM start failed!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"PAM start failed!\"}")); return; } @@ -56,6 +59,7 @@ static void verb_login(struct afb_req req) AFB_ERROR("PAM putenv failed!"); afb_req_fail(req, "PAM putenv failed!", NULL); pam_end(pamh, r); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"PAM putenv failed!\"}")); return; } @@ -64,6 +68,7 @@ static void verb_login(struct afb_req req) AFB_ERROR("PAM authenticate failed!"); afb_req_fail(req, "PAM authenticate failed!", NULL); pam_end(pamh, r); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"PAM authenticate failed!\"}")); return; } @@ -72,6 +77,7 @@ static void verb_login(struct afb_req req) AFB_ERROR("PAM acct_mgmt failed!"); afb_req_fail(req, "PAM acct_mgmt failed!", NULL); pam_end(pamh, r); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"PAM acct_mgmt failed!\"}")); return; } @@ -81,6 +87,7 @@ static void verb_login(struct afb_req req) { AFB_ERROR("[login] No user provided by the PAM module!"); afb_req_fail(req, "No user provided by the PAM module!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"No user provided by the PAM module!\"}")); return; } @@ -91,6 +98,7 @@ static void verb_login(struct afb_req req) { AFB_ERROR("PAM end failed!"); afb_req_fail(req, "PAM end failed!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"PAM end failed!\"}")); return; } @@ -114,6 +122,7 @@ static void verb_logout(struct afb_req req) { AFB_INFO("[logout] device must be provided!"); afb_req_fail(req, "device must be provided!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"Device must be provided!\"}")); return; } @@ -135,12 +144,14 @@ static void verb_logout(struct afb_req req) { AFB_INFO("No user was linked to this device!"); afb_req_fail(req, "No user was linked to this device!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"No user was linked to this device!\"}")); return; } } AFB_INFO("The unplugged device wasn't the user key!"); afb_req_fail(req, "The unplugged device wasn't the user key!", NULL); + afb_event_broadcast(evt_failed, json_tokener_parse("{\"message\":\"The unplugged device wasn't the user key!\"}")); } static void verb_getuser(struct afb_req req) @@ -164,6 +175,7 @@ int ll_auth_init() current_device = NULL; evt_login = afb_daemon_make_event("login"); evt_logout = afb_daemon_make_event("logout"); + evt_failed = afb_daemon_make_event("failed"); if (afb_event_is_valid(evt_login) && afb_event_is_valid(evt_logout)) return 0; |