From 951623375c7825d5fd9404e139a2a0ed56e0ee4e Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 4 Jan 2021 16:58:55 +0100 Subject: [PATCH] Add a script to reset a password and update docs --- tools/reset-password/reset-password.sh | 46 +++++++++++++++++++ website/site/content/docs/api/intro.md | 2 + .../site/content/docs/tools/reset-password.md | 39 ++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 tools/reset-password/reset-password.sh create mode 100644 website/site/content/docs/tools/reset-password.md diff --git a/tools/reset-password/reset-password.sh b/tools/reset-password/reset-password.sh new file mode 100755 index 00000000..b80bf4c8 --- /dev/null +++ b/tools/reset-password/reset-password.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +# A script to reset a password. +# +# Usage: +# ./reset-password.sh +# +# Example: +# ./reset-password.sh http://localhost:7880 test123 your/account +# + +if [ -z "$1" ]; then + echo "The docspell base-url is required as first argument." + exit 1 +else + BASE_URL="$1" +fi + +if [ -z "$2" ]; then + echo "The admin secret is required as second argument." + exit 1 +else + SECRET="$2" +fi + +if [ -z "$3" ]; then + echo "The user account is required as third argument." + exit 1 +else + USER="$3" +fi + +RESET_URL="${BASE_URL}/api/v1/admin/user/resetPassword" + +OUT=$(curl -s -XPOST \ + -H "Docspell-Admin-Secret: $SECRET" \ + -H "Content-Type: application/json" \ + -d "{\"account\": \"$USER\"}" \ + "$RESET_URL") + + +if command -v jq > /dev/null; then + echo $OUT | jq +else + echo $OUT +fi diff --git a/website/site/content/docs/api/intro.md b/website/site/content/docs/api/intro.md index cf2acf61..6d9a7818 100644 --- a/website/site/content/docs/api/intro.md +++ b/website/site/content/docs/api/intro.md @@ -41,6 +41,8 @@ a "normal" http header. If a cookie header is used, the cookie name must be `docspell_auth` and a custom header must be named `X-Docspell-Auth`. +The admin route (see below) `/admin/user/resetPassword` can be used to +reset a password of a user. ## Admin diff --git a/website/site/content/docs/tools/reset-password.md b/website/site/content/docs/tools/reset-password.md new file mode 100644 index 00000000..9c34b667 --- /dev/null +++ b/website/site/content/docs/tools/reset-password.md @@ -0,0 +1,39 @@ ++++ +title = "Reset Password" +description = "Resets a user password." +weight = 70 ++++ + + +This script can be used to reset a user password. This can be done by +admins, who know the `admin-endpoint.secret` value in the +[configuration](@/docs/configure/_index.md#admin-endpoint) file. + +The script is in `/tools/reset-password/reset-password.sh` and it is +only a wrapper around the admin endpoint `/admin/user/resetPassword`. + +## Usage + +It's very simple: + +``` bash +reset-password.sh +``` + +Three arguments are required to specify the docspell base url, the +admin secret and the account you want to reset the password. + +After the password has been reset, the user can login using it and +change it again in the webapp. + + +## Example + +``` json +❯ ./tools/reset-password/reset-password.sh http://localhost:7880 123 eike +{ + "success": true, + "newPassword": "HjtpG9BFo9y", + "message": "Password updated" +} +```