login_find_key.py 2.6 KB

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