server/tools: add password reset script
This commit is contained in:
parent
7a42c7a69b
commit
979d8409d5
3 changed files with 45 additions and 0 deletions
|
@ -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)
|
||||
|
|
42
server/reset-password
Executable file
42
server/reset-password
Executable file
|
@ -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()
|
|
@ -1,7 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
'''
|
||||
Docker helper script. Blocks until the ElasticSearch service is ready.
|
||||
'''
|
||||
|
||||
import logging
|
||||
import time
|
||||
import elasticsearch
|
||||
|
|
Loading…
Reference in a new issue