login_find_key.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 easy_minify(conn, flask.render_template(skin_check(conn),
  27. imp = [get_lang(conn, 'reset_user_ok'), await wiki_set(), await wiki_custom(conn), wiki_css([0, 0])],
  28. data = '' + \
  29. b_text + \
  30. get_lang(conn, 'id') + ' : ' + user_id + \
  31. '<hr class="main_hr">' + \
  32. get_lang(conn, 'password') + ' : ' + key + \
  33. '',
  34. menu = [['user', get_lang(conn, 'return')]]
  35. ))
  36. else:
  37. return easy_minify(conn, flask.render_template(skin_check(conn),
  38. imp = [get_lang(conn, 'password_search'), await wiki_set(), await wiki_custom(conn), wiki_css([0, 0])],
  39. data = '''
  40. <form method="post">
  41. <input placeholder="''' + get_lang(conn, 'key') + '''" name="key" type="password">
  42. <hr class="main_hr">
  43. ''' + await captcha_get(conn) + '''
  44. <button type="submit">''' + get_lang(conn, 'send') + '''</button>
  45. </form>
  46. ''',
  47. menu = [['user', get_lang(conn, 'return')]]
  48. ))