0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-06 12:01:19 -05:00

Merge pull request #1569 from penpot/dashboard-user-menu

Dashboard user menu and session cookie
This commit is contained in:
Andrey Antukh 2022-02-09 23:51:14 +01:00 committed by GitHub
commit 528839cde2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 28 deletions

View file

@ -109,6 +109,7 @@
(s/def ::secret-key ::us/string)
(s/def ::allow-demo-users ::us/boolean)
(s/def ::assets-path ::us/string)
(s/def ::authenticated-cookie-domain ::us/string)
(s/def ::database-password (s/nilable ::us/string))
(s/def ::database-uri ::us/string)
(s/def ::database-username (s/nilable ::us/string))
@ -199,6 +200,7 @@
::allow-demo-users
::audit-log-archive-uri
::audit-log-gc-max-age
::authenticated-cookie-domain
::database-password
::database-uri
::database-username

View file

@ -21,9 +21,13 @@
[integrant.core :as ig]
[ring.middleware.session.store :as rss]))
;; A default cookie name for storing the session. We don't allow
;; configure it.
(def cookie-name "auth-token")
;; A default cookie name for storing the session. We don't allow to configure it.
(def token-cookie-name "auth-token")
;; A cookie that we can use to check from other sites of the same domain if a user
;; is registered. Is not intended for on premise installations, although nothing
;; prevents using it if some one wants to.
(def authenticated-cookie-name "authenticated")
(deftype DatabaseStore [pool tokens]
rss/SessionStore
@ -78,7 +82,7 @@
(defn- delete-session
[store {:keys [cookies] :as request}]
(when-let [token (get-in cookies [cookie-name :value])]
(when-let [token (get-in cookies [token-cookie-name :value])]
(rss/delete-session store token)))
(defn- retrieve-session
@ -88,21 +92,35 @@
(defn- retrieve-from-request
[store {:keys [cookies] :as request}]
(->> (get-in cookies [cookie-name :value])
(->> (get-in cookies [token-cookie-name :value])
(retrieve-session store)))
(defn- add-cookies
[response token]
(let [cors? (contains? cfg/flags :cors)
secure? (contains? cfg/flags :secure-session-cookies)]
(assoc response :cookies {cookie-name {:path "/"
:http-only true
:value token
:same-site (if cors? :none :lax)
:secure secure?}})))
secure? (contains? cfg/flags :secure-session-cookies)
authenticated-cookie-domain (cfg/get :authenticated-cookie-domain)]
(update response :cookies
(fn [cookies]
(cond-> cookies
:always
(assoc token-cookie-name {:path "/"
:http-only true
:value token
:same-site (if cors? :none :lax)
:secure secure?})
(some? authenticated-cookie-domain)
(assoc authenticated-cookie-name {:domain authenticated-cookie-domain
:path "/"
:value true
:same-site :strict
:secure secure?}))))))
(defn- clear-cookies
[response]
(assoc response :cookies {cookie-name {:value "" :max-age -1}}))
(assoc response :cookies {token-cookie-name {:value "" :max-age -1}
authenticated-cookie-name {:value "" :max-age -1}}))
(defn- middleware
[events-ch store handler]

View file

@ -0,0 +1,4 @@
<svg viewBox="761.822 754.121 16 16" width="16" height="16" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M769.822 768.921a6.8 6.8 0 1 0 0-13.6 6.8 6.8 0 0 0 0 13.6Zm0 1.2a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z" />
<path d="M770.357 766.536h-1.179v-1.24h1.179v1.24Zm1.925-5.57c-.126.264-.394.592-.802.985-.41.394-.68.673-.813.838a1.712 1.712 0 0 0-.304.596c-.068.23-.1.54-.091.929h-1.07c0-.454.036-.817.11-1.088.073-.27.183-.507.328-.71.145-.202.408-.5.79-.893.38-.392.626-.677.735-.855.11-.178.163-.443.163-.795 0-.353-.126-.665-.377-.936s-.615-.406-1.092-.406c-1.078 0-1.615.64-1.615 1.918h-1.07c.017-.583.086-1.027.206-1.33.121-.304.316-.575.583-.814.268-.238.565-.414.893-.529.329-.112.675-.17 1.039-.17.736 0 1.35.218 1.84.65.49.433.734 1.01.734 1.73.002.326-.062.618-.187.88Z" />
</svg>

After

Width:  |  Height:  |  Size: 828 B

View file

@ -415,7 +415,7 @@
width: 12px;
}
&.feedback {
&.separator {
border-top: 1px solid $color-gray-10;
}
}

View file

@ -513,22 +513,30 @@
[:li {:on-click (partial on-click :settings-profile)
:data-test "profile-profile-opt"}
[:span.icon i/user]
[:span.text (tr "labels.profile")]]
[:li {:on-click (partial on-click :settings-password)
:data-test "password-profile-opt"}
[:span.icon i/lock]
[:span.text (tr "labels.password")]]
[:li {:on-click #(on-click (du/logout) %)
:data-test "logout-profile-opt"}
[:span.icon i/exit]
[:span.text (tr "labels.logout")]]
[:span.text (tr "labels.your-account")]]
[:li.separator {:on-click #(dom/open-new-window "https://help.penpot.app")
:data-test "help-center-profile-opt"}
[:span.icon i/help]
[:span.text (tr "labels.help-center")]]
[:li {:on-click #(dom/open-new-window "https://penpot.app/libraries-templates.html")
:data-test "libraries-templates-profile-opt"}
[:span.icon i/download]
[:span.text (tr "labels.libraries-and-templates")]]
[:li {:on-click #(dom/open-new-window "https://penpot.app?no-redirect=1")
:data-test "about-penpot-profile-opt"} ;; Parameter ?no-redirect is to force stay in landing page
[:span.icon i/logo-icon] ;; instead of redirecting to app
[:span.text (tr "labels.about-penpot")]]
(when (contains? @cf/flags :user-feedback)
[:li.feedback {:on-click (partial on-click :settings-feedback)
[:li.separator {:on-click (partial on-click :settings-feedback)
:data-test "feedback-profile-opt"}
[:span.icon i/msg-info]
[:span.text (tr "labels.give-feedback")]
])]]]
[:span.text (tr "labels.give-feedback")]])
[:li.separator {:on-click #(on-click (du/logout) %)
:data-test "logout-profile-opt"}
[:span.icon i/exit]
[:span.text (tr "labels.logout")]]]]]
(when (and team profile)
[:& comments-section {:profile profile

View file

@ -64,6 +64,7 @@
(def full-screen-off (icon-xref :full-screen-off))
(def grid (icon-xref :grid))
(def grid-snap (icon-xref :grid-snap))
(def help (icon-xref :help))
(def icon-empty (icon-xref :icon-empty))
(def icon-list (icon-xref :icon-list))
(def icon-lock (icon-xref :icon-lock))

View file

@ -241,7 +241,6 @@
[:span (tr "workspace.header.menu.option.preferences")] [:span i/arrow-slide]]
(when (contains? @cf/flags :user-feedback)
[:*
[:li.separator]
[:li.feedback {:on-click (st/emitf (rt/nav :settings-feedback))}
[:span (tr "labels.give-feedback")]]])]]

View file

@ -973,6 +973,10 @@ msgstr "Info"
msgid "history.alert-message"
msgstr "You are seeing version %s"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.about-penpot"
msgstr "About Penpot"
msgid "labels.accept"
msgstr "Accept"
@ -1108,6 +1112,10 @@ msgstr "Give feedback"
msgid "labels.go-back"
msgstr "Go back"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.help-center"
msgstr "Help Center"
#: src/app/main/ui/workspace/comments.cljs, src/app/main/ui/viewer/header.cljs
msgid "labels.hide-resolved-comments"
msgstr "Hide resolved comments"
@ -1135,6 +1143,10 @@ msgstr "Internal Error"
msgid "labels.language"
msgstr "Language"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.libraries-and-templates"
msgstr "Libraries & Templates"
msgid "labels.link"
msgstr "Link"
@ -1216,7 +1228,7 @@ msgstr "Password"
msgid "labels.permissions"
msgstr "Permissions"
#: src/app/main/ui/settings/sidebar.cljs, src/app/main/ui/dashboard/sidebar.cljs
#: src/app/main/ui/settings/sidebar.cljs
msgid "labels.profile"
msgstr "Profile"
@ -1330,6 +1342,10 @@ msgstr "Workspace"
msgid "labels.write-new-comment"
msgstr "Write new comment"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.your-account"
msgstr "Your account"
#: src/app/main/data/workspace/persistence.cljs, src/app/main/data/workspace/persistence.cljs, src/app/main/data/media.cljs
msgid "media.loading"
msgstr "Loading image…"

View file

@ -974,6 +974,10 @@ msgstr "Información"
msgid "history.alert-message"
msgstr "Estás viendo la versión %s"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.about-penpot"
msgstr "Acerca de Penpot"
msgid "labels.accept"
msgstr "Aceptar"
@ -1109,6 +1113,10 @@ msgstr "Danos tu opinión"
msgid "labels.go-back"
msgstr "Volver"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.help-center"
msgstr "Centro de ayuda"
#: src/app/main/ui/workspace/comments.cljs, src/app/main/ui/viewer/header.cljs
msgid "labels.hide-resolved-comments"
msgstr "Ocultar comentarios resueltos"
@ -1136,6 +1144,10 @@ msgstr "Error interno"
msgid "labels.language"
msgstr "Idioma"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.libraries-and-templates"
msgstr "Bibliotecas y Plantillas"
msgid "labels.link"
msgstr "Enlace"
@ -1217,7 +1229,7 @@ msgstr "Contraseña"
msgid "labels.permissions"
msgstr "Permisos"
#: src/app/main/ui/settings/sidebar.cljs, src/app/main/ui/dashboard/sidebar.cljs
#: src/app/main/ui/settings/sidebar.cljs
msgid "labels.profile"
msgstr "Perfil"
@ -1332,6 +1344,10 @@ msgstr "Espacio de trabajo"
msgid "labels.write-new-comment"
msgstr "Escribir un nuevo comentario"
#: src/app/main/ui/dashboard/sidebar.cljs
msgid "labels.your-account"
msgstr "Tu cuenta"
#: src/app/main/data/workspace/persistence.cljs, src/app/main/data/workspace/persistence.cljs, src/app/main/data/media.cljs
msgid "media.loading"
msgstr "Cargando imagen…"