Browse Source

Merge pull request #6 from zoechi/logged-in-p_unlocked-p

Call out to Bitwarden to check of logged-in and unlocked status
Sean Farley 4 years ago
parent
commit
94242ff34b
1 changed files with 8 additions and 6 deletions
  1. 8 6
      bitwarden.el

+ 8 - 6
bitwarden.el

@@ -89,14 +89,16 @@ example, this can be the :secret plist from
 (defun bitwarden-logged-in-p ()
   "Check if `bitwarden-user' is logged in.
 Returns nil if not logged in."
-  (let* ((json-object-type 'hash-table)
-         (json-key-type 'string)
-         (json (json-read-file bitwarden-data-file)))
-    (gethash "__PROTECTED__key" json)))
+  (let* ((ret (apply #'bitwarden--raw-runcmd "login" '("--check")))
+	 (exit-code (nth 0 ret)))
+    (eq exit-code 0)))
 
 (defun bitwarden-unlocked-p ()
-  "Check if we have already set the 'BW_SESSION' environment variable."
-  (and (bitwarden-logged-in-p) (getenv "BW_SESSION")))
+  "Check if `bitwarden-user' is loged in.
+Returns nil if not unlocked."
+  (let* ((ret (apply #'bitwarden--raw-runcmd "unlock" '("--check")))
+	 (exit-code (nth 0 ret)))
+    (eq exit-code 0)))
 
 (defun bitwarden--raw-runcmd (cmd &rest args)
   "Run bw command CMD with ARGS.