diff --git a/src/apps/persistence/users.clj b/src/apps/persistence/users.clj index 8d8251a4..a572f973 100644 --- a/src/apps/persistence/users.clj +++ b/src/apps/persistence/users.clj @@ -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 @@ -45,25 +46,17 @@ (defn- insert-login-record "Records when a user logs into the DE." - [user-id ip-address user-agent] + [user-id ip-address session-id login-time] (insert :logins (values (remove-nil-values {:user_id user-id :ip_address ip-address - :user_agent user-agent})))) + :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 user-agent] - (-> (insert-login-record (get-user-id username) ip-address user-agent) + [username ip-address session-id login-time] + (-> (insert-login-record (get-user-id username) ip-address session-id login-time) (:login_time) (.getTime))) - -(defn record-logout - "Records when a user logs out of the DE." - [username ip-address login-time] - (sql/update :logins - (set-fields {:logout_time (sqlfn :now)}) - (where {:user_id (get-user-id username) - :ip_address ip-address}) - (where {(sqlfn :date_trunc "milliseconds" :login_time) (Timestamp. login-time)}))) diff --git a/src/apps/routes/schemas/user.clj b/src/apps/routes/schemas/user.clj index 1b076116..059843a7 100644 --- a/src/apps/routes/schemas/user.clj +++ b/src/apps/routes/schemas/user.clj @@ -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])) @@ -18,8 +18,5 @@ (defschema LoginParams (merge SecuredQueryParams sessions-schema/IPAddrParam - {:user-agent (describe String "The user agent obtained from the original request.")})) - -(defschema LogoutParams - (merge SecuredQueryParams - sessions-schema/LogoutParams)) + {(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.")})) diff --git a/src/apps/routes/users.clj b/src/apps/routes/users.clj index 2e71a33f..b6f2a771 100644 --- a/src/apps/routes/users.clj +++ b/src/apps/routes/users.clj @@ -29,10 +29,4 @@ :summary "User Login Service" :description "Terrain calls this service to record when a user logs in and to fetch user session info." - (ok (users/login current-user params))) - - (POST "/logout" [] - :query [params LogoutParams] - :summary sessions-schema/LogoutSummary - :description sessions-schema/LogoutDocs - (ok (users/logout current-user params)))) + (ok (users/login current-user params)))) diff --git a/src/apps/service/users.clj b/src/apps/service/users.clj index dd696434..891042e7 100644 --- a/src/apps/service/users.clj +++ b/src/apps/service/users.clj @@ -12,11 +12,6 @@ (remove-nil-vals (up/for-username username))) (defn login - [{:keys [username] :as current-user} {:keys [ip-address user-agent]}] - {:login_time (up/record-login username ip-address user-agent) + [{: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)}) - -(defn logout - [{:keys [username]} {:keys [ip-address login-time]}] - (up/record-logout username ip-address login-time) - nil)