Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

commands.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import base64
  17. import click
  18. from flask import Flask
  19. from werkzeug.security import generate_password_hash
  20. from api.db.services import UserService
  21. @click.command('reset-password', help='Reset the account password.')
  22. @click.option('--email', prompt=True, help='The email address of the account whose password you need to reset')
  23. @click.option('--new-password', prompt=True, help='the new password.')
  24. @click.option('--password-confirm', prompt=True, help='the new password confirm.')
  25. def reset_password(email, new_password, password_confirm):
  26. if str(new_password).strip() != str(password_confirm).strip():
  27. click.echo(click.style('sorry. The two passwords do not match.', fg='red'))
  28. return
  29. user = UserService.query(email=email)
  30. if not user:
  31. click.echo(click.style('sorry. The Email is not registered!.', fg='red'))
  32. return
  33. encode_password = base64.b64encode(new_password.encode('utf-8')).decode('utf-8')
  34. password_hash = generate_password_hash(encode_password)
  35. user_dict = {
  36. 'password': password_hash
  37. }
  38. UserService.update_user(user[0].id,user_dict)
  39. click.echo(click.style('Congratulations! Password has been reset.', fg='green'))
  40. def register_commands(app: Flask):
  41. app.cli.add_command(reset_password)