Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set-user-password nbb script to Sitefox #25

Open
chr15m opened this issue Dec 26, 2022 · 0 comments
Open

Add set-user-password nbb script to Sitefox #25

chr15m opened this issue Dec 26, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@chr15m
Copy link
Owner

chr15m commented Dec 26, 2022

Need to package this up so it's available when Sitefox + nbb are installed.

(ns set-user-password
  (:require
    [applied-science.js-interop :as j]
    [promesa.core :as p]
    [sitefox.auth :refer [hash-password save-user]]
    [sitefox.db :refer [f]]))

(defn change-password [password email]
  (p/let [users (f "users" (fn [u] (= (j/get-in u [:auth :email]) email)))
          user (first users)
          [hashed-password salt] (hash-password password)
          user (when user (j/assoc! user :auth (clj->js {:email email
                                                         :password hashed-password
                                                         :salt salt})))]
    (if user
      (save-user user)
      (print
        "User not found.\n"
        "Usage: set-user-password EMAIL NEW-PASSWORD"))))

(change-password (.pop js/process.argv) (.pop js/process.argv))
@chr15m chr15m added the enhancement New feature or request label Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant