login_find_key.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from .tool.func import *
  2. async def login_find_key():
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if flask.request.method == 'POST':
  6. if await captcha_post(conn, flask.request.form.get('g-recaptcha-response', flask.request.form.get('g-recaptcha', ''))) == 1:
  7. return await re_error(conn, 13)
  8. input_key = flask.request.form.get('key', '')
  9. curs.execute(db_change('select id from user_set where name = "random_key" and data = ?'), [input_key])
  10. db_data = curs.fetchall()
  11. if not db_data:
  12. return redirect(conn, '/user')
  13. else:
  14. user_id = db_data[0][0]
  15. key = load_random_key(32)
  16. curs.execute(db_change("update user_set set data = ? where name = 'pw' and id = ?"), [
  17. pw_encode(conn, key),
  18. user_id
  19. ])
  20. curs.execute(db_change('select data from user_set where name = "2fa" and id = ?'), [user_id])
  21. if curs.fetchall():
  22. curs.execute(db_change("update user_set set data = '' where name = '2fa' and id = ?"), [user_id])
  23. curs.execute(db_change('select data from other where name = "reset_user_text"'))
  24. sql_d = curs.fetchall()
  25. b_text = (sql_d[0][0] + '<hr class="main_hr">') if sql_d and sql_d[0][0] != '' else ''
  26. return await render_template(
  27. await get_lang('reset_user_ok'),
  28. '' + \
  29. b_text + \
  30. await get_lang('id') + ' : ' + user_id + \
  31. '<hr class="main_hr">' + \
  32. await get_lang('password') + ' : ' + key + \
  33. '',
  34. 0,
  35. [['user', await get_lang('return')]]
  36. )
  37. else:
  38. return await render_template(
  39. await get_lang('password_search'),
  40. '''
  41. <form method="post">
  42. <input class="__ON_INPUT__" placeholder="''' + await get_lang('key') + '''" name="key" type="password">
  43. <hr class="main_hr">
  44. ''' + await captcha_get(conn) + '''
  45. <button type="submit">''' + await get_lang('send') + '''</button>
  46. </form>
  47. ''',
  48. 0,
  49. [['user', await get_lang('return')]]
  50. )