Skip to content

Commit

Permalink
Allow session ID and login time params, and insert them into the data…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
ianmcorvidae committed Dec 10, 2024
1 parent 7de4910 commit 21a4c97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/apps/persistence/users.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:use [clojure-commons.core :only [remove-nil-values]]
[kameleon.uuids :only [uuidify]]
[korma.core :exclude [update]])
(:require [korma.core :as sql])
(:require [korma.core :as sql]
[apps.util.conversions :refer [long->timestamp]])
(:import [java.sql Timestamp]))

(defn- user-base-query
Expand Down Expand Up @@ -45,15 +46,17 @@

(defn- insert-login-record
"Records when a user logs into the DE."
[user-id ip-address]
[user-id ip-address session-id login-time]
(insert :logins
(values (remove-nil-values
{:user_id user-id
:ip_address ip-address}))))
:ip_address ip-address
:session_id session-id
:login_time (long->timestamp login-time)}))))

(defn record-login
"Records when a user logs into the DE. Returns the recorded login time."
[username ip-address]
(-> (insert-login-record (get-user-id username) ip-address)
[username ip-address session-id login-time]
(-> (insert-login-record (get-user-id username) ip-address session-id login-time)
(:login_time)
(.getTime)))
6 changes: 4 additions & 2 deletions src/apps/routes/schemas/user.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns apps.routes.schemas.user
(:use [common-swagger-api.schema :only [describe]]
[apps.routes.params :only [SecuredQueryParams]]
[schema.core :only [defschema]])
[schema.core :only [defschema optional-key]])
(:require [common-swagger-api.schema.sessions :as sessions-schema])
(:import [java.util UUID]))

Expand All @@ -17,4 +17,6 @@

(defschema LoginParams
(merge SecuredQueryParams
sessions-schema/IPAddrParam))
sessions-schema/IPAddrParam
{(optional-key :session-id) (describe String "The session ID provided by the auth provider.")
(optional-key :login-time) (describe Long "Login time as milliseconds since the epoch, provided by auth provider.")}))
4 changes: 2 additions & 2 deletions src/apps/service/users.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
(remove-nil-vals (up/for-username username)))

(defn login
[{:keys [username] :as current-user} {:keys [ip-address]}]
{:login_time (up/record-login username ip-address)
[{:keys [username] :as current-user} {:keys [ip-address login-time session-id]}]
{:login_time (up/record-login username ip-address session-id login-time)
:auth_redirect (oauth/get-redirect-uris current-user)})

0 comments on commit 21a4c97

Please sign in to comment.