From 979d8409d51ad56ac92ebeca8a75f5b8aaf382fc Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Sat, 27 Jul 2019 17:36:15 -0400 Subject: [PATCH] server/tools: add password reset script --- server/recheck-post-audio | 1 + server/reset-password | 42 +++++++++++++++++++++++++++++++++++++++ server/wait-for-es | 2 ++ 3 files changed, 45 insertions(+) create mode 100755 server/reset-password diff --git a/server/recheck-post-audio b/server/recheck-post-audio index c7200d3c..8e5dfb25 100755 --- a/server/recheck-post-audio +++ b/server/recheck-post-audio @@ -8,6 +8,7 @@ from szurubooru import db, model, errors from szurubooru.func import files, images from szurubooru.func import posts as postfuncs + def main(): post_list = (db.session .query(model.Post) diff --git a/server/reset-password b/server/reset-password new file mode 100755 index 00000000..fb4cb35c --- /dev/null +++ b/server/reset-password @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +''' +If the automatic email-based password reset is not enabled, system +administrators can still manually reset passwords with the help of +this script. +''' + +from sys import stderr +from getpass import getpass +from szurubooru import db +from szurubooru.func import users as userfuncs + + +def main(): + username = input('Enter username or email: ') + + try: + user = userfuncs.get_user_by_name_or_email(username) + except userfuncs.UserNotFoundError as e: + print(e, file=stderr) + return + + new_password = getpass('Enter new password for \'%s\': ' % user.name) + check_password = getpass('Re-enter password: ') + + if check_password != new_password: + print('Passwords do not match.', file=stderr) + return + + try: + userfuncs.update_user_password(user, new_password) + except userfuncs.InvalidPasswordError as e: + print(e, file=stderr) + return + + db.get_session().commit() + print('Sucessfully changed password for \'%s\'' % user.name) + + +if __name__ == '__main__': + main() diff --git a/server/wait-for-es b/server/wait-for-es index 6855c757..d7229296 100755 --- a/server/wait-for-es +++ b/server/wait-for-es @@ -1,7 +1,9 @@ #!/usr/bin/env python3 + ''' Docker helper script. Blocks until the ElasticSearch service is ready. ''' + import logging import time import elasticsearch