]> git.basschouten.com Git - openhab-addons.git/commitdiff
Fix person reauth (#13839)
authorTom Deckers <tom@ducbase.com>
Sun, 4 Dec 2022 18:16:07 +0000 (19:16 +0100)
committerGitHub <noreply@github.com>
Sun, 4 Dec 2022 18:16:07 +0000 (19:16 +0100)
* add null checks
* fix/improve account.html

Signed-off-by: Tom Deckers <tom@ducbase.com>
bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexAuthServlet.java
bundles/org.openhab.binding.webexteams/src/main/java/org/openhab/binding/webexteams/internal/WebexTeamsHandler.java
bundles/org.openhab.binding.webexteams/src/main/resources/templates/account.html

index 4ee33181635626b37cc80e35cb63963e60b815be..f1c6440e0979d656b04629907b4712691398675f 100644 (file)
@@ -121,7 +121,7 @@ public class WebexAuthServlet extends HttpServlet {
 
             replaceMap.put(KEY_PAGE_REFRESH,
                     params.isEmpty() ? "" : String.format(HTML_META_REFRESH_CONTENT, servletBaseURL));
-            if (!reqError.isBlank()) {
+            if (reqError != null && !reqError.isBlank()) {
                 logger.debug("Webex redirected with an error: {}", reqError);
                 replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, reqError));
             } else if (!reqState.isBlank()) {
@@ -172,12 +172,12 @@ public class WebexAuthServlet extends HttpServlet {
             map.put(ACCOUNT_SHWOMSG, "u-show");
             map.put(ACCOUNT_MSG, "Configure account.");
         } else if (handler.isAuthorized()) {
-            map.put(ACCOUNT_USER_ID, String.format(" (Authorized user: %s)", webexUser));
+            map.put(ACCOUNT_USER_ID, String.format("Authorized user: %s", webexUser));
             map.put(ACCOUNT_SHOWBTN, "u-hide");
             map.put(ACCOUNT_SHWOMSG, "u-show");
             map.put(ACCOUNT_MSG, "Authorized.");
-        } else if (!webexUser.isBlank()) {
-            map.put(ACCOUNT_USER_ID, String.format(" (Unauthorized user: %s)", webexUser));
+        } else if (webexUser.isBlank()) {
+            map.put(ACCOUNT_USER_ID, "Unauthorized user");
             map.put(ACCOUNT_SHOWBTN, "u-show");
             map.put(ACCOUNT_SHWOMSG, "u-hide");
             map.put(ACCOUNT_MSG, "");
index d5922259b98bb8095bcf75a4afc06a96bfca9da8..4339b938f508be1efcbb01bbca691b6d73fd8e74 100644 (file)
@@ -70,7 +70,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
 
     private @Nullable OAuthClientService authService;
 
-    private boolean configured = false; // is the handler instance properly configured?
+    private boolean configured; // is the handler instance properly configured?
     private volatile boolean active; // is the handler instance active?
     String accountType = ""; // bot or person?
 
@@ -97,6 +97,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
     public void initialize() {
         logger.debug("Initializing thing {}", this.getThing().getUID());
         active = true;
+        this.configured = false;
         config = getConfigAs(WebexTeamsConfiguration.class);
 
         final String token = config.token;
@@ -210,6 +211,9 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
 
     public boolean isAuthorized() {
         final AccessTokenResponse accessTokenResponse = getAccessTokenResponse();
+        if (accessTokenResponse == null) {
+            return false;
+        }
 
         if ("person".equals(this.accountType)) {
             return accessTokenResponse != null && accessTokenResponse.getAccessToken() != null
@@ -287,7 +291,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
                 updateStatus(ThingStatus.ONLINE);
                 return true;
             } catch (WebexTeamsException e) {
-                logger.warn("Failed to refresh: {}", e.getMessage());
+                logger.warn("Failed to refresh: {}.  Did you authorize?", e.getMessage());
                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
             }
             return false;
index 0a741c227e294bc179bc2d572f6c95c6e7539801..8e0b6cdbcb62b6f120f520788b4405d3ad6eb468 100644 (file)
@@ -1,6 +1,6 @@
 <div class="row" id="${account.id}">
-  <div class="one column">${account.type}:</div>
-  <div class="nine columns"><i>${account.name}${account.user}</i></div>
+  <div class="three columns">${account.name}:</div>
+  <div class="seven columns"><i>${account.user} (${account.type})</i></div>
   <div class="two columns ${account.showbtn}">
     <div class="button-primary"><a href=${account.authorize}>Authorize Account</a></div>
   </div>