 
         :else nil))
 
-(defn update-account [{:keys [params session]}]
+(defn update-account [{:keys [params]}]
   (let [user-id               (:userId params -1)
         current-email         (:userName params)
         current-password      (:currentPassword params)


(defn login [{:keys [params]}]
  (let [{:keys [email password]} params]
    (if-let [user (first (call-sql "check_login" email password))]
      (data-response ""
                     {:session {:userId   (:user_id user)
                                :userName email

(defn update-institution-role [{:keys [params]}]
  (let [account-id       (tc/str->int (:accountId params))
        institution-id   (tc/str->int (:institutionId params))
        institution-role (:role params)] ; TODO rename param to institutionRole
    (if (= institution-role "not-member")
      (call-sql "remove_institution_user_role" institution-id account-id)
      (let [email            (:email (first (call-sql "get_user_by_id" account-id)))
            institution-name (:name (first (call-sql "select_institution_by_id" institution-id)))
            timestamp        (-> (DateTimeFormatter/ofPattern "yyyy/MM/dd HH:mm:ss")
                                 (.format (LocalDateTime/now)))
            inst-user-id     (sql-primitive (call-sql "update_institution_user_role"
                                                      institution-id
                                                      account-id
                                                      institution-role))
            email-msg        (format (str "Dear %s,\n\n"
                                          "You have been assigned the role of %s for %s on %s.\n\n"
                                          "Kind Regards,\n"
                                          "  The CEO Team")
                                     email institution-role institution-name timestamp)]
        (when-not inst-user-id (call-sql "add_institution_user" institution-id account-id institution-role))
        (send-mail email nil nil "User Role Assignment" email-msg "text/plain")))
    (data-response "")))

