forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
104 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ | |
:target-path "target/%s" | ||
:javac-options ["-target" "1.6" "-source" "1.6"] | ||
:uberjar-name "metabase.jar" | ||
:omit-source true | ||
:ring {:handler metabase.core/app | ||
:init metabase.core/init | ||
:destroy metabase.core/destroy} | ||
|
@@ -101,13 +102,15 @@ | |
:source-paths ["sample_dataset"] | ||
:global-vars {*warn-on-reflection* false} | ||
:main ^:skip-aot metabase.sample-dataset.generate} | ||
;; Run reset password from source: lein with-profile reset-password run /path/to/metabase.db [email protected] | ||
;; Run reset password from source: MB_DB_PATH=/path/to/metabase.db lein with-profile reset-password run [email protected] | ||
;; Create the reset password JAR: lein with-profile reset-password jar | ||
;; -> ./reset-password-artifacts/reset-password/reset-password.jar | ||
;; Run the reset password JAR: java -classpath /path/to/metabase-uberjar.jar:/path/to/reset-password.jar \ | ||
;; metabase.reset_password.core /path/to/metabase.db [email protected] | ||
;; Run the reset password JAR: MB_DB_PATH=/path/to/metabase.db java -classpath /path/to/metabase-uberjar.jar:/path/to/reset-password.jar \ | ||
;; metabase.reset_password.core [email protected] | ||
:reset-password {:source-paths ["reset_password"] | ||
:global-vars {*warn-on-reflection* false} | ||
:main metabase.reset-password.core | ||
:jar-name "reset-password.jar" | ||
;; Exclude everything except for reset-password specific code in the created jar | ||
:jar-exclusions [#"^(?!metabase/reset_password).*$"] | ||
:target-path "reset-password-artifacts/%s"}}) ; different than ./target because otherwise lein uberjar will delete our artifacts and vice versa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
(ns metabase.reset-password.core | ||
(:gen-class) | ||
(:require [clojure.java.jdbc :as jdbc])) | ||
(:require [metabase.db :as db] | ||
[metabase.models.user :as user])) | ||
|
||
(defn- db-filepath->connection-details [filepath] | ||
{:classname "org.h2.Driver" | ||
:subprotocol "h2" | ||
:subname (str "file:" filepath ";MV_STORE=FALSE;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1")}) | ||
|
||
(defn- set-reset-token! [dbpath email-address reset-token] | ||
(let [rows-affected (jdbc/execute! (db-filepath->connection-details dbpath) ["UPDATE CORE_USER SET RESET_TOKEN = ?, RESET_TRIGGERED = ? WHERE EMAIL = ?;" reset-token (System/currentTimeMillis) email-address])] | ||
(when (not= rows-affected [1]) | ||
(throw (Exception. (format "No user found with email address '%s'. Please check the spelling and try again." email-address)))))) | ||
(defn- set-reset-token! | ||
"Set and return a new `reset_token` for the user with EMAIL-ADDRESS." | ||
[email-address] | ||
(let [user-id (or (db/sel :one :id 'User, :email email-address) | ||
(throw (Exception. (format "No user found with email address '%s'. Please check the spelling and try again." email-address))))] | ||
(user/set-user-password-reset-token user-id))) | ||
|
||
(defn -main | ||
[dbpath email-address] | ||
[email-address] | ||
(db/setup-db) | ||
(println (format "Resetting password for %s..." email-address)) | ||
(try | ||
(let [reset-token (str (java.util.UUID/randomUUID))] | ||
(set-reset-token! dbpath email-address reset-token) | ||
(println (format "OK [[[%s]]]" reset-token))) | ||
(println (format "OK [[[%s]]]" (set-reset-token! email-address))) | ||
(System/exit 0) | ||
(catch Throwable e | ||
(println (format "FAIL [[[%s]]]" (.getMessage e))) | ||
(System/exit -1)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters