PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/core/widgets/email-unsubscribe.lisp

https://github.com/eslick/cl-registry
Lisp | 71 lines | 67 code | 4 blank | 0 comment | 0 complexity | c55fdf4105871340aee816365c1bc417 MD5 | raw file
  1. (in-package :registry)
  2. (registry-proclamations)
  3. (defwidget email-unsubscribe-widget (widget)
  4. ((username :accessor username :initarg :username)
  5. (type :accessor email-unsubscribe-type :initarg :type))
  6. (:documentation "Provides a widget that allows users to unsubsribe from periodic emails."))
  7. (defun make-email-unsubscribe-widget (username type &key dom-id)
  8. (make-instance 'composite :widgets
  9. (list (make-instance 'email-unsubscribe-widget
  10. :username username
  11. :type type
  12. :dom-id dom-id))))
  13. (defmethod render-widget-body ((widget email-unsubscribe-widget) &rest args)
  14. (declare (ignore args))
  15. (let* ((username (username widget))
  16. (user (get-user username))
  17. (name (and user (user-namestring user)))
  18. (type (email-unsubscribe-type widget))
  19. (forums-p (and user (get-preference :forum-subscriber user)))
  20. (updates-p (and user (get-preference :update-subscriber user))))
  21. (flet ((process-unsubscribes (&key forums updates unsubscribe &allow-other-keys)
  22. (when unsubscribe
  23. (when forums
  24. (setf (get-preference :forum-subscriber user) nil))
  25. (when updates
  26. (setf (get-preference :update-subscriber user) nil)))
  27. (redirect "/")))
  28. (with-html-form (:post #'process-unsubscribes :use-ajax-p t)
  29. (:div
  30. :class "article public-page"
  31. (:div
  32. :class "article-body"
  33. (:h2 (str #!"Unsubscribe from Email"))
  34. (cond ((not user)
  35. (htm (:p (htm (str #!"Unknown user: ") (str username)))))
  36. (t
  37. (htm
  38. (:p (str #!"Welcome ") (str (or name username)))
  39. (:p (str #!"Use this page to unsubscribe from email notifications."))
  40. (:p (str #!"To subscribe, use the \"Contact\" tab on the \"User Preferences\" dialog."))
  41. (:p (cond ((not forums-p)
  42. (cond ((not updates-p)
  43. (htm
  44. (str #!"You are not subscribed to emails.")))
  45. (t
  46. (htm
  47. (str
  48. #!"You are not subscribed to forum changes.")))))
  49. ((not updates-p)
  50. (htm (str #!"You are not subscribed to updates."))))))))
  51. (:p
  52. (when (or forums-p updates-p)
  53. (htm
  54. (str #!"Unsubscribe from:")
  55. (:br)
  56. (when forums-p
  57. (htm "  ")
  58. (render-checkbox "forums" (string-equal type "forums"))
  59. (htm " " (str #!"forum notifications")
  60. (:br)))
  61. (when updates-p
  62. (htm "  ")
  63. (render-checkbox "updates" (string-equal type "updates"))
  64. (htm " " (str #!"update notifications")
  65. (:br)))
  66. (render-translated-button "unsubscribe")))
  67. (render-translated-button "cancel"))))))))