aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-08-06 21:07:33 +0200
committerGravatar Tom Willemsen2012-08-06 21:16:03 +0200
commit32f394cbfa1bed4b3afbc3d7a53964aa57893c71 (patch)
tree8c98c793ff383c6a45e127d80fd1d86ae0847d8d
parent0516b22b9a667ea4db0ec3129cca69f1d2c6868b (diff)
downloadavandu-32f394cbfa1bed4b3afbc3d7a53964aa57893c71.tar.gz
avandu-32f394cbfa1bed4b3afbc3d7a53964aa57893c71.zip
Make avandu use auth-source
* avandu.el (avandu--clear-data): Only use `clear-string' if `avandu-password' is a string, otherwise just set it to nil. (avandu--get-credentials): (avandu--password): New functions. (avandu-login): If either `avandu-user' or `avandu-password' is nil, call `avandu--get-credentials' to fill them. Just pass along `avandu-user' and use `avandu--password' to get the password.
-rw-r--r--avandu.el34
1 files changed, 30 insertions, 4 deletions
diff --git a/avandu.el b/avandu.el
index 8ba638e..f06d0f1 100644
--- a/avandu.el
+++ b/avandu.el
@@ -227,7 +227,24 @@ with their char value or with the value in
"Clean up login data. This makes for a clean slate next time."
(setq avandu-user nil
avandu--session-id nil)
- (clear-string avandu-password))
+
+ (if (stringp avandu-password)
+ (clear-string avandu-password)
+ (setq avandu-password nil)))
+
+(defun avandu--get-credentials ()
+ "Get a username and password for Tiny Tiny RSS. Try it first
+with `auth-source-search' and then by asking the user."
+ (let ((credentials (auth-source-search :max 1
+ :host avandu-tt-rss-api-url
+ :type 'netrc
+ :require '(:user :secret)
+ :user avandu-user)))
+ (if credentials
+ (setq avandu-user (plist-get (car credentials) :user)
+ avandu-password (plist-get (car credentials) :secret))
+ (avandu-getset avandu-user "Username: ")
+ (avandu-getset avandu-password "Password: " t))))
(defun avandu--get-session-id (results)
"Get the session id from RESULTS."
@@ -278,6 +295,13 @@ feed-id property."
(message "%s" (button-label button))))
(insert-char ?\n 2))
+(defun avandu--password ()
+ "Get the password. This means either return `avandu-password'
+as-is, or if it's a function return the result of that function."
+ (if (functionp avandu-password)
+ (funcall avandu-password)
+ avandu-password))
+
(defun avandu--send-command (data)
"Send a command with parameters DATA to tt-rss. The current
session-id is added to the request and then DATA is passed on to
@@ -451,11 +475,13 @@ in. This function returns t if we are, or nil if we're not."
and saved in memory. This function returns t on succes, nil
otherwise."
(interactive)
+ (unless (and avandu-user avandu-password)
+ (avandu--get-credentials))
+
(let ((result (avandu--send-command
`((op . "login")
- (user . ,(avandu-getset avandu-user "Username: "))
- (password
- . ,(avandu-getset avandu-password "Password: " t))))))
+ (user . ,avandu-user)
+ (password . ,(avandu--password))))))
(if (eq (avandu--get-status-id result) 0)
(progn
(setq avandu--session-id (avandu--get-session-id result))