aboutsummaryrefslogtreecommitdiff
path: root/sx-interaction.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-03-08 19:06:01 -0300
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-03-08 19:15:05 -0300
commitad86033d0d425bae8a034bfeadc2940b38f6a733 (patch)
tree524b28c6ebda1cb42d4a4a552df374ab812b1614 /sx-interaction.el
parent019ab80c7935da8236ef902cd04e0216825e79f8 (diff)
Define sx-ensure-authentication
Diffstat (limited to 'sx-interaction.el')
-rw-r--r--sx-interaction.el13
1 files changed, 13 insertions, 0 deletions
diff --git a/sx-interaction.el b/sx-interaction.el
index 368da09..00c2a45 100644
--- a/sx-interaction.el
+++ b/sx-interaction.el
@@ -44,6 +44,7 @@
(require 'sx-question-mode)
(require 'sx-question-list)
(require 'sx-compose)
+(require 'sx-cache)
;;; Using data in buffer
@@ -105,6 +106,18 @@ Only fields contained in TO are copied."
(setcar to (car from))
(setcdr to (cdr from)))
+(defun sx-ensure-authentication ()
+ "Signal user-error if the user refuses to authenticate.
+Note that `sx-method-call' already does authentication checking.
+This function is meant to be used by commands that don't
+immediately perform method calls, such as `sx-ask'. This way,
+the unauthenticated user will be prompted before going through
+the trouble of composing an entire question."
+ (unless (sx-cache-get 'auth)
+ (if (y-or-n-p "This command requires authentication, would you like to authenticate? ")
+ (sx-authenticate)
+ (sx-user-error "This command requires authentication, please run `M-x sx-authenticate' and try again."))))
+
;;; Visiting
(defun sx-visit-externally (data &optional copy-as-kill)